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.getRemoved() != null || 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.waitForState(instance, CommonStatesConstants.REMOVED); } }
final Map<Long, ServiceExposeMap> currentMappedInstances = new HashMap<>(); for (ServiceExposeMap map : current) { currentMappedInstances.put(map.getInstanceId(), map);
protected void checkAndDelete(Service service, Stack env) { service = objectManager.reload(service); env = objectManager.reload(env); boolean found = false; for (ServiceExposeMap map : serviceExportMapDao.getUnmanagedServiceInstanceMapsToRemove(service.getId())) { found = true; if (isRemoved(service.getRemoved(), service.getState())) { Instance instance = objectManager.loadResource(Instance.class, map.getInstanceId()); DefaultDeploymentUnitInstance.removeInstance(instance, objectProcessManager); } } if (!found && !isRemoved(service.getRemoved(), service.getState())) { objectProcessManager.scheduleStandardProcess(StandardProcess.REMOVE, service, null); } env = objectManager.reload(env); if (isRemoved(env.getRemoved(), env.getState())) { return; } List<Service> services = objectManager.find(Service.class, SERVICE.STACK_ID, env.getId(), ObjectMetaDataManager.STATE_FIELD, new Condition(ConditionType.NE, CommonStatesConstants.REMOVING), ObjectMetaDataManager.REMOVED_FIELD, null); if (services.size() == 0) { objectProcessManager.scheduleStandardProcess(StandardProcess.REMOVE, env, null); } }
} else if (obj instanceof ServiceExposeMap) { sendChange(Service.class, accountId, ((ServiceExposeMap) obj).getServiceId(), schedule, context); sendChange(Instance.class, accountId, ((ServiceExposeMap) obj).getInstanceId(), schedule, context); } else if (obj instanceof InstanceHostMap) { sendChange(Host.class, accountId, ((InstanceHostMap) obj).getHostId(), schedule, context);
/** * {@inheritDoc} */ @Override public void from(io.cattle.platform.core.model.ServiceExposeMap from) { setId(from.getId()); setName(from.getName()); setKind(from.getKind()); setUuid(from.getUuid()); setDescription(from.getDescription()); setState(from.getState()); setCreated(from.getCreated()); setRemoved(from.getRemoved()); setRemoveTime(from.getRemoveTime()); setData(from.getData()); setServiceId(from.getServiceId()); setInstanceId(from.getInstanceId()); setAccountId(from.getAccountId()); setIpAddress(from.getIpAddress()); setDnsPrefix(from.getDnsPrefix()); setHostName(from.getHostName()); setManaged(from.getManaged()); setUpgrade(from.getUpgrade()); }