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