Search in sources :

Example 1 with KeyValuePair

use of com.amazonaws.services.ecs.model.KeyValuePair in project gocd-ecs-elastic-agent by gocd.

the class CreateAgentRequest method autoRegisterPropertiesAsEnvironmentVars.

public Set<KeyValuePair> autoRegisterPropertiesAsEnvironmentVars(String elasticAgentId) {
    Set<KeyValuePair> properties = new HashSet<>();
    if (isNotBlank(autoRegisterKey())) {
        properties.add(new KeyValuePair().withName("GO_EA_AUTO_REGISTER_KEY").withValue(autoRegisterKey()));
    }
    if (isNotBlank(environment())) {
        properties.add(new KeyValuePair().withName("GO_EA_AUTO_REGISTER_ENVIRONMENT").withValue(environment()));
    }
    properties.add(new KeyValuePair().withName("GO_EA_AUTO_REGISTER_ELASTIC_AGENT_ID").withValue(elasticAgentId));
    properties.add(new KeyValuePair().withName("GO_EA_AUTO_REGISTER_ELASTIC_PLUGIN_ID").withValue(Constants.PLUGIN_ID));
    properties.add(new KeyValuePair().withName("GO_EA_GUID").withValue(UUID.randomUUID().toString()));
    return properties;
}
Also used : KeyValuePair(com.amazonaws.services.ecs.model.KeyValuePair) HashSet(java.util.HashSet)

Example 2 with KeyValuePair

use of com.amazonaws.services.ecs.model.KeyValuePair in project gocd-ecs-elastic-agent by gocd.

the class ContainerDefinitionBuilder method getKeyValuePairs.

private Collection<KeyValuePair> getKeyValuePairs(Collection<String> lines) {
    Collection<KeyValuePair> env = new HashSet<>();
    for (String variable : lines) {
        if (StringUtils.contains(variable, "=")) {
            String[] pair = variable.split("=", 2);
            env.add(new KeyValuePair().withName(pair[0]).withValue(pair[1]));
        } else {
            LOG.warn(format("Ignoring variable {0} as it is not in acceptable format, Variable must follow `VARIABLE_NAME=VARIABLE_VALUE` format.", variable));
        }
    }
    return env;
}
Also used : KeyValuePair(com.amazonaws.services.ecs.model.KeyValuePair) HashSet(java.util.HashSet)

Example 3 with KeyValuePair

use of com.amazonaws.services.ecs.model.KeyValuePair in project gocd-ecs-elastic-agent by gocd.

the class ContainerDefinitionBuilder method environmentFrom.

private Collection<KeyValuePair> environmentFrom() {
    Collection<KeyValuePair> env = getKeyValuePairs(pluginSettings.getEnvironmentVariables());
    env.addAll(getKeyValuePairs(request.elasticProfile().getEnvironment()));
    env.add(new KeyValuePair().withName("GO_EA_MODE").withValue(mode()));
    env.add(new KeyValuePair().withName("GO_EA_SERVER_URL").withValue(pluginSettings.getGoServerUrl()));
    env.addAll(request.autoRegisterPropertiesAsEnvironmentVars(taskName));
    return env;
}
Also used : KeyValuePair(com.amazonaws.services.ecs.model.KeyValuePair)

Example 4 with KeyValuePair

use of com.amazonaws.services.ecs.model.KeyValuePair in project gocd-ecs-elastic-agent by gocd.

the class ContainerDefinitionBuilderTest method shouldBuildContainerDefinitionWithEnvironments.

@Test
void shouldBuildContainerDefinitionWithEnvironments() {
    when(elasticAgentProfileProperties.getImage()).thenReturn("alpine");
    when(elasticAgentProfileProperties.getEnvironment()).thenReturn(Arrays.asList("TZ=PST"));
    when(pluginSettings.getEnvironmentVariables()).thenReturn(Arrays.asList("JAVA_HOME=/var/lib/java"));
    when(pluginSettings.getGoServerUrl()).thenReturn("https://foo.server/go");
    when(createAgentRequest.autoRegisterKey()).thenReturn("some-auto-register-key");
    when(createAgentRequest.environment()).thenReturn("some-environment");
    when(createAgentRequest.autoRegisterPropertiesAsEnvironmentVars("foo")).thenCallRealMethod();
    ContainerDefinitionBuilder builder = new ContainerDefinitionBuilder().withName("foo").pluginSettings(pluginSettings).createAgentRequest(createAgentRequest);
    final ContainerDefinition containerDefinition = builder.build();
    assertThat(containerDefinition.getEnvironment()).contains(new KeyValuePair().withName("TZ").withValue("PST"), new KeyValuePair().withName("JAVA_HOME").withValue("/var/lib/java"), new KeyValuePair().withName("GO_EA_MODE").withValue("dev"), new KeyValuePair().withName("GO_EA_SERVER_URL").withValue("https://foo.server/go"), new KeyValuePair().withName("GO_EA_AUTO_REGISTER_KEY").withValue("some-auto-register-key"), new KeyValuePair().withName("GO_EA_AUTO_REGISTER_ENVIRONMENT").withValue("some-environment"), new KeyValuePair().withName("GO_EA_AUTO_REGISTER_ELASTIC_AGENT_ID").withValue("foo"), new KeyValuePair().withName("GO_EA_AUTO_REGISTER_ELASTIC_PLUGIN_ID").withValue(PLUGIN_ID));
}
Also used : KeyValuePair(com.amazonaws.services.ecs.model.KeyValuePair) ContainerDefinition(com.amazonaws.services.ecs.model.ContainerDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

KeyValuePair (com.amazonaws.services.ecs.model.KeyValuePair)4 HashSet (java.util.HashSet)2 ContainerDefinition (com.amazonaws.services.ecs.model.ContainerDefinition)1 Test (org.junit.jupiter.api.Test)1