Search in sources :

Example 16 with BootstrapStepResult

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

the class NativeProfileCreatorTest method testCreation.

@Test
public void testCreation() throws Exception {
    try {
        profileService.getProfile(ProfileId.NATIVE);
        Assert.fail("Native profile should not exist.");
    } catch (NotFoundException e) {
    // expected
    }
    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 : NotFoundException(io.cdap.cdap.common.NotFoundException) JsonObject(com.google.gson.JsonObject) BootstrapStepResult(io.cdap.cdap.proto.bootstrap.BootstrapStepResult) Test(org.junit.Test)

Example 17 with BootstrapStepResult

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

the class ProgramStarterTest method invalidStructureFails.

@Test
public void invalidStructureFails() throws Exception {
    JsonObject argumentsObj = new JsonObject();
    argumentsObj.addProperty("namespace", "ns");
    argumentsObj.addProperty("application", "app");
    argumentsObj.addProperty("type", "WORKFLOW");
    argumentsObj.add("name", new JsonObject());
    BootstrapStepResult result = programStarter.execute("label", argumentsObj);
    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 18 with BootstrapStepResult

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

the class SystemPreferencesSetterTest method testExistingIsUnmodified.

@Test
public void testExistingIsUnmodified() throws Exception {
    Map<String, String> preferences = new HashMap<>();
    preferences.put("p1", "v1");
    preferencesService.setProperties(preferences);
    preferences.put("p2", "v2");
    preferences.put("p1", "v3");
    SystemPreferenceSetter.Arguments arguments = new SystemPreferenceSetter.Arguments(preferences);
    BootstrapStepResult result = systemPreferenceSetter.execute("label", GSON.toJsonTree(arguments).getAsJsonObject());
    Assert.assertEquals(BootstrapStepResult.Status.SUCCEEDED, result.getStatus());
    Map<String, String> expected = new HashMap<>();
    // p1 should not have been overridden
    expected.put("p1", "v1");
    expected.put("p2", "v2");
    Assert.assertEquals(expected, preferencesService.getProperties());
}
Also used : HashMap(java.util.HashMap) BootstrapStepResult(io.cdap.cdap.proto.bootstrap.BootstrapStepResult) Test(org.junit.Test)

Example 19 with BootstrapStepResult

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

the class BootstrapServiceTest method testRetries.

@Test
public void testRetries() throws Exception {
    EXECUTOR1.setNumRetryableFailures(3);
    BootstrapResult result = bootstrapService.bootstrap();
    List<BootstrapStepResult> expectedStepResults = new ArrayList<>();
    for (BootstrapStep step : bootstrapConfig.getSteps()) {
        expectedStepResults.add(new BootstrapStepResult(step.getLabel(), BootstrapStepResult.Status.SUCCEEDED));
    }
    BootstrapResult expected = new BootstrapResult(expectedStepResults);
    Assert.assertEquals(expected, 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 20 with BootstrapStepResult

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

the class SystemProfileCreatorTest method testExistingIsUnmodified.

@Test
public void testExistingIsUnmodified() throws Exception {
    // write a profile
    ProfileId profileId = NamespaceId.SYSTEM.profile("p1");
    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);
    Profile profile = new Profile(profileId.getProfile(), "profile label", "profile description", EntityScope.SYSTEM, provisionerInfo);
    profileService.saveProfile(profileId, profile);
    // run the bootstrap step and make sure it succeeded
    SystemProfileCreator.Arguments arguments = new SystemProfileCreator.Arguments(profile.getName(), "different label", "different desciption", profile.getProvisioner());
    BootstrapStepResult result = profileCreator.execute("label", GSON.toJsonTree(arguments).getAsJsonObject());
    BootstrapStepResult expected = new BootstrapStepResult("label", BootstrapStepResult.Status.SUCCEEDED);
    Assert.assertEquals(expected, result);
    // check that it didn't overwrite the existing profile
    Assert.assertEquals(profile, profileService.getProfile(profileId));
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) 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) Profile(io.cdap.cdap.proto.profile.Profile) 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