use of co.cask.cdap.internal.app.runtime.artifact.ArtifactDetail 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.
* @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) 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);
}
use of co.cask.cdap.internal.app.runtime.artifact.ArtifactDetail in project cdap by caskdata.
the class ExistingEntitySystemMetadataWriter method writeSystemMetadataForArtifacts.
private void writeSystemMetadataForArtifacts(NamespaceId namespace) throws IOException {
for (ArtifactDetail artifactDetail : artifactStore.getArtifacts(namespace)) {
co.cask.cdap.api.artifact.ArtifactId artifact = artifactDetail.getDescriptor().getArtifactId();
ArtifactInfo artifactInfo = new ArtifactInfo(artifact, artifactDetail.getMeta().getClasses(), artifactDetail.getMeta().getProperties());
ArtifactId artifactId = namespace.artifact(artifact.getName(), artifact.getVersion().getVersion());
SystemMetadataWriter writer = new ArtifactSystemMetadataWriter(metadataStore, artifactId, artifactInfo);
writer.write();
}
}
use of co.cask.cdap.internal.app.runtime.artifact.ArtifactDetail in project cdap by caskdata.
the class ArtifactHttpHandler method getArtifactLocation.
@GET
@Path("/namespaces/{namespace-id}/artifact-internals/artifacts/{artifact-name}/versions/{artifact-version}/location")
public void getArtifactLocation(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion) {
try {
ArtifactDetail artifactDetail = artifactRepository.getArtifact(new ArtifactId(namespaceId, artifactName, artifactVersion).toId());
responder.sendString(HttpResponseStatus.OK, artifactDetail.getDescriptor().getLocation().toURI().getPath());
} catch (Exception e) {
LOG.warn("Exception reading artifact metadata for namespace {} from the store.", namespaceId, e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading artifact metadata from the store.");
}
}
use of co.cask.cdap.internal.app.runtime.artifact.ArtifactDetail in project cdap by caskdata.
the class ArtifactHttpHandler method getProperty.
@GET
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/properties/{property}")
public void getProperty(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion, @PathParam("property") String key, @QueryParam("scope") @DefaultValue("user") String scope) throws Exception {
NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope);
Id.Artifact artifactId = validateAndGetArtifactId(namespace, artifactName, artifactVersion);
try {
ArtifactDetail detail = artifactRepository.getArtifact(artifactId);
responder.sendString(HttpResponseStatus.OK, detail.getMeta().getProperties().get(key));
} catch (IOException e) {
LOG.error("Exception reading property for artifact {}.", artifactId, e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading properties for artifact.");
}
}
use of co.cask.cdap.internal.app.runtime.artifact.ArtifactDetail in project cdap by caskdata.
the class ApplicationLifecycleService method deployAppAndArtifact.
/**
* Deploy an application by first adding the application jar to the artifact repository, then creating an application
* using that newly added artifact.
*
* @param namespace the namespace to deploy the application and artifact in
* @param appName the name of the app. If null, the name will be set based on the application spec
* @param artifactId the id of the artifact to add and create the application from
* @param jarFile the application jar to add as an artifact and create the application from
* @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.
* @return information about the deployed application
* @throws InvalidArtifactException the the artifact is invalid. For example, if it does not contain any app classes
* @throws ArtifactAlreadyExistsException if the specified artifact already exists
* @throws IOException if there was an IO error writing the artifact
*/
public ApplicationWithPrograms deployAppAndArtifact(NamespaceId namespace, @Nullable String appName, Id.Artifact artifactId, File jarFile, @Nullable String configStr, @Nullable KerberosPrincipalId ownerPrincipal, ProgramTerminator programTerminator, boolean updateSchedules) throws Exception {
ArtifactDetail artifactDetail = artifactRepository.addArtifact(artifactId, jarFile);
try {
return deployApp(namespace, appName, null, configStr, programTerminator, artifactDetail, ownerPrincipal, updateSchedules);
} catch (Exception e) {
// to the state we were in before this call.
try {
artifactRepository.deleteArtifact(artifactId);
} catch (IOException e2) {
// if the delete fails, nothing we can do, just log it and continue on
LOG.warn("Failed to delete artifact {} after deployment of artifact and application failed.", artifactId, e2);
e.addSuppressed(e2);
}
throw e;
}
}
Aggregations