use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class ProgramExistenceVerifier method ensureExists.
@Override
public void ensureExists(ProgramId programId) throws ApplicationNotFoundException, ProgramNotFoundException {
ApplicationId appId = programId.getParent();
ApplicationSpecification appSpec = store.getApplication(appId);
if (appSpec == null) {
throw new ApplicationNotFoundException(appId);
}
ProgramType programType = programId.getType();
Set<String> programNames = null;
if (programType == ProgramType.FLOW && appSpec.getFlows() != null) {
programNames = appSpec.getFlows().keySet();
} else if (programType == ProgramType.MAPREDUCE && appSpec.getMapReduce() != null) {
programNames = appSpec.getMapReduce().keySet();
} else if (programType == ProgramType.WORKFLOW && appSpec.getWorkflows() != null) {
programNames = appSpec.getWorkflows().keySet();
} else if (programType == ProgramType.SERVICE && appSpec.getServices() != null) {
programNames = appSpec.getServices().keySet();
} else if (programType == ProgramType.SPARK && appSpec.getSpark() != null) {
programNames = appSpec.getSpark().keySet();
} else if (programType == ProgramType.WORKER && appSpec.getWorkers() != null) {
programNames = appSpec.getWorkers().keySet();
}
if (programNames != null) {
if (programNames.contains(programId.getProgram())) {
// is valid.
return;
}
}
throw new ProgramNotFoundException(programId);
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class LocalArtifactLoaderStage method process.
/**
* Instantiates the Application class and calls configure() on it to generate the {@link ApplicationSpecification}.
*
* @param deploymentInfo information needed to deploy the application, such as the artifact to create it from
* and the application config to use.
*/
@Override
public void process(AppDeploymentInfo deploymentInfo) throws Exception {
ArtifactId artifactId = deploymentInfo.getArtifactId();
Location artifactLocation = deploymentInfo.getArtifactLocation();
String appClassName = deploymentInfo.getAppClassName();
String appVersion = deploymentInfo.getApplicationVersion();
String configString = deploymentInfo.getConfigString();
EntityImpersonator classLoaderImpersonator = new EntityImpersonator(artifactId, impersonator);
ClassLoader artifactClassLoader = artifactRepository.createArtifactClassLoader(artifactLocation, classLoaderImpersonator);
getContext().setProperty(LocalApplicationManager.ARTIFACT_CLASSLOADER_KEY, artifactClassLoader);
InMemoryConfigurator inMemoryConfigurator = new InMemoryConfigurator(cConf, Id.Namespace.fromEntityId(deploymentInfo.getNamespaceId()), Id.Artifact.fromEntityId(artifactId), appClassName, artifactRepository, artifactClassLoader, deploymentInfo.getApplicationName(), deploymentInfo.getApplicationVersion(), configString);
ListenableFuture<ConfigResponse> result = inMemoryConfigurator.config();
ConfigResponse response = result.get(120, TimeUnit.SECONDS);
if (response.getExitCode() != 0) {
throw new IllegalArgumentException("Failed to configure application: " + deploymentInfo);
}
ApplicationSpecification specification = adapter.fromJson(response.get());
ApplicationId applicationId;
if (appVersion == null) {
applicationId = deploymentInfo.getNamespaceId().app(specification.getName());
} else {
applicationId = deploymentInfo.getNamespaceId().app(specification.getName(), appVersion);
}
authorizationEnforcer.enforce(applicationId, authenticationContext.getPrincipal(), Action.ADMIN);
emit(new ApplicationDeployable(deploymentInfo.getArtifactId(), deploymentInfo.getArtifactLocation(), applicationId, specification, store.getApplication(applicationId), ApplicationDeployScope.USER, deploymentInfo.getOwnerPrincipal(), deploymentInfo.canUpdateSchedules()));
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class ApplicationVerificationStage method process.
/**
* Receives an input containing application specification and location
* and verifies both.
*
* @param input An instance of {@link ApplicationDeployable}
*/
@Override
public void process(ApplicationDeployable input) throws Exception {
Preconditions.checkNotNull(input);
ApplicationSpecification specification = input.getSpecification();
ApplicationId appId = input.getApplicationId();
// verify that the owner principal is valid if one was given
if (input.getOwnerPrincipal() != null) {
SecurityUtil.validateKerberosPrincipal(input.getOwnerPrincipal());
}
Collection<ApplicationId> allAppVersionsAppIds = store.getAllAppVersionsAppIds(appId);
// verify that the owner is same
if (!allAppVersionsAppIds.isEmpty()) {
verifyOwner(appId, input.getOwnerPrincipal());
}
verifySpec(appId, specification);
// We are verifying owner of dataset/stream at this stage itself even though the creation will fail in later
// stage if the owner is different because we don't want to end up in scenario where we created few dataset/streams
// and the failed because some dataset/stream already exists and have different owner
verifyData(appId, specification, input.getOwnerPrincipal());
verifyPrograms(appId, specification);
// Emit the input to next stage.
emit(input);
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class ApplicationVerificationTest method testGoodApplication.
/**
* Good test
*/
@Test
public void testGoodApplication() throws Exception {
ApplicationSpecification appSpec = Specifications.from(new WebCrawlApp());
ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
ApplicationVerification app = new ApplicationVerification();
VerifyResult result = app.verify(new ApplicationId("test", newSpec.getName()), newSpec);
Assert.assertTrue(result.getMessage(), result.getStatus() == VerifyResult.Status.SUCCESS);
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class DefaultStoreTest method testUpdateChangedApplication.
@Test
public void testUpdateChangedApplication() throws Exception {
ApplicationId id = new ApplicationId("account1", "application1");
store.addApplication(id, Specifications.from(new FooApp()));
// update
store.addApplication(id, Specifications.from(new ChangedFooApp()));
ApplicationSpecification stored = store.getApplication(id);
assertChangedFooAppSpecAndInMetadataStore(stored);
}
Aggregations