예제 #1
0
  Stack getStack(final ExternalEvent event) {
    final Map<String, Object> env =
        CollectionUtils.castMap(DataUtils.getFields(event).get(FIELD_ENVIRIONMENT));
    Object eId = CollectionUtils.getNestedValue(env, FIELD_EXTERNAL_ID);
    if (eId == null) {
      return null;
    }
    final String envExtId = eId.toString();

    Stack stack = stackDao.getStackByExternalId(event.getAccountId(), envExtId);
    // If stack has not been created yet
    if (stack == null) {
      final Stack newEnv = objectManager.newRecord(Stack.class);

      Object possibleName = CollectionUtils.getNestedValue(env, "name");
      newEnv.setExternalId(envExtId);
      newEnv.setAccountId(event.getAccountId());
      String name = possibleName != null ? possibleName.toString() : envExtId;
      newEnv.setName(name);

      stack =
          DeferredUtils.nest(
              new Callable<Stack>() {
                @Override
                public Stack call() {
                  return resourceDao.createAndSchedule(newEnv);
                }
              });

      stack =
          resourceMonitor.waitFor(
              stack,
              new ResourcePredicate<Stack>() {
                @Override
                public boolean evaluate(Stack obj) {
                  return obj != null && CommonStatesConstants.ACTIVE.equals(obj.getState());
                }

                @Override
                public String getMessage() {
                  return "active state";
                }
              });
    }
    return stack;
  }
예제 #2
0
 protected void waitForHealthyState(Service service) {
   List<? extends Instance> serviceInstances =
       exposeMapDao.listServiceManagedInstances(service.getId());
   final List<String> healthyStates =
       Arrays.asList(
           HealthcheckConstants.HEALTH_STATE_HEALTHY,
           HealthcheckConstants.HEALTH_STATE_UPDATING_HEALTHY);
   for (final Instance instance : serviceInstances) {
     resourceMntr.waitFor(
         instance,
         DEFAULT_WAIT_TIMEOUT,
         new ResourcePredicate<Instance>() {
           @Override
           public boolean evaluate(Instance obj) {
             return instance.getHealthState() == null
                 || healthyStates.contains(obj.getHealthState());
           }
         });
   }
 }
  protected Subnet getServiceVipSubnet(final Service service) {
    Subnet vipSubnet =
        DeferredUtils.nest(
            new Callable<Subnet>() {
              @Override
              public Subnet call() throws Exception {
                return ntwkDao.addVIPSubnet(service.getAccountId());
              }
            });

    // wait for subnet to become active so the ip range is populated
    vipSubnet =
        resourceMonitor.waitFor(
            vipSubnet,
            new ResourcePredicate<Subnet>() {
              @Override
              public boolean evaluate(Subnet obj) {
                return CommonStatesConstants.ACTIVE.equals(obj.getState());
              }
            });
    return vipSubnet;
  }
예제 #4
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());
           }
         });
   }
 }
예제 #5
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());
            }
          });
    }
  }