@Override public Service createServiceInstance() throws Throwable { return new ReservationTaskService(); } }
switch (state.taskSubStage) { case CREATED: queryGroupResourcePlacements(state, description, QUERY_RETRIES_COUNT); break; case SELECTED: case SELECTED_GLOBAL: selectPlacementComputeHosts(state, new HashSet<>( state.resourcePoolsPerGroupPlacementLinks.values())); break; case HOSTS_SELECTED: case HOSTS_SELECTED_GLOBAL: hostsSelected(state); break; case RESERVATION_ALLOCATION: createReservationAllocationTask(state, null); break; case ALLOCATING_RESOURCE_POOL: break; case RESERVATION_SELECTED: makeReservation(state, state.groupResourcePlacementLink, state.resourcePoolsPerGroupPlacementLinks); break; case QUERYING_GLOBAL: queryGroupResourcePlacements(state, description, QUERY_RETRIES_COUNT); break; case COMPLETED: complete();
private void hostsSelected(ReservationTaskState state) { if (state.hostSelections == null || state.hostSelections.isEmpty()) { if (state.tenantLinks != null && !state.tenantLinks.isEmpty()) { proceedTo(SubStage.QUERYING_GLOBAL); } else { failTask("Available compute host can't be selected.", null); } return; } logInfo("Hosts selected %s", state.hostSelections); final Set<String> resourcePools = new HashSet<>(); state.hostSelections.forEach(hs -> resourcePools.addAll(hs.resourcePoolLinks)); if (state.resourcePoolsPerGroupPlacementLinks != null) { state.resourcePoolsPerGroupPlacementLinks = state.resourcePoolsPerGroupPlacementLinks .entrySet().stream().filter((e) -> resourcePools.contains(e.getValue())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (k1, k2) -> k1, LinkedHashMap::new)); } else { state.resourcePoolsPerGroupPlacementLinks = new LinkedHashMap<>(); } selectReservation(state, state.resourcePoolsPerGroupPlacementLinks); }
private void selectReservation(ReservationTaskState state, LinkedHashMap<String, String> resourcePoolsPerGroupPlacementLinks) { if (resourcePoolsPerGroupPlacementLinks.isEmpty()) { failTask("No suitable host available", null); return; } Iterator<String> iter = resourcePoolsPerGroupPlacementLinks.keySet().iterator(); String placementLink = iter.next(); iter.remove(); logInfo("Current selected placement: %s", placementLink); proceedTo(SubStage.RESERVATION_SELECTED, s -> { s.resourcePoolsPerGroupPlacementLinks = resourcePoolsPerGroupPlacementLinks; s.groupResourcePlacementLink = placementLink; }); }
getContainerDescription(state.resourceDescriptionLink, (retrievedContDesc) -> queryGroupResourcePlacements(state, retrievedContDesc, retriesCount)); return; if (customProperties != null && customProperties .containsKey(ReservationAllocationTaskService.CONTAINER_HOST_ID_CUSTOM_PROPERTY)) { proceedTo(ReservationTaskState.SubStage.RESERVATION_ALLOCATION); return; if (isGlobal(state)) { logInfo("Querying for global placements for resource description: [%s] and resource" + " count: [%s]..", state.resourceDescriptionLink, state.resourceCount); q.querySpec.query.addBooleanClause(tenantLinksQuery); } else { logInfo("Querying for group [%s] placements for resource description: [%s] and resource" + " count: [%s]...", state.tenantLinks, state.resourceDescriptionLink, state.resourceCount); logInfo("Placement query includes memory limit of: [%s]", memoryLimit); getHost(), GroupResourcePlacementState.class); List<GroupResourcePlacementState> placements = new ArrayList<>(); (r) -> { if (r.hasException()) { failTask("Exception while quering for placements", r.getException());
getContainerDescription( reservationTask.resourceDescriptionLink, (desc) -> createReservationAllocationTask(reservationTask, desc)); return; reservationAllocationTask.name = description.getCommonDescription().name; reservationAllocationTask.resourcePoolsPerGroupPlacementLinks = reservationTask.resourcePoolsPerGroupPlacementLinks; reservationAllocationTask.documentSelfLink = getSelfId(); reservationAllocationTask.contextId = getContextId(reservationTask); reservationAllocationTask.resourceDescriptionLink = reservationTask.resourceDescriptionLink; reservationAllocationTask.requestTrackerLink = reservationTask.requestTrackerLink; reservationAllocationTask.serviceTaskCallback = ServiceTaskCallback.create( getSelfLink(), TaskStage.STARTED, SubStage.RESERVATION_SELECTED, TaskStage.STARTED, SubStage.ERROR); sendRequest(Operation .createPost(this, ReservationAllocationTaskService.FACTORY_LINK) .setBody(reservationAllocationTask) .setContextId(getSelfId()) .setCompletion( (o, e) -> { if (e != null) { failTask("Failure creating reservation allocation task", e); return; proceedTo(SubStage.ALLOCATING_RESOURCE_POOL);
placementTask.documentSelfLink = getSelfId() + "-reservation" + (isGlobal(state) ? "-global" : ""); placementTask.resourceDescriptionLink = state.resourceDescriptionLink; placementTask.resourcePoolLinks = new ArrayList<>(resourcePools); placementTask.serviceTaskCallback = ServiceTaskCallback.create(getSelfLink(), TaskStage.STARTED, isGlobal(state) ? SubStage.HOSTS_SELECTED_GLOBAL : SubStage.HOSTS_SELECTED, TaskStage.STARTED, SubStage.ERROR); placementTask.requestTrackerLink = state.requestTrackerLink; sendRequest(Operation.createPost(this, PlacementHostSelectionTaskService.FACTORY_LINK) .setBody(placementTask) .setCompletion((o, e) -> { if (e != null) { failTask("Failure creating placement task", e); return; proceedTo(isGlobal(state) ? SubStage.PLACEMENT_GLOBAL : SubStage.PLACEMENT); }));
reservationRequest.resourceCount = state.resourceCount; reservationRequest.resourceDescriptionLink = state.resourceDescriptionLink; reservationRequest.referer = getSelfLink(); logInfo("Reserving instances: %d for descLink: %s and groupPlacementId: %s", reservationRequest.resourceCount, reservationRequest.resourceDescriptionLink, Service.getId(placementLink)); sendRequest(Operation .createPatch(this, placementLink) .setBody(reservationRequest) .setCompletion((o, e) -> { if (e != null) { logWarning("Failure reserving group placement: %s. Retrying with the next" + " one...", e.getMessage()); selectReservation(state, resourcePoolsPerGroupPlacementLinks); return; complete(s -> { s.customProperties = mergeCustomProperties(state.customProperties, placement.customProperties);
private void getContainerDescription(String resourceDescriptionLink, Consumer<ReservationComponentDescription> callbackFunction) { if (description != null) { callbackFunction.accept(description); return; } sendRequest(Operation.createGet(this, resourceDescriptionLink) .setCompletion((o, e) -> { if (e != null) { failTask("Failure retrieving description state", e); return; } ReservationComponentDescription cd = new ReservationComponentDescription(); if (resourceDescriptionLink .startsWith(CompositeDescriptionFactoryService.SELF_LINK)) { cd.updateServiceDocument(o.getBody(CompositeDescription.class)); } else { ComponentMeta metaByDescriptionLink = CompositeComponentRegistry .metaByDescriptionLink(resourceDescriptionLink); cd.updateServiceDocument(o.getBody(metaByDescriptionLink.descriptionClass)); } this.description = cd; callbackFunction.accept(cd); })); }