下面列出了org.springframework.core.io.FileUrlResource#org.springframework.cloud.deployer.spi.core.AppDeploymentRequest 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void testAppLogRetrieval() {
Map<String, String> appProperties = new HashMap<>();
appProperties.put("killDelay", "0");
appProperties.put("exitCode", "0");
AppDefinition definition = new AppDefinition(randomName(), appProperties);
Resource resource = testApplication();
AppDeploymentRequest request = new AppDeploymentRequest(definition, resource);
String launchId1 = taskLauncher().launch(request);
Timeout timeout = deploymentTimeout();
assertThat(launchId1, eventually(hasStatusThat(
Matchers.<TaskStatus>hasProperty("state", Matchers.is(LaunchState.complete))), timeout.maxAttempts, timeout.pause));
String logContent = taskLauncher().getLog(launchId1);
assertThat(logContent, containsString("Starting DeployerIntegrationTestApplication"));
}
@Test
public void testTaskTimestampAsHdfsResourceNotExist() throws Exception {
assertThat(context.containsBean("taskLauncher"), is(true));
assertThat(context.getBean("taskLauncher"), instanceOf(YarnTaskLauncher.class));
TaskLauncher deployer = context.getBean("taskLauncher", TaskLauncher.class);
@SuppressWarnings("resource")
HdfsResourceLoader resourceLoader = new HdfsResourceLoader(getConfiguration());
resourceLoader.setHandleNoprefix(true);
Resource resource = resourceLoader.getResource("hdfs:/dataflow/artifacts/cache/timestamp-task-1.0.0.BUILD-SNAPSHOT-exec.jar");
AppDefinition definition = new AppDefinition("timestamp-task", null);
AppDeploymentRequest request = new AppDeploymentRequest(definition, resource);
Exception deployException = null;
try {
deployer.launch(request);
} catch (Exception e) {
deployException = e;
}
assertThat("Expected deploy exception", deployException, notNullValue());
}
/**
* Always delete downloaded files for static http resources. Conditionally delete maven resources.
* @param appDeploymentRequest
*/
protected void deleteLocalApplicationResourceFile(AppDeploymentRequest appDeploymentRequest) {
try {
Optional<File> fileToDelete = fileToDelete(appDeploymentRequest.getResource());
if (fileToDelete.isPresent()) {
File applicationFile = fileToDelete.get();
logger.info("Free Disk Space = {} bytes, Total Disk Space = {} bytes",
applicationFile.getFreeSpace(),
applicationFile.getTotalSpace());
boolean deleted = deleteFileOrDirectory(applicationFile);
logger.info((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());
}
}
@Test
public void deployWithEnvironmentWithMultipleCommaDelimitedValue() throws Exception {
AppDefinition definition = new AppDefinition("app-test", null);
Map<String, String> props = new HashMap<>();
props.put("spring.cloud.deployer.kubernetes.environmentVariables",
"JAVA_TOOL_OPTIONS='thing1,thing2',OPTS='thing3, thing4'");
AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), props);
deployer = new KubernetesAppDeployer(bindDeployerProperties(), null);
PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest);
assertThat(podSpec.getContainers().get(0).getEnv())
.contains(
new EnvVar("JAVA_TOOL_OPTIONS", "thing1,thing2", null),
new EnvVar("OPTS", "thing3, thing4", null));
}
@Test
// was triggered by GH-50 and subsequently GH-55
public void testNoStdoutStderrOnInheritLoggingAndNoNPEOnGetAttributes() {
Map<String, String> properties = new HashMap<>();
AppDefinition definition = new AppDefinition(randomName(), properties);
Resource resource = testApplication();
AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, Collections.singletonMap(LocalDeployerProperties.INHERIT_LOGGING, "true"));
AppDeployer deployer = appDeployer();
String deploymentId = deployer.deploy(request);
AppStatus appStatus = deployer.status(deploymentId);
assertTrue(appStatus.getInstances().size() > 0);
for (Entry<String, AppInstanceStatus> instanceStatusEntry : appStatus.getInstances().entrySet()) {
Map<String, String> attributes = instanceStatusEntry.getValue().getAttributes();
assertFalse(attributes.containsKey("stdout"));
assertFalse(attributes.containsKey("stderr"));
}
deployer.undeploy(deploymentId);
}
@Test
public void testSpringApplicationJSON() throws Exception {
LocalDeployerProperties properties = new LocalDeployerProperties();
LocalAppDeployer deployer = new LocalAppDeployer(properties);
AppDefinition definition = new AppDefinition("foo", Collections.singletonMap("foo","bar"));
Resource resource = new DockerResource("foo/bar");
Map<String, String> deploymentProperties = new HashMap<>();
deploymentProperties.put(LocalDeployerProperties.DEBUG_PORT, "9999");
deploymentProperties.put(LocalDeployerProperties.DEBUG_SUSPEND, "y");
deploymentProperties.put(LocalDeployerProperties.INHERIT_LOGGING, "true");
AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, deploymentProperties);
ProcessBuilder builder = deployer.buildProcessBuilder(request, request.getDefinition().getProperties(), Optional.of(1), "foo" );
String SAJ = LocalDeployerUtils.isWindows() ? "SPRING_APPLICATION_JSON={\\\"foo\\\":\\\"bar\\\"}" : "SPRING_APPLICATION_JSON={\"foo\":\"bar\"}";
assertThat(builder.command(), hasItems("-e", SAJ));
}
@Test
public void testConfigMapKeyRef() {
Map<String, String> props = new HashMap<>();
props.put("spring.cloud.deployer.kubernetes.configMapKeyRefs",
"[{envVarName: 'MY_ENV', configMapName: 'myConfigMap', dataKey: 'envName'}]");
AppDefinition definition = new AppDefinition("app-test", null);
AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), props);
deployer = new KubernetesAppDeployer(new KubernetesDeployerProperties(), null);
PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest);
List<EnvVar> envVars = podSpec.getContainers().get(0).getEnv();
assertEquals("Invalid number of env vars", 2, envVars.size());
EnvVar configMapKeyRefEnvVar = envVars.get(0);
assertEquals("Unexpected env var name", "MY_ENV", configMapKeyRefEnvVar.getName());
ConfigMapKeySelector configMapKeySelector = configMapKeyRefEnvVar.getValueFrom().getConfigMapKeyRef();
assertEquals("Unexpected config map name", "myConfigMap", configMapKeySelector.getName());
assertEquals("Unexpected config map data key", "envName", configMapKeySelector.getKey());
}
@Test
public void testConfigMapKeyRefGlobalFromYaml() throws Exception {
AppDefinition definition = new AppDefinition("app-test", null);
AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), null);
deployer = new KubernetesAppDeployer(bindDeployerProperties(), null);
PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest);
List<EnvVar> envVars = podSpec.getContainers().get(0).getEnv();
assertEquals("Invalid number of env vars", 3, envVars.size());
EnvVar configMapKeyRefEnvVar = envVars.get(1);
assertEquals("Unexpected env var name", "MY_ENV", configMapKeyRefEnvVar.getName());
ConfigMapKeySelector configMapKeySelector = configMapKeyRefEnvVar.getValueFrom().getConfigMapKeyRef();
assertEquals("Unexpected config map name", "myConfigMap", configMapKeySelector.getName());
assertEquals("Unexpected config map data key", "envName", configMapKeySelector.getKey());
}
public ArgumentCaptor<StreamDeploymentRequest> testStreamDeploy(Map<String, String> deploymentProperties) {
appDeploymentRequestCreator = mock(AppDeploymentRequestCreator.class);
skipperStreamDeployer = mock(SkipperStreamDeployer.class);
streamDefinitionRepository = mock(StreamDefinitionRepository.class);
this.defaultStreamService = new DefaultStreamService(streamDefinitionRepository,
this.skipperStreamDeployer, this.appDeploymentRequestCreator,
this.streamValidationService, this.auditRecordService, new DefaultStreamDefinitionService());
StreamDefinition streamDefinition = new StreamDefinition("test1", "time | log");
when(streamDefinitionRepository.findById(streamDefinition.getName())).thenReturn(Optional.of(streamDefinition));
List<AppDeploymentRequest> appDeploymentRequests = Arrays.asList(mock(AppDeploymentRequest.class));
when(appDeploymentRequestCreator.createRequests(streamDefinition, new HashMap<>()))
.thenReturn(appDeploymentRequests);
this.defaultStreamService.deployStream(streamDefinition1.getName(), deploymentProperties);
ArgumentCaptor<StreamDeploymentRequest> argumentCaptor = ArgumentCaptor.forClass(StreamDeploymentRequest.class);
verify(skipperStreamDeployer, times(1)).deployStream(argumentCaptor.capture());
return argumentCaptor;
}
/**
* Tests that command line args can be passed in.
*/
@Test
public void testCommandLineArgs() {
Map<String, String> properties = new HashMap<>();
properties.put("killDelay", "1000");
AppDefinition definition = new AppDefinition(randomName(), properties);
Resource resource = testApplication();
AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, Collections.<String, String>emptyMap(),
Collections.singletonList("--exitCode=0"));
log.info("Launching {}...", request.getDefinition().getName());
String deploymentId = taskLauncher().launch(request);
Timeout timeout = deploymentTimeout();
assertThat(deploymentId, eventually(hasStatusThat(
Matchers.<TaskStatus>hasProperty("state", Matchers.is(complete))), timeout.maxAttempts, timeout.pause));
taskLauncher().destroy(definition.getName());
}
@Test
public void createWithContainerCommand() {
KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();
DefaultContainerFactory defaultContainerFactory = new DefaultContainerFactory(
kubernetesDeployerProperties);
AppDefinition definition = new AppDefinition("app-test", null);
Resource resource = getResource();
Map<String, String> props = new HashMap<>();
props.put("spring.cloud.deployer.kubernetes.containerCommand",
"echo arg1 'arg2'");
AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition,
resource, props);
ContainerConfiguration containerConfiguration = new ContainerConfiguration("app-test", appDeploymentRequest);
Container container = defaultContainerFactory.create(containerConfiguration);
assertNotNull(container);
assertThat(container.getCommand()).containsExactly("echo", "arg1", "arg2");
}
@Test
public void createWithPorts() {
KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();
DefaultContainerFactory defaultContainerFactory = new DefaultContainerFactory(
kubernetesDeployerProperties);
AppDefinition definition = new AppDefinition("app-test", null);
Resource resource = getResource();
Map<String, String> props = new HashMap<>();
props.put("spring.cloud.deployer.kubernetes.containerPorts",
"8081, 8082, 65535");
AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition,
resource, props);
ContainerConfiguration containerConfiguration = new ContainerConfiguration("app-test", appDeploymentRequest);
Container container = defaultContainerFactory.create(containerConfiguration);
assertNotNull(container);
List<ContainerPort> containerPorts = container.getPorts();
assertNotNull(containerPorts);
assertTrue("There should be three ports set", containerPorts.size() == 3);
assertTrue(8081 == containerPorts.get(0).getContainerPort());
assertTrue(8082 == containerPorts.get(1).getContainerPort());
assertTrue(65535 == containerPorts.get(2).getContainerPort());
}
private static AppDeploymentRequest createAppDeploymentRequest(String app, String stream) {
MavenResource resource = new MavenResource.Builder()
.artifactId(app)
.groupId("org.springframework.cloud.stream.app")
.version("1.0.0.BUILD-SNAPSHOT")
.build();
Map<String, String> properties = new HashMap<>();
properties.put("server.port", "0");
if (app.contains("-source-")) {
properties.put("spring.cloud.stream.bindings.output.destination", stream);
}
else {
properties.put("spring.cloud.stream.bindings.input.destination", stream);
properties.put("spring.cloud.stream.bindings.input.group", "default");
}
AppDefinition definition = new AppDefinition(app, properties);
Map<String, String> deploymentProperties = new HashMap<>();
deploymentProperties.put(AppDeployer.GROUP_PROPERTY_KEY, stream);
/*
* This will allow output to be logged to the output of the process that started
* the application.
*/
deploymentProperties.put(LocalDeployerProperties.INHERIT_LOGGING, "true");
AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, deploymentProperties);
return request;
}
/**
* Creates an {@link AppDeploymentRequest}.
*
* @param applicationSpec the Spring Cloud Deployer application spec
* @param releaseName the release name
* @param version the release version
* @return a created AppDeploymentRequest
*/
public AppDeploymentRequest createAppDeploymentRequest(SpringCloudDeployerApplicationManifest applicationSpec, String releaseName,
String version) {
SpringCloudDeployerApplicationSpec spec = applicationSpec.getSpec();
Map<String, String> applicationProperties = new TreeMap<>();
if (spec.getApplicationProperties() != null) {
applicationProperties.putAll(spec.getApplicationProperties());
}
// we need to keep group name same for consumer groups not getting broken, but
// app name needs to differentiate as otherwise it may result same deployment id and
// failure on a deployer.
AppDefinition appDefinition = new AppDefinition(applicationSpec.getApplicationName() + "-v" + version,
applicationProperties);
Resource resource;
try {
resource = delegatingResourceLoader.getResource(getResourceLocation(spec.getResource(), spec.getVersion()));
}
catch (Exception e) {
throw new SkipperException(
"Could not load Resource " + spec.getResource() + ". Message = " + e.getMessage(), e);
}
Map<String, String> deploymentProperties = new TreeMap<>();
if (spec.getDeploymentProperties() != null) {
deploymentProperties.putAll(spec.getDeploymentProperties());
}
if (!deploymentProperties.containsKey(AppDeployer.GROUP_PROPERTY_KEY)) {
logger.debug("Defaulting spring.cloud.deployer.group=" + releaseName);
deploymentProperties.put(AppDeployer.GROUP_PROPERTY_KEY, releaseName);
}
AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(appDefinition, resource,
deploymentProperties);
return appDeploymentRequest;
}
/**
* Deploy a stream as defined by its stream name and optional deployment properties.
*
* @param streamDefinition the stream definition to deploy
* @param deploymentProperties the deployment properties for the stream
* @return return a skipper release {@link Release}
*/
private Release doDeployStream(StreamDefinition streamDefinition, Map<String, String> deploymentProperties) {
// Extract skipper properties
Map<String, String> skipperDeploymentProperties = getSkipperProperties(deploymentProperties);
if (!skipperDeploymentProperties.containsKey(SkipperStream.SKIPPER_PACKAGE_VERSION)) {
skipperDeploymentProperties.put(SkipperStream.SKIPPER_PACKAGE_VERSION, DEFAULT_SKIPPER_PACKAGE_VERSION);
}
// Create map without any skipper properties
Map<String, String> deploymentPropertiesToUse = deploymentProperties.entrySet().stream()
.filter(mapEntry -> !mapEntry.getKey().startsWith(SkipperStream.SKIPPER_KEY_PREFIX))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
List<AppDeploymentRequest> appDeploymentRequests = this.appDeploymentRequestCreator
.createRequests(streamDefinition, deploymentPropertiesToUse);
DeploymentPropertiesUtils.validateSkipperDeploymentProperties(deploymentPropertiesToUse);
StreamDeploymentRequest streamDeploymentRequest = new StreamDeploymentRequest(streamDefinition.getName(),
streamDefinition.getDslText(), appDeploymentRequests, skipperDeploymentProperties);
Release release = this.skipperStreamDeployer.deployStream(streamDeploymentRequest);
if (release != null) {
updateStreamDefinitionFromReleaseManifest(streamDefinition.getName(), release.getManifest().getData());
}
else {
logger.error("Missing skipper release after Stream deploy!");
}
return release;
}
/**
* Get the RestartPolicy setting for the deployment request.
*
* @param request The deployment request.
* @return Whether RestartPolicy is requested
*/
protected RestartPolicy getRestartPolicy(AppDeploymentRequest request) {
String restartPolicyString =
PropertyParserUtils.getDeploymentPropertyValue(request.getDeploymentProperties(),
"spring.cloud.deployer.kubernetes.restartPolicy");
RestartPolicy restartPolicy = (StringUtils.isEmpty(restartPolicyString)) ? this.taskLauncherProperties.getRestartPolicy() :
RestartPolicy.valueOf(restartPolicyString);
if (this.properties.isCreateJob()) {
Assert.isTrue(!restartPolicy.equals(RestartPolicy.Always), "RestartPolicy should not be 'Always' when the JobSpec is used.");
}
return restartPolicy;
}
private String deploy(String jarName, String deployment, String application, String... args)
throws Exception {
Resource resource = new FileSystemResource(
ArchiveUtils.getArchiveRoot(ArchiveUtils.getArchive(jarName)));
AppDefinition definition = new AppDefinition(resource.getFilename(),
properties(application));
AppDeploymentRequest request = new AppDeploymentRequest(definition, resource,
properties(deployment), Arrays.asList(args));
String deployed = deployer.deploy(request);
return deployed;
}
/**
* Stages the application specified in the {@link ScheduleRequest} on the CF server.
* @param scheduleRequest {@link ScheduleRequest} containing the information required to schedule a task.
* @return the command string for the scheduled task.
*/
private String stageTask(ScheduleRequest scheduleRequest) {
logger.debug(String.format("Staging Task: ",
scheduleRequest.getDefinition().getName()));
AppDeploymentRequest request = new AppDeploymentRequest(
scheduleRequest.getDefinition(),
scheduleRequest.getResource(),
scheduleRequest.getDeploymentProperties(),
scheduleRequest.getCommandlineArguments());
SummaryApplicationResponse response = taskLauncher.stage(request);
return taskLauncher.getCommand(response, request);
}
@Before
public void setUp() throws Exception {
this.deploymentProperties = new HashMap<>();
this.deploymentRequest = new AppDeploymentRequest(new AppDefinition("foo", Collections.emptyMap()), new FileSystemResource(""), deploymentProperties);
this.kubernetesDeployerProperties = new KubernetesDeployerProperties();
this.deploymentPropertiesResolver = new DeploymentPropertiesResolver(
KubernetesDeployerProperties.KUBERNETES_DEPLOYER_PROPERTIES_PREFIX, this.kubernetesDeployerProperties);
}
private void validateAppVersionIsRegistered(String registeredAppName, AppDeploymentRequest appDeploymentRequest, String appVersion) {
String appTypeString = appDeploymentRequest.getDefinition().getProperties()
.get(DataFlowPropertyKeys.STREAM_APP_TYPE);
ApplicationType applicationType = ApplicationType.valueOf(appTypeString);
if (!this.appRegistryService.appExist(registeredAppName, applicationType, appVersion)) {
throw new IllegalStateException(String.format("The %s:%s:%s app is not registered!",
registeredAppName, appTypeString, appVersion));
}
}
@Test
public void testTaskTimestamp() throws Exception {
assertThat(context.containsBean("taskLauncher"), is(true));
assertThat(context.getBean("taskLauncher"), instanceOf(YarnTaskLauncher.class));
TaskLauncher deployer = context.getBean("taskLauncher", TaskLauncher.class);
YarnCloudAppService yarnCloudAppService = context.getBean(YarnCloudAppService.class);
MavenProperties m2Properties = new MavenProperties();
Map<String, RemoteRepository> remoteRepositories = new HashMap<>();
remoteRepositories.put("default", new RemoteRepository("https://repo.spring.io/libs-snapshot-local"));
m2Properties.setRemoteRepositories(remoteRepositories);
MavenResource resource = new MavenResource.Builder(m2Properties)
.artifactId("timestamp-task")
.groupId(GROUP_ID)
.version(artifactVersion)
.extension("jar")
.classifier("exec")
.build();
AppDefinition definition = new AppDefinition("timestamp-task", null);
AppDeploymentRequest request = new AppDeploymentRequest(definition, resource);
String id = deployer.launch(request);
assertThat(id, notNullValue());
ApplicationId applicationId = assertWaitApp(2, TimeUnit.MINUTES, yarnCloudAppService);
assertWaitFileContent(2, TimeUnit.MINUTES, applicationId, "Started TaskApplication");
List<Resource> resources = ContainerLogUtils.queryContainerLogs(
getYarnCluster(), applicationId);
assertThat(resources, notNullValue());
assertThat(resources.size(), is(4));
}
@Override
public String launch(AppDeploymentRequest request) {
String launchId = wrapped.launch(request);
deployedApps.add(request.getDefinition().getName());
launchedTasks.add(launchId);
return launchId;
}
@Test
public void createDefaultProbePorts() {
int defaultPort = 8080;
KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();
DefaultContainerFactory defaultContainerFactory = new DefaultContainerFactory(
kubernetesDeployerProperties);
AppDefinition definition = new AppDefinition("app-test", null);
Resource resource = getResource();
Map<String, String> props = new HashMap<>();
AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition,
resource, props);
ContainerConfiguration containerConfiguration = new ContainerConfiguration("app-test", appDeploymentRequest)
.withHostNetwork(true)
.withExternalPort(defaultPort);
Container container = defaultContainerFactory.create(containerConfiguration);
assertNotNull(container);
List<ContainerPort> containerPorts = container.getPorts();
assertNotNull(containerPorts);
assertTrue("Only the default container port should set", containerPorts.size() == 1);
assertTrue(8080 == containerPorts.get(0).getContainerPort());
assertTrue(8080 == containerPorts.get(0).getHostPort());
assertTrue(8080 == container.getLivenessProbe().getHttpGet().getPort().getIntVal());
assertTrue(8080 == container.getReadinessProbe().getHttpGet().getPort().getIntVal());
}
@Test
public void deployWithNodeSelectorGlobalProperty() throws Exception {
AppDefinition definition = new AppDefinition("app-test", null);
AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), null);
KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();
kubernetesDeployerProperties.setNodeSelector("disktype:ssd, os:qnx");
deployer = new KubernetesAppDeployer(kubernetesDeployerProperties, null);
PodSpec podSpec = deployer.createPodSpec(appDeploymentRequest);
assertThat(podSpec.getNodeSelector()).containsOnly(entry("disktype", "ssd"), entry("os", "qnx"));
}
protected Map<String, String> createSpringApplicationJson(AppDeploymentRequest request) {
String value = "{}";
try {
value = new ObjectMapper().writeValueAsString(
Optional.ofNullable(request.getDefinition().getProperties())
.orElse(Collections.emptyMap()));
} catch (JsonProcessingException e) {}
Map<String, String> springApp = new HashMap<>();
if (!"{}".equals(value)) {
springApp.put("name", "SPRING_APPLICATION_JSON");
springApp.put("value", value);
}
return springApp;
}
protected List<String> createCommandArgs(AppDeploymentRequest request) {
List<String> cmdArgs = new LinkedList<String>();
// add provided command line args
cmdArgs.addAll(request.getCommandlineArguments());
logger.debug("Using command args: " + cmdArgs);
return cmdArgs;
}
@Test(expected = IllegalArgumentException.class)
public void testInvalidDeploymentLabelDelimiter() {
Map<String, String> props = Collections.singletonMap("spring.cloud.deployer.kubernetes.deploymentLabels",
"label1|value1");
AppDefinition definition = new AppDefinition("app-test", null);
AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition, getResource(), props);
this.deploymentPropertiesResolver.getDeploymentLabels(appDeploymentRequest.getDeploymentProperties());
}
@Test
public void createCustomReadinessPortFromAppRequest() {
int defaultPort = 8080;
int readinessPort = 8090;
KubernetesDeployerProperties kubernetesDeployerProperties = new KubernetesDeployerProperties();
DefaultContainerFactory defaultContainerFactory = new DefaultContainerFactory(
kubernetesDeployerProperties);
AppDefinition definition = new AppDefinition("app-test", null);
Resource resource = getResource();
Map<String, String> props = new HashMap<>();
props.put("spring.cloud.deployer.kubernetes.readinessProbePort", Integer.toString(readinessPort));
AppDeploymentRequest appDeploymentRequest = new AppDeploymentRequest(definition,
resource, props);
ContainerConfiguration containerConfiguration = new ContainerConfiguration("app-test", appDeploymentRequest)
.withHostNetwork(true)
.withExternalPort(defaultPort);
Container container = defaultContainerFactory.create(containerConfiguration);
assertNotNull(container);
List<ContainerPort> containerPorts = container.getPorts();
assertNotNull(containerPorts);
assertTrue("Only two container ports should be set", containerPorts.size() == 2);
assertTrue(8080 == containerPorts.get(0).getContainerPort());
assertTrue(8080 == containerPorts.get(0).getHostPort());
assertTrue(8090 == containerPorts.get(1).getContainerPort());
assertTrue(8090 == containerPorts.get(1).getHostPort());
assertTrue(8090 == container.getReadinessProbe().getHttpGet().getPort().getIntVal());
}
public StreamDeploymentRequest(String streamName, String dslText, List<AppDeploymentRequest> appDeploymentRequests,
Map<String, String> streamDeployerProperties) {
Assert.hasText(streamName, "stream name is required");
Assert.hasText(dslText, "dslText is required");
Assert.notNull(appDeploymentRequests, "appDeploymentRequests can not be null");
Assert.notNull(streamDeployerProperties, "streamDeployerProperties can not be null");
this.streamName = streamName;
this.dslText = dslText;
this.appDeploymentRequests = appDeploymentRequests;
this.streamDeployerProperties = streamDeployerProperties;
}
@Test
@DirtiesContext
public void executeComposedTaskWithEnabledUserAccessToken2() {
initializeSuccessfulRegistry(appRegistry);
final List<String> arguments = new ArrayList<>();
arguments.add("--dataflow-server-use-user-access-token = true");
AppDeploymentRequest request = getAppDeploymentRequestForToken(
prepareEnvironmentForTokenTests(this.taskSaveService,
this.taskLauncher, this.appRegistry), arguments,
this.taskExecutionService, this.taskLauncher);
assertTrue("Should contain the property 'dataflow-server-access-token'",
request.getDefinition().getProperties().containsKey("dataflow-server-access-token"));
assertEquals("foo-bar-123-token", request.getDefinition().getProperties().get("dataflow-server-access-token"));
}