Search in sources :

Example 1 with ConfigStoreException

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

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());
}
Also used : ConfigStoreException(com.mesosphere.sdk.state.ConfigStoreException) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with ConfigStoreException

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());
}
Also used : Response(javax.ws.rs.core.Response) ConfigStoreException(com.mesosphere.sdk.state.ConfigStoreException) Test(org.junit.Test)

Example 4 with ConfigStoreException

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());
}
Also used : Response(javax.ws.rs.core.Response) ConfigStoreException(com.mesosphere.sdk.state.ConfigStoreException) Test(org.junit.Test)

Example 5 with ConfigStoreException

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());
}
Also used : Response(javax.ws.rs.core.Response) ConfigStoreException(com.mesosphere.sdk.state.ConfigStoreException) Test(org.junit.Test)

Aggregations

ConfigStoreException (com.mesosphere.sdk.state.ConfigStoreException)22 Test (org.junit.Test)11 Response (javax.ws.rs.core.Response)9 UUID (java.util.UUID)5 ServiceSpec (com.mesosphere.sdk.specification.ServiceSpec)3 RawServiceSpec (com.mesosphere.sdk.specification.yaml.RawServiceSpec)3 TaskException (com.mesosphere.sdk.offer.TaskException)2 TaskLabelReader (com.mesosphere.sdk.offer.taskdata.TaskLabelReader)2 TaskLabelWriter (com.mesosphere.sdk.offer.taskdata.TaskLabelWriter)2 DefaultServiceSpec (com.mesosphere.sdk.specification.DefaultServiceSpec)2 RawPlan (com.mesosphere.sdk.specification.yaml.RawPlan)2 ConfigStore (com.mesosphere.sdk.state.ConfigStore)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 ConfigurationUpdater (com.mesosphere.sdk.config.ConfigurationUpdater)1 DefaultConfigurationUpdater (com.mesosphere.sdk.config.DefaultConfigurationUpdater)1 ConfigValidationError (com.mesosphere.sdk.config.validate.ConfigValidationError)1 ConfigValidator (com.mesosphere.sdk.config.validate.ConfigValidator)1 AndRule (com.mesosphere.sdk.offer.evaluate.placement.AndRule)1 IsLocalRegionRule (com.mesosphere.sdk.offer.evaluate.placement.IsLocalRegionRule)1 PlacementRule (com.mesosphere.sdk.offer.evaluate.placement.PlacementRule)1