Search in sources :

Example 1 with ArtifactManager

use of io.cdap.cdap.api.artifact.ArtifactManager in project cdap by caskdata.

the class ArtifactLocalizer method preloadArtifacts.

public void preloadArtifacts(Set<String> artifactNames) throws IOException, ArtifactNotFoundException {
    ArtifactManager artifactManager = artifactManagerFactory.create(NamespaceId.SYSTEM, RetryStrategies.fromConfiguration(cConf, Constants.Service.TASK_WORKER + "."));
    for (ArtifactInfo info : artifactManager.listArtifacts()) {
        if (artifactNames.contains(info.getName()) && info.getParents().isEmpty()) {
            String className = info.getClasses().getApps().stream().findFirst().map(ApplicationClass::getClassName).orElse(null);
            LOG.info("Preloading artifact {}:{}-{}", info.getScope(), info.getName(), info.getVersion());
            ArtifactId artifactId = NamespaceId.SYSTEM.artifact(info.getName(), info.getVersion());
            try {
                fetchArtifact(artifactId);
            } catch (Exception e) {
                LOG.debug("Failed to preload artifact {}", artifactId);
            }
        }
    }
}
Also used : ArtifactManager(io.cdap.cdap.api.artifact.ArtifactManager) ArtifactInfo(io.cdap.cdap.api.artifact.ArtifactInfo) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) IOException(java.io.IOException) ArtifactNotFoundException(io.cdap.cdap.common.ArtifactNotFoundException)

Example 2 with ArtifactManager

use of io.cdap.cdap.api.artifact.ArtifactManager in project cdap by caskdata.

the class ServiceProgramRunner method run.

@Override
public ProgramController run(Program program, ProgramOptions options) {
    int instanceId = Integer.parseInt(options.getArguments().getOption(ProgramOptionConstants.INSTANCE_ID, "-1"));
    Preconditions.checkArgument(instanceId >= 0, "Missing instance Id");
    int instanceCount = Integer.parseInt(options.getArguments().getOption(ProgramOptionConstants.INSTANCES, "0"));
    Preconditions.checkArgument(instanceCount > 0, "Invalid or missing instance count");
    RunId runId = ProgramRunners.getRunId(options);
    ApplicationSpecification appSpec = program.getApplicationSpecification();
    Preconditions.checkNotNull(appSpec, "Missing application specification.");
    ProgramType programType = program.getType();
    Preconditions.checkNotNull(programType, "Missing processor type.");
    Preconditions.checkArgument(programType == ProgramType.SERVICE, "Only Service process type is supported.");
    ServiceSpecification spec = appSpec.getServices().get(program.getName());
    String host = options.getArguments().getOption(ProgramOptionConstants.HOST);
    Preconditions.checkArgument(host != null, "No hostname is provided");
    // Setup dataset framework context, if required
    if (datasetFramework instanceof ProgramContextAware) {
        ProgramId programId = program.getId();
        ((ProgramContextAware) datasetFramework).setContext(new BasicProgramContext(programId.run(runId)));
    }
    final PluginInstantiator pluginInstantiator = createPluginInstantiator(options, program.getClassLoader());
    try {
        RetryStrategy retryStrategy = SystemArguments.getRetryStrategy(options.getUserArguments().asMap(), program.getType(), cConf);
        ArtifactManager artifactManager = artifactManagerFactory.create(program.getId().getNamespaceId(), retryStrategy);
        ServiceHttpServer component = new ServiceHttpServer(host, program, options, cConf, spec, instanceId, instanceCount, serviceAnnouncer, metricsCollectionService, datasetFramework, txClient, discoveryServiceClient, pluginInstantiator, secureStore, secureStoreManager, messagingService, artifactManager, metadataReader, metadataPublisher, namespaceQueryAdmin, pluginFinder, fieldLineageWriter, transactionRunner, preferencesFetcher, remoteClientFactory, contextAccessEnforcer);
        // Add a service listener to make sure the plugin instantiator is closed when the http server is finished.
        component.addListener(createRuntimeServiceListener(Collections.singleton(pluginInstantiator)), Threads.SAME_THREAD_EXECUTOR);
        ProgramController controller = new ServiceProgramControllerAdapter(component, program.getId().run(runId));
        component.start();
        return controller;
    } catch (Throwable t) {
        Closeables.closeQuietly(pluginInstantiator);
        throw t;
    }
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ServiceSpecification(io.cdap.cdap.api.service.ServiceSpecification) ProgramController(io.cdap.cdap.app.runtime.ProgramController) ProgramId(io.cdap.cdap.proto.id.ProgramId) BasicProgramContext(io.cdap.cdap.internal.app.runtime.BasicProgramContext) ServiceHttpServer(io.cdap.cdap.internal.app.services.ServiceHttpServer) ArtifactManager(io.cdap.cdap.api.artifact.ArtifactManager) PluginInstantiator(io.cdap.cdap.internal.app.runtime.plugin.PluginInstantiator) ProgramType(io.cdap.cdap.proto.ProgramType) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) RunId(org.apache.twill.api.RunId) ProgramContextAware(io.cdap.cdap.data.ProgramContextAware) RetryStrategy(io.cdap.cdap.common.service.RetryStrategy)

Aggregations

ArtifactManager (io.cdap.cdap.api.artifact.ArtifactManager)2 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)1 ArtifactInfo (io.cdap.cdap.api.artifact.ArtifactInfo)1 ServiceSpecification (io.cdap.cdap.api.service.ServiceSpecification)1 ProgramController (io.cdap.cdap.app.runtime.ProgramController)1 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)1 RetryStrategy (io.cdap.cdap.common.service.RetryStrategy)1 ProgramContextAware (io.cdap.cdap.data.ProgramContextAware)1 BasicProgramContext (io.cdap.cdap.internal.app.runtime.BasicProgramContext)1 PluginInstantiator (io.cdap.cdap.internal.app.runtime.plugin.PluginInstantiator)1 ServiceHttpServer (io.cdap.cdap.internal.app.services.ServiceHttpServer)1 ProgramType (io.cdap.cdap.proto.ProgramType)1 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)1 ProgramId (io.cdap.cdap.proto.id.ProgramId)1 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)1 IOException (java.io.IOException)1 RunId (org.apache.twill.api.RunId)1