use of io.cdap.cdap.proto.id.ProfileId in project cdap by caskdata.
the class ProfileHttpHandler method writeProfile.
/**
* Write a profile in a namespace.
*/
@PUT
@Path("/namespaces/{namespace-id}/profiles/{profile-name}")
public void writeProfile(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("profile-name") String profileName) throws Exception {
ProfileId profileId = getValidatedProfile(namespaceId, profileName);
checkPutProfilePermissions(profileId);
writeProfile(profileId, request);
responder.sendStatus(HttpResponseStatus.OK);
}
use of io.cdap.cdap.proto.id.ProfileId in project cdap by caskdata.
the class SystemArgumentsTest method testGetProgramProfile.
@Test
public void testGetProgramProfile() {
ProfileId profileId = NamespaceId.DEFAULT.profile("p");
Map<String, String> args = Collections.singletonMap(SystemArguments.PROFILE_NAME, profileId.getScopedName());
ApplicationId appId = NamespaceId.DEFAULT.app("a");
ProgramId mrId = appId.mr("mr");
ProgramId serviceId = appId.service("serv");
ProgramId sparkId = appId.spark("spark");
ProgramId workerId = appId.worker("worker");
ProgramId workflowID = appId.workflow("wf");
Assert.assertEquals(profileId, SystemArguments.getProfileIdForProgram(mrId, args));
Assert.assertEquals(ProfileId.NATIVE, SystemArguments.getProfileIdForProgram(serviceId, args));
Assert.assertEquals(profileId, SystemArguments.getProfileIdForProgram(sparkId, args));
Assert.assertEquals(profileId, SystemArguments.getProfileIdForProgram(workerId, args));
Assert.assertEquals(profileId, SystemArguments.getProfileIdForProgram(workflowID, args));
}
use of io.cdap.cdap.proto.id.ProfileId in project cdap by caskdata.
the class ProfileMetadataMessageProcessor method collectProfileMetadata.
private void collectProfileMetadata(EntityId entityId, MetadataMessage message, List<MetadataMutation> updates) throws IOException {
switch(entityId.getEntityType()) {
case INSTANCE:
for (NamespaceMeta meta : namespaceTable.list()) {
collectProfileMetadata(meta.getNamespaceId(), message, updates);
}
break;
case NAMESPACE:
NamespaceId namespaceId = (NamespaceId) entityId;
// make sure namespace exists before updating
if (namespaceTable.get(namespaceId) == null) {
LOG.debug("Namespace {} is not found, so the profile metadata of programs or schedules in it will not get " + "updated. Ignoring the message {}", namespaceId, message);
return;
}
ProfileId namespaceProfile = getResolvedProfileId(namespaceId);
List<ApplicationMeta> applicationMetas = appMetadataStore.getAllApplications(namespaceId.getNamespace());
for (ApplicationMeta meta : applicationMetas) {
collectAppProfileMetadata(namespaceId.app(meta.getId()), meta.getSpec(), namespaceProfile, updates);
}
break;
case APPLICATION:
ApplicationId appId = (ApplicationId) entityId;
// make sure app exists before updating
ApplicationMeta meta = appMetadataStore.getApplication(appId);
if (meta == null) {
LOG.debug("Application {} is not found, so the profile metadata of its programs/schedules will not get " + "updated. Ignoring the message {}", appId, message);
return;
}
collectAppProfileMetadata(appId, meta.getSpec(), null, updates);
collectPluginMetadata(appId, meta.getSpec(), updates);
break;
case PROGRAM:
ProgramId programId = (ProgramId) entityId;
// make sure the app of the program exists before updating
meta = appMetadataStore.getApplication(programId.getParent());
if (meta == null) {
LOG.debug("Application {} is not found, so the profile metadata of program {} will not get updated. " + "Ignoring the message {}", programId.getParent(), programId, message);
return;
}
if (PROFILE_ALLOWED_PROGRAM_TYPES.contains(programId.getType())) {
collectProgramProfileMetadata(programId, null, updates);
}
break;
case SCHEDULE:
ScheduleId scheduleId = (ScheduleId) entityId;
// make sure the schedule exists before updating
try {
ProgramSchedule schedule = scheduleDataset.getSchedule(scheduleId);
collectScheduleProfileMetadata(schedule, getResolvedProfileId(schedule.getProgramId()), updates);
} catch (NotFoundException e) {
LOG.debug("Schedule {} is not found, so its profile metadata will not get updated. " + "Ignoring the message {}", scheduleId, message);
return;
}
break;
default:
// this should not happen
LOG.warn("Type of the entity id {} cannot be used to update profile metadata. " + "Ignoring the message {}", entityId, message);
}
}
use of io.cdap.cdap.proto.id.ProfileId in project cdap by caskdata.
the class ProfileMetadataMessageProcessor method collectScheduleProfileMetadata.
private void collectScheduleProfileMetadata(ProgramSchedule schedule, ProfileId programProfile, List<MetadataMutation> updates) {
ScheduleId scheduleId = schedule.getScheduleId();
// if we are able to get profile from preferences or schedule properties, use it
// otherwise default profile will be used
Optional<ProfileId> scheduleProfileId = SystemArguments.getProfileIdFromArgs(scheduleId.getNamespaceId(), schedule.getProperties());
programProfile = scheduleProfileId.orElse(programProfile);
addProfileMetadataUpdate(scheduleId, programProfile, updates);
}
use of io.cdap.cdap.proto.id.ProfileId in project cdap by caskdata.
the class ProfileMetadataMessageProcessor method collectProgramProfileMetadata.
private void collectProgramProfileMetadata(ProgramId programId, @Nullable ProfileId appProfile, List<MetadataMutation> updates) throws IOException {
ProfileId programProfile = appProfile == null ? getResolvedProfileId(programId) : getProfileId(programId).orElse(appProfile);
addProfileMetadataUpdate(programId, programProfile, updates);
for (ProgramSchedule schedule : scheduleDataset.listSchedules(programId)) {
collectScheduleProfileMetadata(schedule, programProfile, updates);
}
}
Aggregations