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();
}
}
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());
}
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());
}
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());
}
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());
}
Aggregations