Search in sources :

Example 1 with ServiceSpec

use of com.mesosphere.sdk.specification.ServiceSpec in project dcos-commons by mesosphere.

the class ArtifactQueries method getTemplate.

/**
 * Produces the content of the requested configuration template, or returns an error if that template doesn't exist
 * or the data couldn't be read. Configuration templates are versioned against configuration IDs, which (despite the
 * similar naming) are not directly related. See also {@link ConfigQueries} for more information on configuration
 * IDs.
 *
 * @param configurationId the id of the configuration set to be retrieved from -- this should match the
 *     configuration the task is on. this allows old tasks to continue retrieving old configurations
 * @param podType the name/type of the pod, eg 'index' or 'data'
 * @param taskName the name of the task
 * @param configurationName the name of the configuration to be retrieved
 * @return an HTTP response containing the content of the requested configuration, or an HTTP error
 * @see ConfigQueries
 */
public static Response getTemplate(ConfigStore<ServiceSpec> configStore, String configurationId, String podType, String taskName, String configurationName) {
    LOGGER.info("Attempting to fetch template '{}' from config '{}' with pod '{}', task '{}'", configurationName, configurationId, podType, taskName);
    UUID uuid;
    try {
        uuid = UUID.fromString(configurationId);
    } catch (IllegalArgumentException ex) {
        LOGGER.warn(String.format("Failed to parse requested configuration id as a UUID: '%s'", configurationId), ex);
        return Response.status(Response.Status.BAD_REQUEST).build();
    }
    ServiceSpec serviceSpec;
    try {
        serviceSpec = configStore.fetch(uuid);
    } catch (ConfigStoreException ex) {
        if (ex.getReason() == Reason.NOT_FOUND) {
            LOGGER.warn(String.format("Requested configuration '%s' doesn't exist", configurationId), ex);
            return Response.status(Response.Status.NOT_FOUND).build();
        }
        LOGGER.error(String.format("Failed to fetch requested configuration with id '%s'", configurationId), ex);
        return Response.serverError().build();
    }
    try {
        ConfigFileSpec config = getConfigFile(getTask(getPod(serviceSpec, podType), taskName), configurationName);
        return plainOkResponse(config.getTemplateContent());
    } catch (Exception ex) {
        LOGGER.warn(String.format("Couldn't find requested template in config '%s'", configurationId), ex);
        return Response.status(Response.Status.NOT_FOUND).build();
    }
}
Also used : ConfigFileSpec(com.mesosphere.sdk.specification.ConfigFileSpec) ConfigStoreException(com.mesosphere.sdk.state.ConfigStoreException) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) UUID(java.util.UUID) ConfigStoreException(com.mesosphere.sdk.state.ConfigStoreException)

Example 2 with ServiceSpec

use of com.mesosphere.sdk.specification.ServiceSpec in project dcos-commons by mesosphere.

the class UserCannotChangeTest method testDifferentServiceUser.

@Test
public void testDifferentServiceUser() {
    when(mockNewPodSpec.getUser()).thenReturn(Optional.of(USER_A));
    ServiceSpec oldServiceSpec = DefaultServiceSpec.newBuilder().name("svc").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockOldPodSpec)).user(USER_A).build();
    ServiceSpec newServiceSpec = DefaultServiceSpec.newBuilder().name("svc").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockNewPodSpec)).user(USER_B).build();
    Assert.assertEquals(1, VALIDATOR.validate(Optional.of(oldServiceSpec), newServiceSpec).size());
}
Also used : DefaultServiceSpec(com.mesosphere.sdk.specification.DefaultServiceSpec) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) Test(org.junit.Test)

Example 3 with ServiceSpec

use of com.mesosphere.sdk.specification.ServiceSpec in project dcos-commons by mesosphere.

the class UserCannotChangeTest method testOldPodNotSettingUserButNewPodSettingUser.

@Test
public void testOldPodNotSettingUserButNewPodSettingUser() {
    when(mockOldPodSpec.getUser()).thenReturn(Optional.empty());
    when(mockNewPodSpec.getUser()).thenReturn(Optional.of(USER_B));
    ServiceSpec oldServiceSpec = DefaultServiceSpec.newBuilder().name("svc").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockOldPodSpec)).build();
    ServiceSpec newServiceSpec = DefaultServiceSpec.newBuilder().name("svc").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockNewPodSpec)).build();
    Assert.assertEquals(2, VALIDATOR.validate(Optional.of(oldServiceSpec), newServiceSpec).size());
}
Also used : DefaultServiceSpec(com.mesosphere.sdk.specification.DefaultServiceSpec) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) Test(org.junit.Test)

Example 4 with ServiceSpec

use of com.mesosphere.sdk.specification.ServiceSpec in project dcos-commons by mesosphere.

the class UserCannotChangeTest method testSameUser.

@Test
public void testSameUser() {
    when(mockNewPodSpec.getUser()).thenReturn(Optional.of(USER_A));
    ServiceSpec oldServiceSpec = DefaultServiceSpec.newBuilder().name("svc").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockOldPodSpec)).build();
    ServiceSpec newServiceSpec = DefaultServiceSpec.newBuilder().name("svc").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockNewPodSpec)).build();
    Assert.assertEquals(0, VALIDATOR.validate(Optional.of(oldServiceSpec), newServiceSpec).size());
}
Also used : DefaultServiceSpec(com.mesosphere.sdk.specification.DefaultServiceSpec) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) Test(org.junit.Test)

Example 5 with ServiceSpec

use of com.mesosphere.sdk.specification.ServiceSpec in project dcos-commons by mesosphere.

the class UserCannotChangeTest method testOldPodSettingUserButNewPodNotSettingUser.

@Test
public void testOldPodSettingUserButNewPodNotSettingUser() {
    when(mockNewPodSpec.getUser()).thenReturn(Optional.empty());
    ServiceSpec oldServiceSpec = DefaultServiceSpec.newBuilder().name("svc").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockOldPodSpec)).build();
    ServiceSpec newServiceSpec = DefaultServiceSpec.newBuilder().name("svc").role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).pods(Arrays.asList(mockNewPodSpec)).build();
    Assert.assertEquals(2, VALIDATOR.validate(Optional.of(oldServiceSpec), newServiceSpec).size());
}
Also used : DefaultServiceSpec(com.mesosphere.sdk.specification.DefaultServiceSpec) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) Test(org.junit.Test)

Aggregations

ServiceSpec (com.mesosphere.sdk.specification.ServiceSpec)61 DefaultServiceSpec (com.mesosphere.sdk.specification.DefaultServiceSpec)55 Test (org.junit.Test)51 MemPersister (com.mesosphere.sdk.storage.MemPersister)7 PodSpec (com.mesosphere.sdk.specification.PodSpec)6 Collectors (java.util.stream.Collectors)5 ConfigStoreException (com.mesosphere.sdk.state.ConfigStoreException)3 java.util (java.util)3 Protos (org.apache.mesos.Protos)3 Capabilities (com.mesosphere.sdk.dcos.Capabilities)2 TaskException (com.mesosphere.sdk.offer.TaskException)2 PlacementRule (com.mesosphere.sdk.offer.evaluate.placement.PlacementRule)2 TaskLabelWriter (com.mesosphere.sdk.offer.taskdata.TaskLabelWriter)2 DefaultPodSpec (com.mesosphere.sdk.specification.DefaultPodSpec)2 Persister (com.mesosphere.sdk.storage.Persister)2 PersisterException (com.mesosphere.sdk.storage.PersisterException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 Optional (java.util.Optional)2