use of com.mesosphere.sdk.state.ConfigStoreException 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.state.ConfigStoreException in project dcos-commons by mesosphere.
the class ArtifactQueriesTest method testGetTemplateServiceConfigReadFailed.
@Test
public void testGetTemplateServiceConfigReadFailed() throws ConfigStoreException {
UUID uuid = UUID.randomUUID();
when(mockConfigStore.fetch(uuid)).thenThrow(new ConfigStoreException(Reason.STORAGE_ERROR, "hi"));
assertEquals(500, ArtifactQueries.getTemplate(mockConfigStore, uuid.toString(), "pod", "task", "conffile").getStatus());
}
use of com.mesosphere.sdk.state.ConfigStoreException in project dcos-commons by mesosphere.
the class ConfigQueriesTest method testGetConfigStorageFails.
@Test
public void testGetConfigStorageFails() throws ConfigStoreException {
when(mockConfigStore.fetch(ID1)).thenThrow(new ConfigStoreException(Reason.STORAGE_ERROR, "hi"));
Response response = ConfigQueries.getConfiguration(mockConfigStore, ID1.toString());
assertEquals(500, response.getStatus());
}
use of com.mesosphere.sdk.state.ConfigStoreException in project dcos-commons by mesosphere.
the class ConfigQueriesTest method testGetTargetMissingTargetId.
@Test
public void testGetTargetMissingTargetId() throws ConfigStoreException {
when(mockConfigStore.getTargetConfig()).thenThrow(new ConfigStoreException(Reason.NOT_FOUND, "hi"));
Response response = ConfigQueries.getTarget(mockConfigStore);
assertEquals(404, response.getStatus());
}
use of com.mesosphere.sdk.state.ConfigStoreException in project dcos-commons by mesosphere.
the class ConfigQueriesTest method testGetTargetMissingConfig.
@Test
public void testGetTargetMissingConfig() throws ConfigStoreException {
when(mockConfigStore.getTargetConfig()).thenReturn(ID2);
when(mockConfigStore.fetch(ID2)).thenThrow(new ConfigStoreException(Reason.NOT_FOUND, "hi"));
Response response = ConfigQueries.getTarget(mockConfigStore);
assertEquals(500, response.getStatus());
}
Aggregations