recurrent system schedules tasks no longer deleted after first run; file upload sched...
authorVictor Kirhenshtein <victor@netxms.org>
Wed, 28 Sep 2016 09:06:40 +0000 (12:06 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Wed, 28 Sep 2016 09:06:40 +0000 (12:06 +0300)
12 files changed:
src/java/client/netxms-client/src/main/java/org/netxms/client/ScheduledTask.java
src/java/netxms-eclipse/FileManager/src/org/netxms/ui/eclipse/filemanager/actions/UploadFileToAgent.java
src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/actions/ScheduleMaintenance.java
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/dialogs/ScheduledTaskEditor.java
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/helpers/ScheduleTableEntryComparator.java
src/java/netxms-eclipse/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/helpers/ScheduleTableEntryLabelProvider.java
src/server/core/schedule.cpp
webui/webapp/FileManager/src/org/netxms/ui/eclipse/filemanager/actions/UploadFileToAgent.java
webui/webapp/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/actions/ScheduleMaintenance.java
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/dialogs/ScheduledTaskEditor.java
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/helpers/ScheduleTableEntryComparator.java
webui/webapp/ServerConfig/src/org/netxms/ui/eclipse/serverconfig/views/helpers/ScheduleTableEntryLabelProvider.java

index 7f6c1be..679d14c 100644 (file)
@@ -18,9 +18,9 @@ public class ScheduledTask
    
    final static public int DISABLED = 1;
    final static public int EXECUTED = 2;
-   final static public int IN_PROGRES = 4;
-   final static public int INTERNAL = 8;
-   final static private String statusDescription[] = {"Disabled", "Completed", "Running"};
+   final static public int RUNNING = 4;
+   final static public int SYSTEM = 8;
+   final static private String statusDescription[] = { "Disabled", "Completed", "Running" };
    
    public ScheduledTask()
    {
@@ -222,11 +222,11 @@ public class ScheduledTask
    
    public String getStatus()
    {
-      if((flags & IN_PROGRES) > 0)
+      if ((flags & RUNNING) != 0)
          return statusDescription[2];
-      if((flags & EXECUTED) > 0)
+      if ((flags & EXECUTED) != 0)
          return statusDescription[1];
-      if((flags & DISABLED) > 0)
+      if ((flags & DISABLED) != 0)
          return statusDescription[0];
       return "";
    }
index d5ed334..6867ef4 100644 (file)
@@ -100,17 +100,18 @@ public class UploadFileToAgent implements IObjectActionDelegate
                                   }
                                        for(int i = 0; i < nodeIdList.length; i++)
                                        {
-                                          if(dlg.isScheduled())
+                                          if (dlg.isScheduled())
                                           {
                                              ScheduledTask task = dlg.getScheduledTask();
                                              String parameters = dlg.getServerFile().getName() + "," + remoteFileName; //$NON-NLS-1$
                                              task.setParameters(parameters);
                                              task.setObjectId(nodeIdList[i]);
-                                             task.setFlags(ScheduledTask.INTERNAL);
                                              session.addSchedule(task);
                                           }
                                           else
+                                          {
                                              session.uploadFileToAgent(nodeIdList[i], dlg.getServerFile().getName(), remoteFileName, dlg.isCreateJobOnHold());
+                                          }
                                        }
                                }
                        }.start();
index d3ddd4b..ef20158 100644 (file)
@@ -43,8 +43,8 @@ public class ScheduleMaintenance extends AbstractHandler
             {
                if (o instanceof AbstractObject)
                {
-                  ScheduledTask taskStart = new ScheduledTask("Maintenance.Enter", "", "", dialog.getStartDate(), ScheduledTask.INTERNAL, ((AbstractObject)o).getObjectId()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-                  ScheduledTask taskEnd = new ScheduledTask("Maintenance.Leave", "", "", dialog.getEndDate(), ScheduledTask.INTERNAL, ((AbstractObject)o).getObjectId()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+                  ScheduledTask taskStart = new ScheduledTask("Maintenance.Enter", "", "", dialog.getStartDate(), ScheduledTask.SYSTEM, ((AbstractObject)o).getObjectId()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+                  ScheduledTask taskEnd = new ScheduledTask("Maintenance.Leave", "", "", dialog.getEndDate(), ScheduledTask.SYSTEM, ((AbstractObject)o).getObjectId()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                   session.addSchedule(taskStart);
                   session.addSchedule(taskEnd);                  
                }
index 8e3a068..1bb1c35 100644 (file)
@@ -121,7 +121,7 @@ public class ScheduledTaskEditor extends Dialog
       textParameters.setLayoutData(gd);
       textParameters.setText(scheduledTask.getParameters());
       
-      if((scheduledTask.getFlags() & ScheduledTask.INTERNAL) != 0)
+      if((scheduledTask.getFlags() & ScheduledTask.SYSTEM) != 0)
       {
          scheduleType.add(scheduledTask.getScheduledTaskId());
          scheduleType.select(scheduleTypeList.size());
@@ -146,7 +146,7 @@ public class ScheduledTaskEditor extends Dialog
       scheduledTask.setSchedule(task.getSchedule());
       scheduledTask.setExecutionTime(task.getExecutionTime());
       
-      if((scheduledTask.getFlags() & ScheduledTask.INTERNAL) == 0)
+      if((scheduledTask.getFlags() & ScheduledTask.SYSTEM) == 0)
       {
          scheduledTask.setScheduledTaskId(scheduleTypeList.get(scheduleType.getSelectionIndex()));
          scheduledTask.setParameters(textParameters.getText());
index 1d323fa..a51e1ff 100644 (file)
@@ -71,12 +71,12 @@ public class ScheduleTableEntryComparator extends ViewerComparator
          case ScheduledTaskView.OWNER:
             String user1 = "";
             String user2 = "";
-            if((task1.getFlags() & ScheduledTask.INTERNAL)>0)
+            if((task1.getFlags() & ScheduledTask.SYSTEM)>0)
                user1= "Internal";
             else
                user1 = ((NXCSession)ConsoleSharedData.getSession()).findUserDBObjectById(task1.getOwner()).getName();
             
-            if((task2.getFlags() & ScheduledTask.INTERNAL)>0)
+            if((task2.getFlags() & ScheduledTask.SYSTEM)>0)
                user2= "Internal";
             else
                user2 = ((NXCSession)ConsoleSharedData.getSession()).findUserDBObjectById(task2.getOwner()).getName();
index fded4b8..c607eab 100644 (file)
@@ -71,7 +71,7 @@ public class ScheduleTableEntryLabelProvider extends LabelProvider implements IT
          case ScheduledTaskView.STATUS:
             return task.getStatus();
          case ScheduledTaskView.OWNER:
-            if ((task.getFlags() & ScheduledTask.INTERNAL) != 0)
+            if ((task.getFlags() & ScheduledTask.SYSTEM) != 0)
                return "system";
             AbstractUserObject user = session.findUserDBObjectById(task.getOwner());
             return (user != null) ? user.getName() : ("[" + Long.toString(task.getOwner()) + "]"); //$NON-NLS-1$ //$NON-NLS-2$
index bae8805..acdac0a 100644 (file)
@@ -233,7 +233,7 @@ void ScheduledTask::run(SchedulerCallback *callback)
       MutexUnlock(s_oneTimeScheduleLock);
    }
 
-   if (checkFlag(SCHEDULED_TASK_SYSTEM))
+   if (oneTimeSchedule && checkFlag(SCHEDULED_TASK_SYSTEM))
       RemoveScheduledTask(m_id, 0, SYSTEM_ACCESS_FULL);
 }
 
@@ -342,7 +342,7 @@ UINT32 UpdateScheduledTask(int id, const TCHAR *task, const TCHAR *schedule, con
    {
       if (s_cronSchedules.get(i)->getId() == id)
       {
-         if(!s_cronSchedules.get(i)->canAccess(owner, systemAccessRights))
+         if (!s_cronSchedules.get(i)->canAccess(owner, systemAccessRights))
          {
             rcc = RCC_ACCESS_DENIED;
             break;
@@ -414,9 +414,9 @@ UINT32 UpdateOneTimeScheduledTask(int id, const TCHAR *task, time_t nextExecutio
    }
    MutexUnlock(s_oneTimeScheduleLock);
 
-   if(!found)
+   if (!found)
    {
-      //check in different que and if exists - remove from one and add to another
+      //check in different queue and if exists - remove from one and add to another
       MutexLock(s_cronScheduleLock);
       for (int i = 0; i < s_cronSchedules.size(); i++)
       {
@@ -589,7 +589,7 @@ UINT32 CreateScehduledTaskFromMsg(NXCPMessage *request, UINT32 owner, UINT64 sys
    int flags = request->getFieldAsInt32(VID_FLAGS);
    int objectId = request->getFieldAsInt32(VID_OBJECT_ID);
    UINT32 result;
-   if(request->isFieldExist(VID_SCHEDULE))
+   if (request->isFieldExist(VID_SCHEDULE))
    {
       schedule = request->getFieldAsString(VID_SCHEDULE);
       result = AddScheduledTask(taskId, schedule, params, owner, objectId, systemAccessRights, flags);
@@ -599,9 +599,9 @@ UINT32 CreateScehduledTaskFromMsg(NXCPMessage *request, UINT32 owner, UINT64 sys
       nextExecutionTime = request->getFieldAsTime(VID_EXECUTION_TIME);
       result = AddOneTimeScheduledTask(taskId, nextExecutionTime, params, owner, objectId, systemAccessRights, flags);
    }
-   safe_free(taskId);
-   safe_free(schedule);
-   safe_free(params);
+   free(taskId);
+   free(schedule);
+   free(params);
    return result;
 }
 
@@ -759,10 +759,10 @@ static THREAD_RESULT THREAD_CALL CronCheckThread(void *arg)
       for(int i = 0; i < s_cronSchedules.size(); i++)
       {
          ScheduledTask *sh = s_cronSchedules.get(i);
-         if(sh->checkFlag(SCHEDULED_TASK_DISABLED))
+         if (sh->checkFlag(SCHEDULED_TASK_DISABLED))
             continue;
          SchedulerCallback *callback = s_callbacks.get(sh->getTaskHandlerId());
-         if(callback == NULL)
+         if (callback == NULL)
          {
             DbgPrintf(3, _T("CronCheckThread: Cron execution function with taskId=\'%s\' not found"), sh->getTaskHandlerId());
             continue;
index d5ed334..6867ef4 100644 (file)
@@ -100,17 +100,18 @@ public class UploadFileToAgent implements IObjectActionDelegate
                                   }
                                        for(int i = 0; i < nodeIdList.length; i++)
                                        {
-                                          if(dlg.isScheduled())
+                                          if (dlg.isScheduled())
                                           {
                                              ScheduledTask task = dlg.getScheduledTask();
                                              String parameters = dlg.getServerFile().getName() + "," + remoteFileName; //$NON-NLS-1$
                                              task.setParameters(parameters);
                                              task.setObjectId(nodeIdList[i]);
-                                             task.setFlags(ScheduledTask.INTERNAL);
                                              session.addSchedule(task);
                                           }
                                           else
+                                          {
                                              session.uploadFileToAgent(nodeIdList[i], dlg.getServerFile().getName(), remoteFileName, dlg.isCreateJobOnHold());
+                                          }
                                        }
                                }
                        }.start();
index d3ddd4b..ef20158 100644 (file)
@@ -43,8 +43,8 @@ public class ScheduleMaintenance extends AbstractHandler
             {
                if (o instanceof AbstractObject)
                {
-                  ScheduledTask taskStart = new ScheduledTask("Maintenance.Enter", "", "", dialog.getStartDate(), ScheduledTask.INTERNAL, ((AbstractObject)o).getObjectId()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-                  ScheduledTask taskEnd = new ScheduledTask("Maintenance.Leave", "", "", dialog.getEndDate(), ScheduledTask.INTERNAL, ((AbstractObject)o).getObjectId()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+                  ScheduledTask taskStart = new ScheduledTask("Maintenance.Enter", "", "", dialog.getStartDate(), ScheduledTask.SYSTEM, ((AbstractObject)o).getObjectId()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+                  ScheduledTask taskEnd = new ScheduledTask("Maintenance.Leave", "", "", dialog.getEndDate(), ScheduledTask.SYSTEM, ((AbstractObject)o).getObjectId()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                   session.addSchedule(taskStart);
                   session.addSchedule(taskEnd);                  
                }
index 8e3a068..1bb1c35 100644 (file)
@@ -121,7 +121,7 @@ public class ScheduledTaskEditor extends Dialog
       textParameters.setLayoutData(gd);
       textParameters.setText(scheduledTask.getParameters());
       
-      if((scheduledTask.getFlags() & ScheduledTask.INTERNAL) != 0)
+      if((scheduledTask.getFlags() & ScheduledTask.SYSTEM) != 0)
       {
          scheduleType.add(scheduledTask.getScheduledTaskId());
          scheduleType.select(scheduleTypeList.size());
@@ -146,7 +146,7 @@ public class ScheduledTaskEditor extends Dialog
       scheduledTask.setSchedule(task.getSchedule());
       scheduledTask.setExecutionTime(task.getExecutionTime());
       
-      if((scheduledTask.getFlags() & ScheduledTask.INTERNAL) == 0)
+      if((scheduledTask.getFlags() & ScheduledTask.SYSTEM) == 0)
       {
          scheduledTask.setScheduledTaskId(scheduleTypeList.get(scheduleType.getSelectionIndex()));
          scheduledTask.setParameters(textParameters.getText());
index 1d323fa..a51e1ff 100644 (file)
@@ -71,12 +71,12 @@ public class ScheduleTableEntryComparator extends ViewerComparator
          case ScheduledTaskView.OWNER:
             String user1 = "";
             String user2 = "";
-            if((task1.getFlags() & ScheduledTask.INTERNAL)>0)
+            if((task1.getFlags() & ScheduledTask.SYSTEM)>0)
                user1= "Internal";
             else
                user1 = ((NXCSession)ConsoleSharedData.getSession()).findUserDBObjectById(task1.getOwner()).getName();
             
-            if((task2.getFlags() & ScheduledTask.INTERNAL)>0)
+            if((task2.getFlags() & ScheduledTask.SYSTEM)>0)
                user2= "Internal";
             else
                user2 = ((NXCSession)ConsoleSharedData.getSession()).findUserDBObjectById(task2.getOwner()).getName();
index fded4b8..c607eab 100644 (file)
@@ -71,7 +71,7 @@ public class ScheduleTableEntryLabelProvider extends LabelProvider implements IT
          case ScheduledTaskView.STATUS:
             return task.getStatus();
          case ScheduledTaskView.OWNER:
-            if ((task.getFlags() & ScheduledTask.INTERNAL) != 0)
+            if ((task.getFlags() & ScheduledTask.SYSTEM) != 0)
                return "system";
             AbstractUserObject user = session.findUserDBObjectById(task.getOwner());
             return (user != null) ? user.getName() : ("[" + Long.toString(task.getOwner()) + "]"); //$NON-NLS-1$ //$NON-NLS-2$