示例#1
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());
            }
          });
    }
  }
示例#2
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());
           }
         });
   }
 }
  private void removeOldServiceMaps(Service service, Map<Long, String> newServiceLinks) {
    List<? extends ServiceConsumeMap> existingMaps =
        consumeMapDao.findConsumedMapsToRemove(service.getId());
    List<ServiceConsumeMap> mapsToRemove = new ArrayList<>();

    for (ServiceConsumeMap existingMap : existingMaps) {
      if (!newServiceLinks.containsKey(existingMap.getConsumedServiceId())) {
        mapsToRemove.add(existingMap);
      } else {
        String newName = newServiceLinks.get(existingMap.getConsumedServiceId());
        String existingName = existingMap.getName();

        if (!StringUtils.equalsIgnoreCase(newName, existingName)) {
          mapsToRemove.add(existingMap);
        }
      }
    }

    for (ServiceConsumeMap mapToRemove : mapsToRemove) {
      objectProcessManager.scheduleProcessInstanceAsync(
          ServiceDiscoveryConstants.PROCESS_SERVICE_CONSUME_MAP_REMOVE, mapToRemove, null);
    }
  }
 private void createNewServiceMaps(Service service, Map<Long, String> newServiceLinks) {
   for (Long consumedServiceId : newServiceLinks.keySet()) {
     String linkName = newServiceLinks.get(consumedServiceId);
     ServiceConsumeMap map =
         consumeMapDao.findNonRemovedMap(service.getId(), consumedServiceId, linkName);
     if (map == null) {
       map =
           objectManager.create(
               ServiceConsumeMap.class,
               SERVICE_CONSUME_MAP.SERVICE_ID,
               service.getId(),
               SERVICE_CONSUME_MAP.CONSUMED_SERVICE_ID,
               consumedServiceId,
               SERVICE_CONSUME_MAP.ACCOUNT_ID,
               service.getAccountId(),
               SERVICE_CONSUME_MAP.NAME,
               linkName);
     }
     if (map.getState().equalsIgnoreCase(CommonStatesConstants.REQUESTED)) {
       objectProcessManager.scheduleProcessInstanceAsync(
           ServiceDiscoveryConstants.PROCESS_SERVICE_CONSUME_MAP_CREATE, map, null);
     }
   }
 }