use of io.cdap.cdap.proto.profile.Profile in project cdap by cdapio.
the class ProvisioningServiceTest method createTaskInfo.
private TaskFields createTaskInfo(ProvisionerInfo provisionerInfo) {
ProgramRunId programRunId = NamespaceId.DEFAULT.app("app").workflow("wf").run(RunIds.generate());
Map<String, String> systemArgs = new HashMap<>();
Map<String, String> userArgs = new HashMap<>();
Profile profile = new Profile(ProfileId.NATIVE.getProfile(), "label", "desc", provisionerInfo);
SystemArguments.addProfileArgs(systemArgs, profile);
systemArgs.put(Constants.APP_CDAP_VERSION, APP_CDAP_VERSION);
ProgramOptions programOptions = new SimpleProgramOptions(programRunId.getParent(), new BasicArguments(systemArgs), new BasicArguments(userArgs));
ArtifactId artifactId = NamespaceId.DEFAULT.artifact("testArtifact", "1.0").toApiArtifactId();
ApplicationSpecification appSpec = new DefaultApplicationSpecification("name", "1.0.0", APP_CDAP_VERSION, "desc", null, artifactId, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap());
ProgramDescriptor programDescriptor = new ProgramDescriptor(programRunId.getParent(), appSpec);
return new TaskFields(programDescriptor, programOptions, programRunId);
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by cdapio.
the class ProfileStore method getProfileAssignments.
/**
* Get assignments with the profile.
*
* @param profileId the profile id
* @return the set of entities that the profile is assigned to
* @throws NotFoundException if the profile is not found
*/
public Set<EntityId> getProfileAssignments(ProfileId profileId) throws NotFoundException, IOException {
Collection<Field<?>> fields = getProfileKeys(profileId);
Profile profile = getProfileInternal(fields);
if (profile == null) {
throw new NotFoundException(profileId);
}
Set<EntityId> entities = new HashSet<>();
scanEntities(profileId, entities);
return Collections.unmodifiableSet(entities);
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by cdapio.
the class ProfileStore method removeProfileAssignment.
/**
* Remove an assignment from the profile.
*
* @param profileId the profile id
* @param entityId the entity to remove from the assignment
* @throws NotFoundException if the profile is not found
*/
public void removeProfileAssignment(ProfileId profileId, EntityId entityId) throws NotFoundException, IOException {
Collection<Field<?>> keys = getProfileKeys(profileId);
Profile profile = getProfileInternal(keys);
if (profile == null) {
throw new NotFoundException(profileId);
}
addEntityIdKey(keys, entityId);
profileEntityTable.delete(keys);
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by cdapio.
the class AppLifecycleHttpHandlerTest method testDeployAppWithDisabledProfileInSchedule.
@Test
public void testDeployAppWithDisabledProfileInSchedule() throws Exception {
// put my profile and disable it
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 an app with schedule with some disabled profile in the schedule property
AppWithSchedule.AppConfig config = new AppWithSchedule.AppConfig(true, true, true, ImmutableMap.of(SystemArguments.PROFILE_NAME, "USER:MyProfile"));
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.fromEntityId(TEST_NAMESPACE_META1.getNamespaceId()), AppWithSchedule.NAME, VERSION1);
addAppArtifact(artifactId, AppWithSchedule.class);
AppRequest<? extends Config> request = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), config, null, null, true);
// deploy should fail with a 409
ApplicationId defaultAppId = TEST_NAMESPACE_META1.getNamespaceId().app(AppWithSchedule.NAME);
Assert.assertEquals(409, deploy(defaultAppId, request).getResponseCode());
// enable
enableProfile(profileId, 200);
Assert.assertEquals(200, deploy(defaultAppId, request).getResponseCode());
// disable again so that we can delete it at namespace deletion
disableProfile(profileId, 200);
// clean up
deleteApp(defaultAppId, 200);
deleteArtifact(artifactId, 200);
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by cdapio.
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);
}
Aggregations