/** * Return a Path to the application Resource or {@literal null} if the request is for a Docker image. * * @see #getDockerImage(AppDeploymentRequest) */ Path getApplication(AppDeploymentRequest request) { try { if (!request.getResource().getURI().toString().startsWith("docker:")) { return request.getResource().getFile().toPath(); } else { return null; } } catch (IOException e) { throw Exceptions.propagate(e); } }
protected void deleteLocalApplicationResourceFile(AppDeploymentRequest appDeploymentRequest) { try { File applicationFile = appDeploymentRequest.getResource().getFile(); logger.info("Free Disk Space = {} bytes, Total Disk Space = {} bytes", applicationFile.getFreeSpace(), applicationFile.getTotalSpace()); if (appDeploymentRequest.getResource().getURI().getScheme().toLowerCase().startsWith("http")) { boolean deleted = applicationFile.delete(); logger.debug((deleted) ? "Successfully deleted the application resource: "+ applicationFile.getCanonicalPath() : "Could not delete the application resource: "+ applicationFile.getCanonicalPath()); } } catch (IOException e) { logger.warn("Exception deleting the application resource after successful CF push request." + " This could cause increase in disk space usage. Exception message: " + e.getMessage()); } }
/** * Return a Docker image identifier if the application Resource is for a Docker image, or {@literal null} otherwise. * * @see #getApplication(AppDeploymentRequest) */ String getDockerImage(AppDeploymentRequest request) { try { String uri = request.getResource().getURI().toString(); if (uri.startsWith("docker:")) { return uri.substring("docker:".length()); } else { return null; } } catch (IOException e) { throw Exceptions.propagate(e); } }
private List<String> addDockerOptions(AppDeploymentRequest request, Map<String, String> appInstanceEnv, Optional<Integer> appInstanceNumber) { List<String> commands = new ArrayList<>(); commands.add("docker"); commands.add("run"); // Add env vars for (String env : appInstanceEnv.keySet()) { commands.add("-e"); commands.add(String.format("%s=%s", env, appInstanceEnv.get(env))); } setPort(commands, appInstanceEnv); if(request.getDeploymentProperties().containsKey(DOCKER_CONTAINER_NAME_KEY)) { if(appInstanceNumber.isPresent()) { commands.add(String.format("--name=%s-%d", request.getDeploymentProperties().get(DOCKER_CONTAINER_NAME_KEY), appInstanceNumber.get())); } else { commands.add(String.format("--name=%s", request.getDeploymentProperties().get(DOCKER_CONTAINER_NAME_KEY))); } } DockerResource dockerResource = (DockerResource) request.getResource(); try { String dockerImageURI = dockerResource.getURI().toString(); commands.add(dockerImageURI.substring("docker:".length())); } catch (IOException e) { throw new IllegalStateException(e); } return commands; }
formatApplicationProperties(request, appInstanceEnv); if (request.getResource() instanceof DockerResource) { commands = this.dockerCommandBuilder.buildExecutionCommand(request, appPropertiesToUse, appInstanceNumber); if (!(request.getResource() instanceof DockerResource)) { builder.environment().putAll(appPropertiesToUse); portToUse); if(request.getResource() instanceof DockerResource) { builder.command().add(2, "-e"); builder.command().add(3, "JAVA_TOOL_OPTIONS="+ debugInstruction);
protected void addJavaExecutionOptions(List<String> commands, AppDeploymentRequest request) { Map<String, String> deploymentProperties = request.getDeploymentProperties(); if (containsKey(deploymentProperties, MAIN) || containsKey(deploymentProperties, CLASSPATH)) { Assert.isTrue(containsKey(deploymentProperties, MAIN) && containsKey(deploymentProperties, CLASSPATH), PREFIX + "." + MAIN + " and " + PREFIX + "." + CLASSPATH + " deployment properties are both required if either is provided."); commands.add("-cp"); commands.add(getValue(deploymentProperties, CLASSPATH)); commands.add(getValue(deploymentProperties, MAIN)); } else { commands.add("-jar"); Resource resource = request.getResource(); try { commands.add(resource.getFile().getAbsolutePath()); } catch (IOException e) { throw new IllegalStateException(e); } } }
public String deploy(AppDeploymentRequest request) { ThinJarAppWrapper wrapper = new ThinJarAppWrapper(request.getResource(), getName(request), getProfiles(request)); String id = wrapper.getId(); if (!apps.containsKey(id)) { apps.put(id, wrapper); } else { wrapper = apps.get(id); } wrapper.run(getProperties(request), request.getCommandlineArguments()); return id; }
private Container createContainer(AppDeploymentRequest request) { Container container = new Container(); Docker docker = new Docker(); String image = null; try { image = request.getResource().getURI().getSchemeSpecificPart(); } catch (IOException e) { throw new IllegalArgumentException("Unable to get URI for " + request.getResource(), e); } logger.info("Using Docker image: " + image); docker.setImage(image); Port port = new Port(8080); port.setHostPort(0); docker.setPortMappings(Arrays.asList(port)); docker.setNetwork("BRIDGE"); container.setDocker(docker); return container; }
@Override public String deploy(AppDeploymentRequest request) { logger.trace("Entered deploy: Deploying AppDeploymentRequest: AppDefinition = {}, Resource = {}, Deployment Properties = {}", request.getDefinition(), request.getResource(), request.getDeploymentProperties()); String deploymentId = deploymentId(request);
logger.info("Deploy request deployment properties {}", request.getDeploymentProperties()); logger.info("Deploy definition {}", request.getDefinition()); Resource resource = request.getResource(); AppDefinition definition = request.getDefinition();
try { logger.info(String.format(deployLoggingString, appDeploymentRequest.getDefinition().getName(), streamDeploymentRequest.getStreamName(), appDeploymentRequest.getResource().getURI())); String id = this.appDeployer.deploy(appDeploymentRequest); this.deploymentIdRepository.save(DeploymentKey for (AppDeploymentRequest appDeploymentRequest : streamDeploymentRequest.getAppDeploymentRequests()) { deploymentProperties.put(appDeploymentRequest.getDefinition().getName(), appDeploymentRequest.getDeploymentProperties()); appVersions.put(appDeploymentRequest.getDefinition().getName(), this.appRegistry.getResourceVersion(appDeploymentRequest.getResource()));
String resourceWithoutVersion = this.appRegistryService.getResourceWithoutVersion(appDeploymentRequest.getResource()); specMap.put("resource", resourceWithoutVersion); specMap.put("applicationProperties", appDeploymentRequest.getDefinition().getProperties()); specMap.put("deploymentProperties", appDeploymentRequest.getDeploymentProperties()); String version = this.appRegistryService.getResourceVersion(appDeploymentRequest.getResource());
Resource resource = request.getResource(); final String clusterId = group + ":" + definition.getName();
String resourceWithoutVersion = this.appRegistryService.getResourceWithoutVersion(appDeploymentRequest.getResource()); specMap.put("resource", resourceWithoutVersion); specMap.put("applicationProperties", appDeploymentRequest.getDefinition().getProperties()); specMap.put("deploymentProperties", appDeploymentRequest.getDeploymentProperties()); String version = this.appRegistryService.getResourceVersion(appDeploymentRequest.getResource());
private void validateAllAppsRegistered(StreamDeploymentRequest streamDeploymentRequest) { if (streamDeploymentRequest.getAppDeploymentRequests() == null || streamDeploymentRequest.getAppDeploymentRequests().isEmpty()) { // nothing to validate. return; } // throw as at this point we should have definition StreamDefinition streamDefinition = this.streamDefinitionRepository .findById(streamDeploymentRequest.getStreamName()) .orElseThrow(() -> new NoSuchStreamDefinitionException(streamDeploymentRequest.getStreamName())); for (AppDeploymentRequest adr : streamDeploymentRequest.getAppDeploymentRequests()) { String version = this.appRegistryService.getResourceVersion(adr.getResource()); validateAppVersionIsRegistered(getRegisteredName(streamDefinition, adr.getDefinition().getName()), adr, version); } }
image = request.getResource().getURI().getSchemeSpecificPart(); throw new IllegalArgumentException("Unable to get URI for " + request.getResource(), e);
String image = null; try { image = request.getResource().getURI().getSchemeSpecificPart(); } catch (IOException e) { throw new IllegalArgumentException("Unable to get URI for " + request.getResource(), e);
private void validateAllAppsRegistered(StreamDeploymentRequest streamDeploymentRequest) { StreamDefinition streamDefinition = this.streamDefinitionRepository.findOne(streamDeploymentRequest.getStreamName()); for (AppDeploymentRequest adr : streamDeploymentRequest.getAppDeploymentRequests()) { String version = this.appRegistryService.getResourceVersion(adr.getResource()); validateAppVersionIsRegistered(getRegisteredName(streamDefinition, adr.getDefinition().getName()), adr, version); } }