@Override
  protected Object getAgentResource(
      ProcessState state, ProcessInstance process, Object dataResource) {
    Instance instance = getInstance(state);
    if (!isPod(instance)) {
      return false;
    }
    Long accountId = instance.getAccountId();
    List<Long> agentIds =
        agentInstanceDao.getAgentProvider(
            SystemLabels.LABEL_AGENT_SERVICE_LABELS_PROVIDER, accountId);
    Long agentId = agentIds.size() == 0 ? null : agentIds.get(0);
    if ((instance instanceof Instance)
        && (agentIds.contains(instance.getAgentId()) || instance.getSystem())) {
      return null;
    }

    if (agentId == null) {
      throw new ExecutionException("Failed to find labels provider", instance);
    }

    return agentId;
  }
Exemple #2
0
  @Override
  public HandlerResult handle(ProcessState state, ProcessInstance process) {
    Account account = (Account) state.getResource();

    for (Certificate cert : getObjectManager().children(account, Certificate.class)) {
      if (cert.getRemoved() != null) {
        continue;
      }

      deactivateThenRemove(cert, state.getData());
    }

    for (Credential cred : getObjectManager().children(account, Credential.class)) {
      if (cred.getRemoved() != null) {
        continue;
      }

      deactivateThenRemove(cred, state.getData());
    }

    for (Host host : getObjectManager().children(account, Host.class)) {
      try {
        deactivateThenRemove(host, state.getData());
      } catch (ProcessCancelException e) {
        // ignore
      }
      purge(host, null);
    }

    for (PhysicalHost host : getObjectManager().children(account, PhysicalHost.class)) {
      try {
        getObjectProcessManager().executeStandardProcess(StandardProcess.REMOVE, host, null);
      } catch (ProcessCancelException e) {
        // ignore
      }
    }

    for (Agent agent : getObjectManager().children(account, Agent.class)) {
      if (agent.getRemoved() != null) {
        continue;
      }
      deactivateThenRemove(agent, state.getData());
    }

    for (Environment env : getObjectManager().children(account, Environment.class)) {
      if (env.getRemoved() != null) {
        continue;
      }
      objectProcessManager.scheduleStandardProcessAsync(StandardProcess.REMOVE, env, null);
    }

    for (Instance instance : instanceDao.listNonRemovedInstances(account, false)) {
      deleteAgentAccount(instance.getAgentId(), state.getData());

      try {
        objectProcessManager.scheduleStandardProcess(StandardProcess.REMOVE, instance, null);
      } catch (ProcessCancelException e) {
        objectProcessManager.scheduleProcessInstance(
            InstanceConstants.PROCESS_STOP,
            instance,
            CollectionUtils.asMap(InstanceConstants.REMOVE_OPTION, true));
      }
    }

    accountDao.deleteProjectMemberEntries(account);

    return null;
  }