@Override public void handlePost(Operation post) { Map<String, String> params = UriUtils.parseUriQueryParams(post.getUri()); String hostLink = params.get(HOST_LINK_URI_PARAM); String containerLink = params.get(CONTAINER_LINK_URI_PARAM); if (containerLink == null) { if (hostLink == null) { post.fail(new LocalizableValidationException(String.format("%s or %s is required", HOST_LINK_URI_PARAM, CONTAINER_LINK_URI_PARAM), "compute.shell.container.links.required", HOST_LINK_URI_PARAM, CONTAINER_LINK_URI_PARAM)); return; } // default to shell agent for common ssh tasks String hostId = Service.getId(hostLink); containerLink = SystemContainerDescriptions .getSystemContainerSelfLink( SystemContainerDescriptions.AGENT_CONTAINER_NAME, hostId); } execute(post, hostLink, containerLink); }
/** Create a container description to be used for installing host agents containers. */ public static ContainerDescription buildCoreAgentContainerDescription() { ContainerDescription cd = new ContainerDescription(); cd.documentSelfLink = AGENT_CONTAINER_DESCRIPTION_LINK; cd.name = AGENT_CONTAINER_NAME; cd.image = getAgentImageNameAndVersion(); cd.publishAll = true; cd.volumes = AGENT_CONTAINER_VOLUMES; cd.restartPolicy = "always"; return cd; }
public static String getAgentImageNameAndVersion() { return String.format("%s:%s", AGENT_IMAGE_NAME, getAgentImageVersion()); }
private void updateContainerStates(ContainerListCallback callback, List<ContainerState> containerStates, String containerHostLink) { final List<String> systemContainersToInstall = SystemContainerDescriptions .getSystemContainerNames(); for (ContainerState existingContainerState : containerStates) { boolean exists = false; .getSystemContainerSelfLink(systemContainerName, Service.getId(containerHostLink)); containerState.system = Boolean.TRUE;
systemContainerLink = SystemContainerDescriptions.getSystemContainerSelfLink( SystemContainerDescriptions.AGENT_CONTAINER_NAME, TEST_HOST_ID); image = String.format("%s:%s", SystemContainerDescriptions.AGENT_IMAGE_NAME, SystemContainerDescriptions.getAgentImageVersion());
private ContainerState createSystemContainerState(ContainerState containerState, ContainerDescription containerDesc, String containerHostLink) { String systemContainerName = isSystemContainer( SystemContainerDescriptions.getSystemContainerNames(), containerState.names); final ContainerState systemContainerState = new ContainerState(); systemContainerState.documentSelfLink = containerState.documentSelfLink; systemContainerState.names = new ArrayList<>(); systemContainerState.names.add(systemContainerName); systemContainerState.descriptionLink = containerDesc.documentSelfLink; systemContainerState.parentLink = containerHostLink; systemContainerState.powerState = ContainerState.PowerState.PROVISIONING; systemContainerState.adapterManagementReference = containerDesc.instanceAdapterReference; systemContainerState.image = containerDesc.image; systemContainerState.command = containerDesc.command; systemContainerState.groupResourcePlacementLink = GroupResourcePlacementService.DEFAULT_RESOURCE_PLACEMENT_LINK; systemContainerState.system = Boolean.TRUE; systemContainerState.volumes = containerDesc.volumes; systemContainerState.id = containerState.id; return systemContainerState; }
private boolean validate(Set<ResourceState> resourcesStates) { if (resourcesStates.stream() .filter(r -> r instanceof ContainerState) .map(r -> ((ContainerState) r)) .anyMatch(c -> isSystemContainer(c))) { failTask(null, new LocalizableValidationException( "Day2 operations are not supported for system container", "request.system.container.day2")); return false; } return true; }
private Operation releaseResourcePlacement(ContainerRemovalTaskState state, ContainerState cs, String subTaskLink) { if (isDiscoveredContainer(cs) || state.skipReleaseResourcePlacement) { logFine("Skipping releasing placement because container is a discovered one: %s", cs.documentSelfLink); return null; } if (isSystemContainer(cs)) { logFine("Skipping releasing placement because container is a system one: %s", cs.documentSelfLink); return null; } ReservationRemovalTaskState rsrvTask = new ReservationRemovalTaskState(); rsrvTask.resourceCount = 1; rsrvTask.resourceDescriptionLink = cs.descriptionLink; rsrvTask.groupResourcePlacementLink = cs.groupResourcePlacementLink; rsrvTask.requestTrackerLink = state.requestTrackerLink; // Completion of the reservation removal also notifies the counter task rsrvTask.serviceTaskCallback = ServiceTaskCallback.create(subTaskLink); return Operation.createPost(this, ReservationRemovalTaskFactoryService.SELF_LINK) .setBody(rsrvTask) .setCompletion((o, e) -> { if (e != null) { logWarning("Failed creating task to delete placement %s. Error: %s", cs.groupResourcePlacementLink, Utils.toString(e)); return; } }); }
@Override public void handlePost(Operation post) { initInstances(Operation.createGet(null), false, false, SystemContainerDescriptions.buildCoreAgentContainerDescription());
private void inspectContainerWithCallback( ContainerState containerState, BiConsumer<AbstractCallbackServiceHandler.CallbackServiceHandlerState, Boolean> consumer, ServiceTaskCallback serviceTaskCallback) { if (serviceTaskCallback == null) { String systemContainerName = isSystemContainer( SystemContainerDescriptions.getSystemContainerNames(), containerState.names); startAndCreateCallbackHandlerService(systemContainerName, consumer, (callback) -> inspectContainerWithCallback(containerState, consumer, callback)); return; } inspectContainer(containerState, serviceTaskCallback); }
private void queryContainerResources(ContainerOperationTaskState state) { QueryTask computeQuery = createResourcesQuery(ContainerState.class, state.resourceLinks); ServiceDocumentQuery<ContainerState> query = new ServiceDocumentQuery<>(getHost(), ContainerState.class); final List<ContainerState> documents = new ArrayList<>(state.resourceLinks.size()); query.query(computeQuery, (r) -> { if (r.hasException()) { failTask("Failure retrieving query results", r.getException()); } else if (r.hasResult()) { if (isSystemContainer(r.getResult())) { failTask(null, new LocalizableValidationException( "Day2 operations are not supported for system container", "request.system.container.day2")); } documents.add(r.getResult()); } else { if (documents.isEmpty()) { if (ContainerOperationType.DELETE.id.equals(state.operation)) { logWarning("No resources found to be removed with links: %s", state.resourceLinks); proceedTo(SubStage.COMPLETED); } else { failTask("No available resources", null); } } else { performResourceOperations(state, documents, null); } } }); }
protected void createHostShellContainer() throws Throwable { waitForServiceAvailability(ContainerFactoryService.SELF_LINK); ContainerState state = new ContainerState(); String hostId = Service.getId(dockerHostState.documentSelfLink); state.documentSelfLink = SystemContainerDescriptions.getSystemContainerSelfLink( SystemContainerDescriptions.AGENT_CONTAINER_NAME, hostId); state.parentLink = dockerHostState.documentSelfLink; PortBinding portBinding = new PortBinding(); portBinding.containerPort = "80"; portBinding.hostPort = "80"; state.ports = new ArrayList<>(); state.ports.add(portBinding); shellContainerState = doPost(state, ContainerFactoryService.SELF_LINK); }
SystemContainerDescriptions.getSystemContainerNames(), containerState.names);
if (isSystemContainer(o.getBody(ContainerState.class)) && !(isRemoveHost.get())) { logWarning("Resource [%s] will not be removed because it is a"
@Test public void verifyDefaultContainerDescriptionCreatedOnStartup() throws Throwable { ContainerDescription agentContainerDesc = getDocument( ContainerDescription.class, SystemContainerDescriptions.AGENT_CONTAINER_DESCRIPTION_LINK); assertNotNull(agentContainerDesc); assertEquals(SystemContainerDescriptions.AGENT_CONTAINER_NAME, agentContainerDesc.name); String expectedImageName = String.format("%s:%s", SystemContainerDescriptions.AGENT_IMAGE_NAME, SystemContainerDescriptions.getAgentImageVersion()); assertEquals(expectedImageName, agentContainerDesc.image); } }
}; if (SystemContainerDescriptions.getAgentImageNameAndVersion() .equals(context.containerDescription.image)) { String ref = SystemContainerDescriptions.AGENT_IMAGE_REFERENCE;
String shellContainerLink = SystemContainerDescriptions.getSystemContainerSelfLink( SystemContainerDescriptions.AGENT_CONTAINER_NAME, Service.getId(hostLink != null ? hostLink : ""));
SystemContainerDescriptions.getSystemContainerNames(), container.names);
containerState.documentSelfLink); completeSubTasksCounter(subTaskLink, null); } else if (isSystemContainer(o.getBody(ContainerState.class))) { logWarning( "Resource [%s] will not be removed because it is a system container",
@Test public void testCoreAgentContainerCreatedOnStartUp() throws Throwable { waitForServiceAvailability(SystemContainerDescriptions.AGENT_CONTAINER_DESCRIPTION_LINK); ContainerDescription agentDesc = getDocument(ContainerDescription.class, SystemContainerDescriptions.AGENT_CONTAINER_DESCRIPTION_LINK); assertNotNull(agentDesc); assertEquals(SystemContainerDescriptions.AGENT_CONTAINER_NAME, agentDesc.name); String expectedImageName = String.format("%s:%s", SystemContainerDescriptions.AGENT_IMAGE_NAME, SystemContainerDescriptions.getAgentImageVersion()); assertEquals(expectedImageName, agentDesc.image); }