Search in sources :

Example 11 with BootstrapStepResult

use of io.cdap.cdap.proto.bootstrap.BootstrapStepResult in project cdap by cdapio.

the class BaseStepExecutor method execute.

@Override
public BootstrapStepResult execute(String label, JsonObject argumentsObj) throws InterruptedException {
    T arguments;
    try {
        arguments = GSON.fromJson(argumentsObj, getArgumentsType());
    } catch (JsonParseException e) {
        LOG.warn("Bootstrap step {} failed because its arguments are malformed: {}", label, e.getMessage());
        return new BootstrapStepResult(label, BootstrapStepResult.Status.FAILED, String.format("Argument decoding failed. Reason: %s", e.getMessage()));
    }
    try {
        arguments.validate();
    } catch (RuntimeException e) {
        LOG.warn("Bootstrap step {} failed due to invalid arguments: {}", label, e.getMessage());
        return new BootstrapStepResult(label, BootstrapStepResult.Status.FAILED, e.getMessage());
    }
    try {
        LOG.debug("Executing bootstrap step {}", label);
        Retries.runWithInterruptibleRetries(() -> execute(arguments), getRetryStrategy(), t -> t instanceof RetryableException);
        LOG.debug("Bootstrap step {} completed successfully", label);
        return new BootstrapStepResult(label, BootstrapStepResult.Status.SUCCEEDED);
    } catch (InterruptedException e) {
        throw e;
    } catch (Exception e) {
        LOG.warn("Bootstrap step {} failed to execute", label, e);
        return new BootstrapStepResult(label, BootstrapStepResult.Status.FAILED, e.getMessage());
    }
}
Also used : RetryableException(io.cdap.cdap.api.retry.RetryableException) JsonParseException(com.google.gson.JsonParseException) BootstrapStepResult(io.cdap.cdap.proto.bootstrap.BootstrapStepResult) JsonParseException(com.google.gson.JsonParseException) RetryableException(io.cdap.cdap.api.retry.RetryableException)

Example 12 with BootstrapStepResult

use of io.cdap.cdap.proto.bootstrap.BootstrapStepResult in project cdap by cdapio.

the class SystemProfileCreatorTest method testMissingProfileName.

@Test
public void testMissingProfileName() throws Exception {
    List<ProvisionerPropertyValue> properties = new ArrayList<>();
    properties.add(new ProvisionerPropertyValue("name1", "val1", true));
    properties.add(new ProvisionerPropertyValue("name2", "val2", true));
    ProvisionerInfo provisionerInfo = new ProvisionerInfo(MockProvisioner.NAME, properties);
    SystemProfileCreator.Arguments arguments = new SystemProfileCreator.Arguments("", "label", "desc", provisionerInfo);
    BootstrapStepResult result = profileCreator.execute("label", GSON.toJsonTree(arguments).getAsJsonObject());
    Assert.assertEquals(BootstrapStepResult.Status.FAILED, result.getStatus());
}
Also used : ProvisionerPropertyValue(io.cdap.cdap.proto.provisioner.ProvisionerPropertyValue) ProvisionerInfo(io.cdap.cdap.proto.provisioner.ProvisionerInfo) ArrayList(java.util.ArrayList) BootstrapStepResult(io.cdap.cdap.proto.bootstrap.BootstrapStepResult) Test(org.junit.Test)

Example 13 with BootstrapStepResult

use of io.cdap.cdap.proto.bootstrap.BootstrapStepResult in project cdap by cdapio.

the class SystemProfileCreatorTest method testInvalidArgumentStructure.

@Test
public void testInvalidArgumentStructure() throws Exception {
    JsonObject arguments = new JsonObject();
    arguments.addProperty("name", "p1");
    arguments.addProperty("description", "desc");
    arguments.addProperty("label", "some label");
    // this is invalid, should be an object
    arguments.addProperty("provisioner", "native");
    BootstrapStepResult result = profileCreator.execute("label", arguments);
    Assert.assertEquals(BootstrapStepResult.Status.FAILED, result.getStatus());
}
Also used : JsonObject(com.google.gson.JsonObject) BootstrapStepResult(io.cdap.cdap.proto.bootstrap.BootstrapStepResult) Test(org.junit.Test)

Example 14 with BootstrapStepResult

use of io.cdap.cdap.proto.bootstrap.BootstrapStepResult in project cdap by cdapio.

the class BootstrapServiceTest method testRunCondition.

@Test
public void testRunCondition() throws Exception {
    BootstrapResult result = bootstrapService.bootstrap(step -> step.getRunCondition() == BootstrapStep.RunCondition.ONCE);
    List<BootstrapStepResult> stepResults = new ArrayList<>(3);
    stepResults.add(new BootstrapStepResult(STEP1.getLabel(), BootstrapStepResult.Status.SKIPPED));
    stepResults.add(new BootstrapStepResult(STEP2.getLabel(), BootstrapStepResult.Status.SUCCEEDED));
    stepResults.add(new BootstrapStepResult(STEP3.getLabel(), BootstrapStepResult.Status.SKIPPED));
    Assert.assertEquals(new BootstrapResult(stepResults), result);
}
Also used : ArrayList(java.util.ArrayList) BootstrapResult(io.cdap.cdap.proto.bootstrap.BootstrapResult) BootstrapStepResult(io.cdap.cdap.proto.bootstrap.BootstrapStepResult) Test(org.junit.Test)

Example 15 with BootstrapStepResult

use of io.cdap.cdap.proto.bootstrap.BootstrapStepResult in project cdap by cdapio.

the class NativeProfileCreatorTest method testAlreadyExistsDoesNotError.

@Test
public void testAlreadyExistsDoesNotError() throws Exception {
    profileService.saveProfile(ProfileId.NATIVE, Profile.NATIVE);
    BootstrapStepResult result = nativeProfileCreator.execute("label", new JsonObject());
    BootstrapStepResult expected = new BootstrapStepResult("label", BootstrapStepResult.Status.SUCCEEDED);
    Assert.assertEquals(expected, result);
    Assert.assertEquals(Profile.NATIVE, profileService.getProfile(ProfileId.NATIVE));
}
Also used : JsonObject(com.google.gson.JsonObject) BootstrapStepResult(io.cdap.cdap.proto.bootstrap.BootstrapStepResult) Test(org.junit.Test)

Aggregations

BootstrapStepResult (io.cdap.cdap.proto.bootstrap.BootstrapStepResult)34 Test (org.junit.Test)32 ArrayList (java.util.ArrayList)14 JsonObject (com.google.gson.JsonObject)12 BootstrapResult (io.cdap.cdap.proto.bootstrap.BootstrapResult)8 ProvisionerInfo (io.cdap.cdap.proto.provisioner.ProvisionerInfo)6 ProvisionerPropertyValue (io.cdap.cdap.proto.provisioner.ProvisionerPropertyValue)6 NotFoundException (io.cdap.cdap.common.NotFoundException)4 ProfileId (io.cdap.cdap.proto.id.ProfileId)4 Profile (io.cdap.cdap.proto.profile.Profile)4 HashMap (java.util.HashMap)4 JsonParseException (com.google.gson.JsonParseException)2 RetryableException (io.cdap.cdap.api.retry.RetryableException)2 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)2