protected boolean isStartOnce(Instance instance) { Map<String, Object> labels = DataAccessor .fieldMap(instance, InstanceConstants.FIELD_LABELS); boolean startOnce = false; List<String> stoppedStates = Arrays.asList(InstanceConstants.STATE_STOPPED, InstanceConstants.STATE_STOPPING); if (labels.containsKey(SystemLabels.LABEL_SERVICE_CONTAINER_START_ONCE)) { startOnce = Boolean.valueOf(((String) labels .get(SystemLabels.LABEL_SERVICE_CONTAINER_START_ONCE))) && instance.getStartCount() != null && instance.getStartCount() >= 1L && stoppedStates.contains(instance.getState()); } return startOnce; }
@Override public HandlerResult handle(ProcessState state, ProcessInstance process) { InstanceHostMap map = (InstanceHostMap) state.getResource(); Instance instance = getObjectManager().loadResource(Instance.class, map.getInstanceId()); if (instance == null) { return null; } // set startCount Long startCount = instance.getStartCount() == null ? 1 : instance.getStartCount() + 1; objectManager.setFields(instance, INSTANCE.START_COUNT, startCount); return null; }
protected List<? extends Instance> getServiceInstancesToRestart(Service service) { // get all instances of the service List<? extends Instance> instances = exposeMapDao.listServiceManagedInstances(service); List<Instance> toRestart = new ArrayList<>(); ServiceRestart svcRestart = DataAccessor.field(service, ServiceConstants.FIELD_RESTART, jsonMapper, ServiceRestart.class); RollingRestartStrategy strategy = svcRestart.getRollingRestartStrategy(); Map<Long, Long> instanceToStartCount = strategy.getInstanceToStartCount(); // compare its start_count with one set on the service restart field for (Instance instance : instances) { if (instanceToStartCount.containsKey(instance.getId())) { Long previousStartCount = instanceToStartCount.get(instance.getId()); if (previousStartCount == instance.getStartCount()) { toRestart.add(instance); } } } return toRestart; }
this.start_count = instance.getStartCount(); this.state = instance.getState(); this.memory_reservation = instance.getMemoryReservation();
@Override public Object resourceAction(String type, ApiRequest request, ResourceManager next) { if (request.getAction().equals(ServiceConstants.ACTION_SERVICE_RESTART)) { Service service = objectManager.loadResource(Service.class, request.getId()); ServiceRestart restart = jsonMapper.convertValue(request.getRequestObject(), ServiceRestart.class); RollingRestartStrategy strategy = restart.getRollingRestartStrategy(); if (strategy == null) { ValidationErrorCodes.throwValidationError(ValidationErrorCodes.MISSING_REQUIRED, "Restart strategy needs to be set"); } Map<Long, Long> instanceToStartCount = new HashMap<>(); for (Instance instance : exposeMapDao.listServiceManagedInstances(service)) { instanceToStartCount.put(instance.getId(), instance.getStartCount()); } strategy.setInstanceToStartCount(instanceToStartCount); restart.setRollingRestartStrategy(strategy); request.setRequestObject(jsonMapper.writeValueAsMap(restart)); objectManager.persist(service); } return super.resourceAction(type, request, next); } }
setNetworkContainerId(from.getNetworkContainerId()); setHealthState(from.getHealthState()); setStartCount(from.getStartCount()); setCreateIndex(from.getCreateIndex()); setDeploymentUnitUuid(from.getDeploymentUnitUuid());