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