@Override
 public void stop() {
   if (instance != null && instance.getState().equals(InstanceConstants.STATE_RUNNING)) {
     context.objectProcessManager.scheduleProcessInstanceAsync(
         InstanceConstants.PROCESS_STOP, instance, null);
   }
 }
 protected void removeLoadBalancerInstance(
     LoadBalancer loadBalancer, LoadBalancerHostMap hostMap) {
   Instance lbInstance = lbInstanceManager.getLoadBalancerInstance(hostMap);
   if (lbInstance != null
       && !(lbInstance.getState().equalsIgnoreCase(CommonStatesConstants.REMOVED)
           || lbInstance.getState().equals(CommonStatesConstants.REMOVING))) {
     // try to remove first
     try {
       objectProcessManager.scheduleStandardProcess(StandardProcess.REMOVE, lbInstance, null);
     } catch (ProcessCancelException e) {
       objectProcessManager.scheduleProcessInstance(
           InstanceConstants.PROCESS_STOP,
           lbInstance,
           CollectionUtils.asMap(InstanceConstants.REMOVE_OPTION, true));
     }
   }
 }
Esempio n. 3
0
 protected void stopInstances(Map<String, List<Instance>> deploymentUnitInstancesToStop) {
   List<Instance> toStop = new ArrayList<>();
   for (String key : deploymentUnitInstancesToStop.keySet()) {
     toStop.addAll(deploymentUnitInstancesToStop.get(key));
   }
   for (Instance instance : toStop) {
     if (!instance.getState().equalsIgnoreCase(InstanceConstants.STATE_STOPPED)) {
       objectProcessMgr.scheduleProcessInstanceAsync(
           InstanceConstants.PROCESS_STOP, instance, null);
     }
   }
   for (Instance instance : toStop) {
     resourceMntr.waitFor(
         instance,
         new ResourcePredicate<Instance>() {
           @Override
           public boolean evaluate(Instance obj) {
             return InstanceConstants.STATE_STOPPED.equals(obj.getState());
           }
         });
   }
 }
Esempio n. 4
0
  public void cleanupUpgradedInstances(Service service) {
    List<? extends ServiceExposeMap> maps = exposeMapDao.getInstancesSetForUpgrade(service.getId());
    List<Instance> waitList = new ArrayList<>();
    for (ServiceExposeMap map : maps) {
      Instance instance = objectManager.loadResource(Instance.class, map.getInstanceId());
      if (instance == null
          || instance.getState().equals(CommonStatesConstants.REMOVED)
          || instance.getState().equals(CommonStatesConstants.REMOVING)) {
        continue;
      }
      try {
        objectProcessMgr.scheduleProcessInstanceAsync(
            InstanceConstants.PROCESS_REMOVE, instance, null);
      } catch (ProcessCancelException ex) {
        // in case instance was manually restarted
        objectProcessMgr.scheduleProcessInstanceAsync(
            InstanceConstants.PROCESS_STOP,
            instance,
            ProcessUtils.chainInData(
                new HashMap<String, Object>(),
                InstanceConstants.PROCESS_STOP,
                InstanceConstants.PROCESS_REMOVE));
      }
    }

    for (Instance instance : waitList) {
      resourceMntr.waitFor(
          instance,
          new ResourcePredicate<Instance>() {
            @Override
            public boolean evaluate(Instance obj) {
              return CommonStatesConstants.REMOVED.equals(obj.getState());
            }
          });
    }
  }