Search in sources :

Example 26 with ProfileId

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);
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 27 with ProfileId

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));
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) Test(org.junit.Test)

Example 28 with ProfileId

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);
    }
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ProgramSchedule(io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) NotFoundException(io.cdap.cdap.common.NotFoundException) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) ScheduleId(io.cdap.cdap.proto.id.ScheduleId) ApplicationMeta(io.cdap.cdap.internal.app.store.ApplicationMeta)

Example 29 with ProfileId

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);
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ScheduleId(io.cdap.cdap.proto.id.ScheduleId)

Example 30 with ProfileId

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);
    }
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ProgramSchedule(io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule)

Aggregations

ProfileId (io.cdap.cdap.proto.id.ProfileId)112 Test (org.junit.Test)68 Profile (io.cdap.cdap.proto.profile.Profile)50 ProgramId (io.cdap.cdap.proto.id.ProgramId)26 ProvisionerInfo (io.cdap.cdap.proto.provisioner.ProvisionerInfo)26 Path (javax.ws.rs.Path)22 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)16 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)14 HashMap (java.util.HashMap)14 ProfileConflictException (io.cdap.cdap.common.ProfileConflictException)12 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)12 MetricStore (io.cdap.cdap.api.metrics.MetricStore)10 NotFoundException (io.cdap.cdap.common.NotFoundException)10 ProgramSchedule (io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule)10 ProfileService (io.cdap.cdap.internal.profile.ProfileService)10 ArrayList (java.util.ArrayList)10 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)8 ScheduleId (io.cdap.cdap.proto.id.ScheduleId)8 POST (javax.ws.rs.POST)8 Store (io.cdap.cdap.app.store.Store)6