private void deactivateThenRemove(ProjectMember member) {
    Object state = ObjectUtils.getPropertyIgnoreErrors(member, ObjectMetaDataManager.STATE_FIELD);

    if (CommonStatesConstants.ACTIVE.equals(state)) {
      objectProcessManager.executeStandardProcess(StandardProcess.DEACTIVATE, member, null);
      member = objectManager.reload(member);
    }

    if (CommonStatesConstants.PURGED.equals(state)) {
      return;
    }

    objectProcessManager.executeStandardProcess(StandardProcess.REMOVE, member, null);
  }
  @Override
  public void removeServiceMaps(Service service) {
    // 1. remove all maps to the services consumed by service specified
    for (ServiceConsumeMap map : consumeMapDao.findConsumedMapsToRemove(service.getId())) {
      objectProcessManager.scheduleProcessInstance(
          ServiceDiscoveryConstants.PROCESS_SERVICE_CONSUME_MAP_REMOVE, map, null);
    }

    // 2. remove all maps to the services consuming service specified
    for (ServiceConsumeMap map : consumeMapDao.findConsumingMapsToRemove(service.getId())) {
      objectProcessManager.scheduleProcessInstance(
          ServiceDiscoveryConstants.PROCESS_SERVICE_CONSUME_MAP_REMOVE, map, null);
    }
  }
 @Override
 public void updateLoadBalancerService(
     Service service, List<? extends Long> certIds, Long defaultCertId) {
   LoadBalancer lb =
       objectManager.findOne(
           LoadBalancer.class,
           LOAD_BALANCER.SERVICE_ID,
           service.getId(),
           LOAD_BALANCER.REMOVED,
           null);
   if (lb != null) {
     Map<String, Object> data = new HashMap<>();
     if (certIds == null) {
       certIds =
           DataAccessor.fields(service)
               .withKey(LoadBalancerConstants.FIELD_LB_CERTIFICATE_IDS)
               .asList(jsonMapper, Long.class);
     }
     if (defaultCertId == null) {
       defaultCertId =
           DataAccessor.fieldLong(service, LoadBalancerConstants.FIELD_LB_DEFAULT_CERTIFICATE_ID);
     }
     data.put(LoadBalancerConstants.FIELD_LB_CERTIFICATE_IDS, certIds);
     data.put(LoadBalancerConstants.FIELD_LB_DEFAULT_CERTIFICATE_ID, defaultCertId);
     DataUtils.getWritableFields(lb).putAll(data);
     objectManager.persist(lb);
     objectProcessManager.scheduleStandardProcess(StandardProcess.UPDATE, lb, data);
   }
 }
Ejemplo n.º 4
0
 private void activateServices(final Service initialService, final List<Service> services) {
   /*
    * Trigger activate for all the services
    */
   try {
     for (Service service : services) {
       if (service.getState().equalsIgnoreCase(CommonStatesConstants.INACTIVE)) {
         objectProcessMgr.scheduleStandardProcess(StandardProcess.ACTIVATE, service, null);
       } else if (service.getState().equalsIgnoreCase(CommonStatesConstants.ACTIVE)) {
         objectProcessMgr.scheduleStandardProcess(StandardProcess.UPDATE, service, null);
       }
     }
   } catch (IdempotentRetryException ex) {
     // if not caught, the process will keep on spinning forever
     // figure out better solution
   }
 }
  @Override
  public void removeServiceLink(Service service, ServiceLink serviceLink) {
    ServiceConsumeMap map =
        consumeMapDao.findMapToRemove(service.getId(), serviceLink.getServiceId());

    if (map != null) {
      objectProcessManager.scheduleProcessInstance(
          ServiceDiscoveryConstants.PROCESS_SERVICE_CONSUME_MAP_REMOVE, map, null);
    }
  }
  protected void createListener(
      Service service,
      Map<Integer, LoadBalancerListener> listeners,
      LoadBalancerListenerPort port) {
    LoadBalancerListener listenerObj =
        objectManager.findOne(
            LoadBalancerListener.class,
            LOAD_BALANCER_LISTENER.SERVICE_ID,
            service.getId(),
            LOAD_BALANCER_LISTENER.SOURCE_PORT,
            port.getSourcePort(),
            LOAD_BALANCER_LISTENER.PRIVATE_PORT,
            port.getPrivatePort(),
            LOAD_BALANCER_LISTENER.TARGET_PORT,
            port.getTargetPort(),
            LOAD_BALANCER_LISTENER.REMOVED,
            null,
            LOAD_BALANCER_LISTENER.ACCOUNT_ID,
            service.getAccountId());

    if (listenerObj == null) {
      listenerObj =
          objectManager.create(
              LoadBalancerListener.class,
              LOAD_BALANCER_LISTENER.NAME,
              getLoadBalancerName(service) + "_" + port.getPrivatePort(),
              LOAD_BALANCER_LISTENER.ACCOUNT_ID,
              service.getAccountId(),
              LOAD_BALANCER_LISTENER.SOURCE_PORT,
              port.getSourcePort(),
              LOAD_BALANCER_LISTENER.PRIVATE_PORT,
              port.getPrivatePort(),
              LOAD_BALANCER_LISTENER.TARGET_PORT,
              port.getTargetPort(),
              LOAD_BALANCER_LISTENER.SOURCE_PROTOCOL,
              port.getProtocol(),
              LOAD_BALANCER_LISTENER.TARGET_PROTOCOL,
              port.getProtocol(),
              LoadBalancerConstants.FIELD_LB_LISTENER_ALGORITHM,
              "roundrobin",
              LOAD_BALANCER_LISTENER.ACCOUNT_ID,
              service.getAccountId(),
              LOAD_BALANCER_LISTENER.SERVICE_ID,
              service.getId());
    }
    objectProcessManager.executeProcess(
        LoadBalancerConstants.PROCESS_LB_LISTENER_CREATE, listenerObj, null);

    listeners.put(listenerObj.getPrivatePort(), listenerObj);
  }
 @Override
 public void cleanupLoadBalancerService(Service service) {
   // 1) remove load balancer
   LoadBalancer lb =
       objectManager.findOne(
           LoadBalancer.class,
           LOAD_BALANCER.SERVICE_ID,
           service.getId(),
           LOAD_BALANCER.REMOVED,
           null);
   if (lb != null) {
     objectProcessManager.scheduleProcessInstance(
         LoadBalancerConstants.PROCESS_LB_REMOVE, lb, null);
   }
 }
Ejemplo n.º 8
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());
            }
          });
    }
  }
Ejemplo n.º 9
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);
     }
   }
 }
  private LoadBalancerConfig createDefaultLoadBalancerConfig(
      String defaultName, Map<String, Object> lbConfigData, Service service) {
    String name =
        lbConfigData.get("name") == null ? defaultName : lbConfigData.get("name").toString();
    LoadBalancerConfig lbConfig =
        objectManager.findOne(
            LoadBalancerConfig.class,
            LOAD_BALANCER_CONFIG.REMOVED,
            null,
            LOAD_BALANCER_CONFIG.ACCOUNT_ID,
            service.getAccountId(),
            LOAD_BALANCER_CONFIG.SERVICE_ID,
            service.getId());

    if (lbConfig == null) {
      lbConfigData.put("accountId", service.getAccountId());
      lbConfigData.put("name", name);
      lbConfigData.put("serviceId", service.getId());
      lbConfig = objectManager.create(LoadBalancerConfig.class, lbConfigData);
    }
    objectProcessManager.executeProcess(
        LoadBalancerConstants.PROCESS_LB_CONFIG_CREATE, lbConfig, null);
    return lbConfig;
  }
  private void createLoadBalancer(
      Service service,
      String lbName,
      LoadBalancerConfig lbConfig,
      Map<String, Object> launchConfigData,
      List<? extends Long> certIds,
      Long defaultCertId) {
    LoadBalancer lb =
        objectManager.findOne(
            LoadBalancer.class,
            LOAD_BALANCER.SERVICE_ID,
            service.getId(),
            LOAD_BALANCER.REMOVED,
            null,
            LOAD_BALANCER.ACCOUNT_ID,
            service.getAccountId());
    Map<String, Object> data =
        populateLBData(service, lbName, lbConfig, launchConfigData, certIds, defaultCertId);
    if (lb == null) {
      lb = objectManager.create(LoadBalancer.class, data);
    }

    objectProcessManager.executeProcess(LoadBalancerConstants.PROCESS_LB_CREATE, lb, data);
  }