/** * Helper method executing Operation.createGet. * Calls {@code callbackFunction} passing the result, * or in case of exception just logs it and returns. * * @param service {@link Service} * @param link document link * @param callbackFunction callback to receive the result * @param <T> document state class, extends {@link ServiceDocument} */ public static <T extends ServiceDocument> void getDocumentState(Service service, String link, Class<T> classT, Consumer<T> callbackFunction) { getDocumentState(service, link, classT, callbackFunction, null); }
OperationUtil.getDocumentState(this, descriptionLink, ContainerDescription.class, (ContainerDescription contDesc) -> installSystemContainerToHost( containerHostLink, systemContainerName, contDesc)); OperationUtil.getDocumentState(this, containerHostLink, ComputeState.class, (ComputeState host) -> { if (ContainerHostUtil.getDriver(host) == null) {
private void handleDiscoveredSystemContainer(ContainerState containerState, String containerHostLink, ContainerDescription containerDesc) { if (containerDesc == null) { OperationUtil.getDocumentState(this, containerState.descriptionLink, ContainerDescription.class, (ContainerDescription contDesc) -> handleDiscoveredSystemContainer( containerState, containerHostLink, contDesc)); return; } ContainerVersion containerVersion = ContainerVersion.fromImageName(containerState.image); ContainerVersion containerDescVersion = ContainerVersion.fromImageName(containerDesc.image); if (containerVersion.compareTo(containerDescVersion) < 0) { // if container version is old, delete the container and create it again recreateSystemContainer(containerState, containerHostLink); } else { // check if system ContainerState exists. If not, start won't work as docker-adapter // will refer to missing ContainerState resulting in failure in starting operation. checkIfSystemContainerStateExistsBeforeStartIt(containerState, containerDesc, containerHostLink); } }
protected void uploadCertificate(String hostLink, String registryAddress, String certificate, List<String> tenantLinks) { OperationUtil.getDocumentState(this, hostLink, ComputeState.class, (ComputeState host) -> { if (ContainerHostUtil.isVicHost(host)) { logInfo("Skip installing certificate for VIC host [%s]", hostLink); return; } ShellContainerExecutorState execState = new ShellContainerExecutorState(); execState.command = new String[] { "sh", "/copy-certificate.sh", getCertificateDirName(registryAddress), certificate }; try { processUploadCertificateQuery(execState, hostLink, MAX_RETRIES, registryAddress, tenantLinks); } catch (Throwable t) { logSevere("Fail to upload registry certificate to host %s: " + "failed to connect to shell container executor service.", hostLink); } }); }
private void execute(Operation post, String hostLink, String containerLink) { ShellContainerExecutorState body = post.getBody(ShellContainerExecutorState.class); BiConsumer<ContainerState, Exception> callback = (container, e) -> { if (e != null) { post.fail(e); } else { executeCommand(container, body, post); } }; if (hostLink != null) { // execute command in system agent, check if supported OperationUtil.getDocumentState(this, hostLink, ComputeState.class, (ComputeState host) -> { if (isAgentSupported(host)) { getContainerWhenAvailable(containerLink, RETRY_COUNT, callback); } else { logInfo("Agent not supported for host %s", hostLink); post.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED); post.complete(); } }, post::fail); } else { // execute command for specific container getContainerWhenAvailable(containerLink, RETRY_COUNT, callback); } }
OperationUtil.getDocumentState(this, container.documentSelfLink, ContainerState.class, (ContainerState c) -> { if (c.ports == null) { OperationUtil.getDocumentState(this, container.parentLink, ComputeState.class, (ComputeState h) -> importAgentSslCertificate(container, h, retryCount)); return;