@Override protected Long getId(Object obj) { if (obj instanceof Instance) { return ((Instance) obj).getId(); } return null; } }
@Override public void instanceAllocate(final Instance instance) { log.info("Allocating instance [{}]", instance.getId()); lockManager.lock(new AllocateResourceLock(instance.getId()), new LockCallbackNoReturn() { @Override public void doWithLockNoResult() { allocateInstance(instance); } }); log.info("Handled request for instance [{}]", instance.getId()); }
protected void reregisterInstancesForHealtchecks(List<? extends Instance> instances) { for (Instance instance : instances) { healthcheckService.registerForHealtcheck(HealthcheckInstanceType.INSTANCE, instance.getId()); } }
@Override public void doWithLockNoResult() { objectProcessManager.scheduleStandardProcessAsync(StandardProcess.REMOVE, currentMappedInstances.get(instance.getId()), null); } });
private EventVO<Map<String, Object>> buildEvent(String eventName, String phase, List<Instance> instances, Set<Volume> volumes, Long agentId) { List<ResourceRequest> resourceRequests = gatherResourceRequests(instances, volumes, agentId); if (resourceRequests.isEmpty()) { return null; } return newEvent(eventName, resourceRequests, "instance", phase, instances.get(0).getId(), instances); }
private EventVO<Map<String, Object>> buildEventForPort(String eventName, String phase, List<Instance> instances, Long agentId, List<Port> newPorts) { List<ResourceRequest> resourceRequests = gatherResourceRequestsForPort(instances, agentId, newPorts); if (resourceRequests.isEmpty()) { return null; } return newEvent(eventName, resourceRequests, "instance", phase, instances.get(0).getId(), instances); }
protected boolean isStartedOnce() { List<String> validStates = Arrays.asList(InstanceConstants.STATE_STOPPED, InstanceConstants.STATE_STOPPING, InstanceConstants.STATE_RUNNING); return validStates.contains(context.objectManager.reload(this.instance).getState()) && context.objectManager.find(InstanceHostMap.class, INSTANCE_HOST_MAP.INSTANCE_ID, instance.getId()).size() > 0; }
@Override public ServiceExposeMap getServiceInstanceMap(Service service, final Instance instance) { return objectManager.findAny(ServiceExposeMap.class, SERVICE_EXPOSE_MAP.INSTANCE_ID, instance.getId(), SERVICE_EXPOSE_MAP.SERVICE_ID, service.getId(), SERVICE_EXPOSE_MAP.REMOVED, null); }
protected void releaseAllocation(Instance instance) { // This is kind of strange logic to remove deallocate for every instance host map, but in truth there will be only one ihm Map<String, List<InstanceHostMap>> maps = allocatorDao.getInstanceHostMapsWithHostUuid(instance.getId()); for (Map.Entry<String, List<InstanceHostMap>> entry : maps.entrySet()) { for (InstanceHostMap map : entry.getValue()) { if (!allocatorDao.isAllocationReleased(map)) { allocatorDao.releaseAllocation(instance, map); releaseResources(instance, entry.getKey(), InstanceConstants.PROCESS_DEALLOCATE); } } } }
protected String key(Instance instance) { Object resourceId = context.idFormatter.formatId(instance.getKind(), instance.getId()); return String.format("%s:%s", instance.getKind(), resourceId); }
@Override public HandlerResult handle(ProcessState state, ProcessInstance process) { Instance instance = (Instance)state.getResource(); if (mapDao.findNonRemoved(InstanceHostMap.class, Instance.class, instance.getId()).size() == 0) { allocatorService.instanceAllocate(instance); } return afterAllocate(state, process, new HashMap<Object, Object>()); }
private void createLabels(Instance instance) { @SuppressWarnings("unchecked") Map<String, String> labels = DataAccessor.fields(instance).withKey(InstanceConstants.FIELD_LABELS).as(Map.class); if (labels == null) { return; } for (Map.Entry<String, String> labelEntry : labels.entrySet()) { String labelKey = labelEntry.getKey(); String labelValue = labelEntry.getValue(); labelsService.createContainerLabel(instance.getAccountId(), instance.getId(), labelKey, labelValue); } }
public Condition getInstanceHostConstraint(Instance instance) { if (StringUtils.isEmpty(instance.getDeploymentUnitUuid())) { return INSTANCE_HOST_MAP.INSTANCE_ID.eq(instance.getId()); } else { return INSTANCE.DEPLOYMENT_UNIT_UUID.eq(instance.getDeploymentUnitUuid()); } }
private void deleteServiceMappings(Instance instance) { List<? extends ServiceExposeMap> maps = objectManager.mappedChildren( objectManager.loadResource(Instance.class, instance.getId()), ServiceExposeMap.class); for (ServiceExposeMap map : maps) { if (!(map.getState().equals(CommonStatesConstants.REMOVED) || map.getState().equals( CommonStatesConstants.REMOVING))) { objectProcessManager.scheduleStandardProcessAsync(StandardProcess.REMOVE, map, null); } } }
protected void compute(Instance instance, ProcessState state) { for (InstanceHostMap map : mapDao.findNonRemoved(InstanceHostMap.class, Instance.class, instance.getId())) { activate(map, state.getData()); } }
protected Volume getRoot(Instance instance, List<Volume> volumes) { if (instance.getImageId() == null) { return null; } for (Volume volume : volumes) { if (volume.getDeviceNumber() != null && volume.getDeviceNumber().intValue() == 0) { return volume; } } return objectManager.create(Volume.class, VOLUME.ACCOUNT_ID, instance.getAccountId(), VOLUME.INSTANCE_ID, instance.getId(), VOLUME.IMAGE_ID, instance .getImageId(), VOLUME.DEVICE_NUMBER, 0, VOLUME.ATTACHED_STATE, CommonStatesConstants.ACTIVE); }
protected HandlerResult afterDeallocate(ProcessState state, ProcessInstance process, Map<Object, Object> result) { Instance instance = (Instance) state.getResource(); for (InstanceHostMap map : mapDao.findToRemove(InstanceHostMap.class, Instance.class, instance.getId())) { if (CommonStatesConstants.ACTIVATING.equals(map.getState()) || CommonStatesConstants.ACTIVE.equals(map.getState())) { deactivate(map, state.getData()); } remove(map, state.getData()); } return new HandlerResult(result); } }
@Override public Nic getPrimaryNic(Instance instance) { if ( instance == null ) { return null; } return create() .selectFrom(NIC) .where(NIC.INSTANCE_ID.eq(instance.getId()) .and(NIC.DEVICE_NUMBER.eq(0))) .fetchOne(); }
@Override public List<? extends Service> findServicesFor(Instance instance) { return create().select(SERVICE.fields()) .from(SERVICE) .join(SERVICE_EXPOSE_MAP) .on(SERVICE_EXPOSE_MAP.SERVICE_ID.eq(SERVICE.ID)) .where(SERVICE_EXPOSE_MAP.INSTANCE_ID.eq(instance.getId())) .fetchInto(ServiceRecord.class); }
@Override public List<? extends Service> findServicesNonRemovedLinksOnly(Instance instance) { return create().select(SERVICE.fields()) .from(SERVICE) .join(SERVICE_EXPOSE_MAP) .on(SERVICE_EXPOSE_MAP.SERVICE_ID.eq(SERVICE.ID)) .where(SERVICE_EXPOSE_MAP.INSTANCE_ID.eq(instance.getId()) .and(SERVICE_EXPOSE_MAP.REMOVED.isNull())) .fetchInto(ServiceRecord.class); }