Exemple #1
0
  @Override
  public HandlerResult handle(ProcessState state, ProcessInstance process) {
    Volume volume = (Volume) state.getResource();

    deallocate(volume, state.getData());

    for (VolumeStoragePoolMap map :
        mapDao.findToRemove(VolumeStoragePoolMap.class, Volume.class, volume.getId())) {
      try {
        objectProcessManager.scheduleStandardProcess(
            StandardProcess.DEACTIVATE,
            map,
            ProcessUtils.chainInData(
                state.getData(), "volumestoragepoolmap.deactivate", "volumestoragepoolmap.remove"));
      } catch (ProcessCancelException e) {
        objectProcessManager.scheduleStandardProcess(StandardProcess.REMOVE, map, null);
      }
    }

    for (Mount mount : mapDao.findToRemove(Mount.class, Volume.class, volume.getId())) {
      try {
        objectProcessManager.scheduleStandardProcess(
            StandardProcess.DEACTIVATE,
            mount,
            ProcessUtils.chainInData(state.getData(), "mount.deactivate", "mount.remove"));
      } catch (ProcessCancelException e) {
        objectProcessManager.scheduleStandardProcess(StandardProcess.REMOVE, mount, null);
      }
    }

    return new HandlerResult();
  }
  void createService(ExternalEvent event, Map<String, Object> serviceData) {
    Service svc = serviceDao.getServiceByExternalId(event.getAccountId(), event.getExternalId());
    if (svc != null) {
      return;
    }

    Stack stack = getStack(event);
    if (stack == null) {
      log.info("Can't process service event. Could not get or create stack. Event: [{}]", event);
      return;
    }

    Map<String, Object> service = new HashMap<String, Object>();
    if (serviceData != null) {
      service.putAll(serviceData);
    }
    service.put(ObjectMetaDataManager.ACCOUNT_FIELD, event.getAccountId());
    service.put(FIELD_STACK_ID, stack.getId());

    try {
      String create =
          objectProcessManager.getStandardProcessName(StandardProcess.CREATE, Service.class);
      String activate =
          objectProcessManager.getStandardProcessName(StandardProcess.ACTIVATE, Service.class);
      ProcessUtils.chainInData(service, create, activate);
      resourceDao.createAndSchedule(Service.class, service);
    } catch (ProcessCancelException e) {
      log.info(
          "Create and activate process cancelled for service with account id {}and external id {}",
          event.getAccountId(),
          event.getExternalId());
    }
  }
  protected void removeLoadBalancerAgent(LoadBalancer loadBalancer, LoadBalancerHostMap hostMap) {
    Agent lbAgent = lbInstanceManager.getLoadBalancerAgent(loadBalancer, hostMap);
    if (lbAgent == null) {
      return;
    }

    if (lbAgent.getRemoved() == null
        && !(lbAgent.getState().equalsIgnoreCase(CommonStatesConstants.REMOVED)
            || lbAgent.getState().equals(CommonStatesConstants.REMOVING))) {
      // try to remove first
      try {
        objectProcessManager.scheduleStandardProcess(StandardProcess.REMOVE, lbAgent, null);
      } catch (ProcessCancelException e) {
        objectProcessManager.scheduleStandardProcess(
            StandardProcess.DEACTIVATE,
            lbAgent,
            ProcessUtils.chainInData(
                new HashMap<String, Object>(),
                AgentConstants.PROCESS_DEACTIVATE,
                AgentConstants.PROCESS_REMOVE));
      }
    }
  }
Exemple #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());
            }
          });
    }
  }