use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class LogHttpHandlerTest method testLogsRunId.
private void testLogsRunId(String appId, String entityType, String entityId, String namespace, String format, List<String> suppress) throws Exception {
ProgramId programId = new NamespaceId(namespace).app(appId).program(ProgramType.valueOfCategoryName(entityType), entityId);
RunRecord runRecord = mockLogReader.getRunRecord(programId);
int expectedEvents = 20;
if (runRecord.getStatus() == ProgramRunStatus.RUNNING || runRecord.getStatus() == ProgramRunStatus.SUSPENDED) {
expectedEvents = 30;
}
long startTime = MockLogReader.getMockTimeSecs(0);
long stopTime = MockLogReader.getMockTimeSecs(100);
String nextNoFromUrl;
if (suppress.isEmpty()) {
nextNoFromUrl = String.format("apps/%s/%s/%s/runs/%s/logs?format=%s&start=%s&stop=%s", appId, entityType, entityId, runRecord.getPid(), format, startTime, stopTime);
} else {
String fieldsToSuppress = getSuppressStr(suppress);
nextNoFromUrl = String.format("apps/%s/%s/%s/runs/%s/logs?format=%s&start=%s&stop=%s&suppress=%s", appId, entityType, entityId, runRecord.getPid(), format, startTime, stopTime, fieldsToSuppress);
}
HttpResponse response = doGet(getVersionedAPIPath(nextNoFromUrl, namespace));
verifyLogs(response, entityId, format, true, true, true, expectedEvents, 20, suppress);
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class LogHttpHandlerTest method testNextRunId.
private void testNextRunId(String appId, String entityType, String entityId, String namespace, String format, List<String> suppress) throws Exception {
ProgramId programId = new NamespaceId(namespace).app(appId).program(ProgramType.valueOfCategoryName(entityType), entityId);
RunRecord runRecord = mockLogReader.getRunRecord(programId);
int expectedEvents = 20;
if (runRecord.getStatus() == ProgramRunStatus.RUNNING || runRecord.getStatus() == ProgramRunStatus.SUSPENDED) {
expectedEvents = 30;
}
String nextNoFromUrl;
if (suppress.isEmpty()) {
nextNoFromUrl = String.format("apps/%s/%s/%s/runs/%s/logs/next?format=%s&max=100", appId, entityType, entityId, runRecord.getPid(), format);
} else {
String fieldsToSuppress = getSuppressStr(suppress);
nextNoFromUrl = String.format("apps/%s/%s/%s/runs/%s/logs/next?format=%s&max=100&suppress=%s", appId, entityType, entityId, runRecord.getPid(), format, fieldsToSuppress);
}
HttpResponse response = doGet(getVersionedAPIPath(nextNoFromUrl, namespace));
verifyLogs(response, entityId, format, true, false, true, expectedEvents, 20, suppress);
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class ApplicationLifecycleService method deployApp.
/**
* Deploy an application using the specified artifact and configuration. When an app is deployed, the Application
* class is instantiated and configure() is called in order to generate an {@link ApplicationSpecification}.
* Programs, datasets, and streams are created based on the specification before the spec is persisted in the
* {@link Store}. This method can create a new application as well as update an existing one.
*
* @param namespace the namespace to deploy the app to
* @param appName the name of the app. If null, the name will be set based on the application spec
* @param summary the artifact summary of the app
* @param configStr the configuration to send to the application when generating the application specification
* @param programTerminator a program terminator that will stop programs that are removed when updating an app.
* For example, if an update removes a flow, the terminator defines how to stop that flow.
* @param ownerPrincipal the kerberos principal of the application owner
* @param updateSchedules specifies if schedules of the workflow have to be updated,
* if null value specified by the property "app.deploy.update.schedules" will be used.
* @param isPreview whether the app deployment is for preview
* @param userProps the user properties for the app deployment, this is basically used for preview deployment
* @return information about the deployed application
* @throws InvalidArtifactException if the artifact does not contain any application classes
* @throws IOException if there was an IO error reading artifact detail from the meta store
* @throws ArtifactNotFoundException if the specified artifact does not exist
* @throws Exception if there was an exception during the deployment pipeline. This exception will often wrap
* the actual exception
*/
public ApplicationWithPrograms deployApp(NamespaceId namespace, @Nullable String appName, @Nullable String appVersion, ArtifactSummary summary, @Nullable String configStr, ProgramTerminator programTerminator, @Nullable KerberosPrincipalId ownerPrincipal, @Nullable Boolean updateSchedules, boolean isPreview, Map<String, String> userProps) throws Exception {
NamespaceId artifactNamespace = ArtifactScope.SYSTEM.equals(summary.getScope()) ? NamespaceId.SYSTEM : namespace;
ArtifactRange range = new ArtifactRange(artifactNamespace.getNamespace(), summary.getName(), ArtifactVersionRange.parse(summary.getVersion()));
// this method will not throw ArtifactNotFoundException, if no artifacts in the range, we are expecting an empty
// collection returned.
List<ArtifactDetail> artifactDetail = artifactRepository.getArtifactDetails(range, 1, ArtifactSortOrder.DESC);
if (artifactDetail.isEmpty()) {
throw new ArtifactNotFoundException(range.getNamespace(), range.getName());
}
return deployApp(namespace, appName, appVersion, configStr, programTerminator, artifactDetail.iterator().next(), ownerPrincipal, updateSchedules == null ? appUpdateSchedules : updateSchedules, isPreview, userProps);
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class ApplicationLifecycleService method scanApplications.
/**
* Scans all applications in the specified namespace, filtered to only include application details
* which satisfy the filters
*
* @param request application scan request. Must name namespace filled
* @param consumer a {@link Consumer} to consume each ApplicationDetail being scanned
* @return if limit was reached (true) or all items were scanned before reaching the limit (false)
* @throws IllegalArgumentException if scan request does not have namespace specified
*/
public boolean scanApplications(ScanApplicationsRequest request, Consumer<ApplicationDetail> consumer) {
NamespaceId namespace = request.getNamespaceId();
if (namespace == null) {
throw new IllegalStateException("Application scan request without namespace");
}
accessEnforcer.enforceOnParent(EntityType.DATASET, namespace, authenticationContext.getPrincipal(), StandardPermission.LIST);
try (BatchingConsumer<Entry<ApplicationId, ApplicationSpecification>> batchingConsumer = new BatchingConsumer<>(list -> processApplications(list, consumer), batchSize)) {
return store.scanApplications(request, batchSize, (appId, appSpec) -> {
batchingConsumer.accept(new SimpleEntry<>(appId, appSpec));
});
}
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class ApplicationLifecycleService method createAppDetailsArchive.
/**
* Creates a ZIP archive that contains the {@link ApplicationDetail} for all applications. The archive created will
* contain a directory entry for each of the namespace. Inside each namespace directory, it contains the
* application detail json, the application name as the file name, with {@code ".json"} as the file extension.
* <p/>
* This method requires instance admin permission.
*
* @param zipOut the {@link ZipOutputStream} for writing out the application details
*/
public void createAppDetailsArchive(ZipOutputStream zipOut) throws Exception {
accessEnforcer.enforce(new InstanceId(cConf.get(Constants.INSTANCE_NAME)), authenticationContext.getPrincipal(), StandardPermission.GET);
Set<NamespaceId> namespaces = new HashSet<>();
JsonWriter jsonWriter = new JsonWriter(new OutputStreamWriter(zipOut, StandardCharsets.UTF_8));
store.scanApplications(batchSize, (appId, appSpec) -> {
// Skip the SYSTEM namespace apps
if (NamespaceId.SYSTEM.equals(appId.getParent())) {
return;
}
try {
ApplicationDetail applicationDetail = enforceApplicationDetailAccess(appId, ApplicationDetail.fromSpec(appSpec, null));
// Add a directory for the namespace
if (namespaces.add(appId.getParent())) {
ZipEntry entry = new ZipEntry(appId.getNamespace() + "/");
zipOut.putNextEntry(entry);
zipOut.closeEntry();
}
ZipEntry entry = new ZipEntry(appId.getNamespace() + "/" + appId.getApplication() + ".json");
zipOut.putNextEntry(entry);
GSON.toJson(applicationDetail, ApplicationDetail.class, jsonWriter);
jsonWriter.flush();
zipOut.closeEntry();
} catch (IOException | AccessException e) {
throw new RuntimeException("Failed to add zip entry for application " + appId, e);
}
});
}
Aggregations