Search in sources :

Example 6 with Profile

use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.

the class ProfileHttpHandlerTest method testNullProvisionerProperty.

@Test
public void testNullProvisionerProperty() throws Exception {
    // provide a profile with null provsioner property, it should still succeed
    List<ProvisionerPropertyValue> listWithNull = new ArrayList<>();
    listWithNull.add(null);
    Profile profile = new Profile("ProfileWithNull", "label", "should succeed", new ProvisionerInfo(MockProvisioner.NAME, listWithNull));
    putProfile(NamespaceId.DEFAULT.profile(profile.getName()), profile, HttpURLConnection.HTTP_OK);
    // Get the profile, it should not contain the null value, the property should be an empty list
    Profile actual = getProfile(NamespaceId.DEFAULT.profile(profile.getName()), HttpURLConnection.HTTP_OK).get();
    Assert.assertNotNull(actual);
    Assert.assertEquals(Collections.EMPTY_SET, actual.getProvisioner().getProperties());
    disableProfile(NamespaceId.DEFAULT.profile(profile.getName()), HttpURLConnection.HTTP_OK);
    deleteProfile(NamespaceId.DEFAULT.profile(profile.getName()), HttpURLConnection.HTTP_OK);
    // provide a profile with mixed properties with null, it should still succeed
    List<ProvisionerPropertyValue> listMixed = new ArrayList<>(PROPERTY_SUMMARIES);
    listMixed.addAll(listWithNull);
    profile = new Profile("ProfileMixed", "label", "should succeed", new ProvisionerInfo(MockProvisioner.NAME, listMixed));
    putProfile(NamespaceId.DEFAULT.profile(profile.getName()), profile, HttpURLConnection.HTTP_OK);
    // Get the profile, it should not contain the null value, the property should be all non-null properties in the list
    actual = getProfile(NamespaceId.DEFAULT.profile(profile.getName()), HttpURLConnection.HTTP_OK).get();
    Assert.assertNotNull(actual);
    Assert.assertEquals(PROPERTY_SUMMARIES, actual.getProvisioner().getProperties());
    disableProfile(NamespaceId.DEFAULT.profile(profile.getName()), HttpURLConnection.HTTP_OK);
    deleteProfile(NamespaceId.DEFAULT.profile(profile.getName()), HttpURLConnection.HTTP_OK);
}
Also used : ProvisionerPropertyValue(io.cdap.cdap.proto.provisioner.ProvisionerPropertyValue) ProvisionerInfo(io.cdap.cdap.proto.provisioner.ProvisionerInfo) ArrayList(java.util.ArrayList) Profile(io.cdap.cdap.proto.profile.Profile) Test(org.junit.Test)

Example 7 with Profile

use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.

the class ProfileHttpHandlerTest method testPutPermissionChecks.

@Test
public void testPutPermissionChecks() throws Exception {
    Profile profile = new Profile(PERMISSIONS_TEST_PROFILE, "label", "default permissions testing profile", new ProvisionerInfo(MockProvisioner.NAME, Collections.emptyList()));
    ProfileId profileId = NamespaceId.DEFAULT.profile(PERMISSIONS_TEST_PROFILE);
    // Verify the UPDATE user does not have permissions to create a profile
    doAs(UPDATE_PROFILE_USER.getName(), () -> {
        putProfile(profileId, profile, HttpURLConnection.HTTP_FORBIDDEN);
        putSystemProfile(profile.getName(), profile, HttpURLConnection.HTTP_FORBIDDEN);
    });
    // Verify that the CREATE user can create both profiles
    doAs(CREATE_PROFILE_USER.getName(), () -> {
        putProfile(profileId, profile, HttpURLConnection.HTTP_OK);
        putSystemProfile(profile.getName(), profile, HttpURLConnection.HTTP_OK);
    });
    // Verify that the UPDATE user can modify the profiles after they have been created
    doAs(UPDATE_PROFILE_USER.getName(), () -> {
        putProfile(profileId, profile, HttpURLConnection.HTTP_OK);
        putSystemProfile(profile.getName(), profile, HttpURLConnection.HTTP_OK);
        // Disable the profiles in preparation for deletion.
        disableProfile(profileId, HttpURLConnection.HTTP_OK);
        disableSystemProfile(profile.getName(), HttpURLConnection.HTTP_OK);
        // Verify deletion failure
        deleteProfile(profileId, HttpURLConnection.HTTP_FORBIDDEN);
        deleteSystemProfile(profile.getName(), HttpURLConnection.HTTP_FORBIDDEN);
    });
    // Verify that the CREATE user cannot update profiles after they have been created
    doAs(CREATE_PROFILE_USER.getName(), () -> {
        putProfile(profileId, profile, HttpURLConnection.HTTP_FORBIDDEN);
        putSystemProfile(profile.getName(), profile, HttpURLConnection.HTTP_FORBIDDEN);
    });
    // Delete profiles
    doAs(DELETE_PROFILE_USER.getName(), () -> {
        deleteProfile(profileId, HttpURLConnection.HTTP_OK);
        deleteSystemProfile(profile.getName(), HttpURLConnection.HTTP_OK);
    });
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ProvisionerInfo(io.cdap.cdap.proto.provisioner.ProvisionerInfo) Profile(io.cdap.cdap.proto.profile.Profile) Test(org.junit.Test)

Example 8 with Profile

use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.

the class SystemProfileCreatorTest method testCreation.

@Test
public void testCreation() throws Exception {
    ProfileId profileId = NamespaceId.SYSTEM.profile("p1");
    try {
        profileService.getProfile(profileId);
        Assert.fail("profile should not exist.");
    } catch (NotFoundException e) {
    // expected
    }
    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);
    SystemProfileCreator.Arguments arguments = new SystemProfileCreator.Arguments(profile.getName(), profile.getLabel(), profile.getDescription(), profile.getProvisioner());
    BootstrapStepResult result = profileCreator.execute("label", GSON.toJsonTree(arguments).getAsJsonObject());
    BootstrapStepResult expected = new BootstrapStepResult("label", BootstrapStepResult.Status.SUCCEEDED);
    Assert.assertEquals(expected, result);
    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) NotFoundException(io.cdap.cdap.common.NotFoundException) BootstrapStepResult(io.cdap.cdap.proto.bootstrap.BootstrapStepResult) Profile(io.cdap.cdap.proto.profile.Profile) Test(org.junit.Test)

Example 9 with Profile

use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.

the class ProgramLifecycleHttpHandlerTest method testStartProgramWithDisabledProfile.

@Test
public void testStartProgramWithDisabledProfile() throws Exception {
    // put my profile and disable it, using this profile to start program should fail
    ProfileId profileId = new NamespaceId(TEST_NAMESPACE1).profile("MyProfile");
    Profile profile = new Profile("MyProfile", Profile.NATIVE.getLabel(), Profile.NATIVE.getDescription(), Profile.NATIVE.getScope(), Profile.NATIVE.getProvisioner());
    putProfile(profileId, profile, 200);
    disableProfile(profileId, 200);
    // deploy, check the status
    deploy(AppWithWorkflow.class, 200, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1);
    ProgramId programId = new NamespaceId(TEST_NAMESPACE1).app(AppWithWorkflow.NAME).workflow(AppWithWorkflow.SampleWorkflow.NAME);
    // workflow is stopped initially
    Assert.assertEquals(STOPPED, getProgramStatus(programId));
    // start workflow should give a 409 since we have a runtime argument associated with a disabled profile
    startProgram(programId, Collections.singletonMap(SystemArguments.PROFILE_NAME, profileId.getScopedName()), 409);
    Assert.assertEquals(STOPPED, getProgramStatus(programId));
    // use native profile to start workflow should work since it is always enabled.
    // the workflow should start but fail because we are not passing in required runtime args.
    int runs = getProgramRuns(programId, ProgramRunStatus.FAILED).size();
    startProgram(programId, Collections.singletonMap(SystemArguments.PROFILE_NAME, ProfileId.NATIVE.getScopedName()), 200);
    // wait for the workflow to stop and check the status
    Tasks.waitFor(runs + 1, () -> getProgramRuns(programId, ProgramRunStatus.FAILED).size(), 60, TimeUnit.SECONDS);
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ProgramId(io.cdap.cdap.proto.id.ProgramId) Profile(io.cdap.cdap.proto.profile.Profile) ConcurrencyConstraint(io.cdap.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint) ServiceHttpEndpoint(io.cdap.cdap.api.service.http.ServiceHttpEndpoint) ProtoConstraint(io.cdap.cdap.proto.ProtoConstraint) Test(org.junit.Test)

Example 10 with Profile

use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.

the class ProfileStore method saveProfile.

/**
 * Save the profile to the profile store. By default the profile status will be enabled.
 *
 * @param profileId the id of the profile to save
 * @param profile the information of the profile
 */
public void saveProfile(ProfileId profileId, Profile profile) throws IOException {
    Collection<Field<?>> fields = getProfileKeys(profileId);
    Profile oldProfile = getProfileInternal(fields);
    Profile newProfile = new Profile(profile.getName(), profile.getLabel(), profile.getDescription(), profile.getScope(), oldProfile == null ? ProfileStatus.ENABLED : oldProfile.getStatus(), profile.getProvisioner(), oldProfile == null ? profile.getCreatedTsSeconds() : oldProfile.getCreatedTsSeconds());
    fields.add(Fields.stringField(StoreDefinition.ProfileStore.PROFILE_DATA_FIELD, GSON.toJson(newProfile)));
    profileTable.upsert(fields);
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) Profile(io.cdap.cdap.proto.profile.Profile)

Aggregations

Profile (io.cdap.cdap.proto.profile.Profile)86 ProfileId (io.cdap.cdap.proto.id.ProfileId)50 Test (org.junit.Test)48 ProvisionerInfo (io.cdap.cdap.proto.provisioner.ProvisionerInfo)32 NotFoundException (io.cdap.cdap.common.NotFoundException)16 ProfileConflictException (io.cdap.cdap.common.ProfileConflictException)14 ProgramId (io.cdap.cdap.proto.id.ProgramId)14 Field (io.cdap.cdap.spi.data.table.field.Field)14 ArrayList (java.util.ArrayList)14 ProvisionerPropertyValue (io.cdap.cdap.proto.provisioner.ProvisionerPropertyValue)10 TableNotFoundException (io.cdap.cdap.spi.data.TableNotFoundException)10 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)8 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)8 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)6 Store (io.cdap.cdap.app.store.Store)6 DefaultStore (io.cdap.cdap.internal.app.store.DefaultStore)6 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)6 Injector (com.google.inject.Injector)4