Package co.cask.cdap.api.service

Examples of co.cask.cdap.api.service.ServiceSpecification


      Preconditions.checkArgument(processorType == ProgramType.SERVICE, "Only Service process type is supported.");

      String processorName = program.getName();
      Preconditions.checkNotNull(processorName, "Missing processor name.");

      ServiceSpecification serviceSpec = appSpec.getServices().get(processorName);
      RuntimeSpecification runnableSpec = serviceSpec.getRunnables().get(runnableName);
      Preconditions.checkNotNull(runnableSpec, "RuntimeSpecification missing for Runnable \"%s\"", runnableName);

      Class<?> clz = null;

      String classStr = runnableSpec.getRunnableSpecification().getClassName();
      // special case for handling http service
      if (classStr.equals(HttpServiceTwillRunnable.class.getName())) {
        clz = HttpServiceTwillRunnable.class;
      } else {
        clz = Class.forName(runnableSpec.getRunnableSpecification().getClassName(),
                            true, program.getClassLoader());
      }

      Preconditions.checkArgument(TwillRunnable.class.isAssignableFrom(clz), "%s is not a TwillRunnable.", clz);

      Class<? extends TwillRunnable> runnableClass = (Class<? extends TwillRunnable>) clz;
      RunId twillRunId = RunIds.generate();
      final String[] argArray = RuntimeArguments.toPosixArray(options.getUserArguments());

      DiscoveryService dService = new DiscoveryService() {
        @Override
        public Cancellable register(final Discoverable discoverable) {
          discoverables.add(discoverable);
          return dsService.register(new Discoverable() {
            @Override
            public String getName() {
              return String.format("service.%s.%s.%s", program.getAccountId(),
                                   program.getApplicationId(), program.getName());
            }

            @Override
            public InetSocketAddress getSocketAddress() {
              return discoverable.getSocketAddress();
            }
          });
        }
      };

      twillContext = new InMemoryTwillContext(twillRunId, runId, InetAddress.getLocalHost(), new String[0], argArray,
                                              runnableSpec.getRunnableSpecification(), instanceId,
                                              runnableSpec.getResourceSpecification().getVirtualCores(),
                                              runnableSpec.getResourceSpecification().getMemorySize(),
                                              discoveryServiceClient, dService, instanceCount, electionRegistry);

      TypeToken<? extends  TwillRunnable> runnableType = TypeToken.of(runnableClass);
      TwillRunnable runnable = null;

      if (runnableClass.isAssignableFrom(HttpServiceTwillRunnable.class)) {
        // Special case for running HTTP services
        runnable = new HttpServiceTwillRunnable(program, runId, cConfiguration, runnableName, metricsCollectionService,
                                                discoveryServiceClient, datasetFramework,
                                                transactionSystemClient);
      } else if (runnableClass.isAssignableFrom(ServiceWorkerTwillRunnable.class)) {
        runnable = new ServiceWorkerTwillRunnable(program, runId, runnableName, program.getClassLoader(),
                                                  cConfiguration, metricsCollectionService, datasetFramework,
                                                  transactionSystemClient, discoveryServiceClient);
      } else {
        runnable = new InstantiatorFactory(false).get(runnableType).create();
      }

      InMemoryRunnableDriver driver = new
        InMemoryRunnableDriver(runnable, twillContext, new UserServiceLoggingContext(program.getAccountId(),
                                                                                     program.getApplicationId(),
                                                                                     processorName,
                                                                                     runnableName));

      //Injecting Metrics
      Reflections.visit(runnable, runnableType,
                        new MetricsFieldSetter(new ServiceRunnableMetrics(metricsCollectionService,
                                                                          program.getApplicationId(),
                                                                          serviceSpec.getName(), runnableName,
                                                                          twillContext.getInstanceId())),
                        new PropertyFieldSetter(runnableSpec.getRunnableSpecification().getConfigs()));

      ProgramController controller = new InMemoryRunnableProgramController(program.getName(), runnableName,
                                                                           twillContext, driver,
View Full Code Here


    ProgramType processorType = program.getType();
    Preconditions.checkNotNull(processorType, "Missing processor type.");
    Preconditions.checkArgument(processorType == ProgramType.SERVICE, "Only SERVICE process type is supported.");

    ServiceSpecification serviceSpec = appSpec.getServices().get(program.getName());
    Preconditions.checkNotNull(serviceSpec, "Missing ServiceSpecification for %s", program.getName());

    //RunId for the service
    RunId runId = RunIds.generate();
    programOptions.put(runId, options);
View Full Code Here

              addCodeError(requestedObj, HttpResponseStatus.NOT_FOUND.getCode(), "Flow: " + programId + " not found");
              continue;
            }
          } else {
            // Services
            ServiceSpecification serviceSpec = spec.getServices().get(programId);
            if (serviceSpec != null) {
              Map<String, RuntimeSpecification> runtimeSpecs = serviceSpec.getRunnables();
              if (runtimeSpecs != null && runtimeSpecs.containsKey(runnableId)) {
                requested = runtimeSpecs.get(runnableId).getResourceSpecification().getInstances();
              } else {
                addCodeError(requestedObj, HttpResponseStatus.NOT_FOUND.getCode(),
                             "Runnable: " + runnableId + " not found");
View Full Code Here

  public int getServiceRunnableInstances(final Id.Program id, final String runnable) {
    return txnl.executeUnchecked(new TransactionExecutor.Function<AppMds, Integer>() {
      @Override
      public Integer apply(AppMds mds) throws Exception {
        ApplicationSpecification appSpec = getAppSpecOrFail(mds, id);
        ServiceSpecification serviceSpec = getServiceSpecOrFail(id, appSpec);
        RuntimeSpecification runtimeSpec = getRunnableSpecOrFail(id, serviceSpec, runnable);
        return runtimeSpec.getResourceSpecification().getInstances();
      }
    });
  }
View Full Code Here

    txnl.executeUnchecked(new TransactionExecutor.Function<AppMds, Void>() {
      @Override
      public Void apply(AppMds mds) throws Exception {
        ApplicationSpecification appSpec = getAppSpecOrFail(mds, id);
        ServiceSpecification serviceSpec = getServiceSpecOrFail(id, appSpec);

        RuntimeSpecification runtimeSpec = serviceSpec.getRunnables().get(runnable);
        if (runtimeSpec == null) {
          throw new IllegalArgumentException(String.format("Runnable not found, app: %s, service: %s, runnable %s",
                                                           id.getApplication(), id.getId(), runnable));
        }
View Full Code Here

    }
    return flowSpec;
  }

  private static ServiceSpecification getServiceSpecOrFail(Id.Program id, ApplicationSpecification appSpec) {
    ServiceSpecification spec = appSpec.getServices().get(id.getId());
    if (spec == null) {
      throw new NoSuchElementException("no such service @ account id: " + id.getAccountId() +
                                           ", app id: " + id.getApplication() +
                                           ", service id: " + id.getId());
    }
View Full Code Here

      String accountId = getAuthenticatedAccountId(request);
      ApplicationSpecification spec = store.getApplication(Id.Application.from(accountId, appId));
      if (spec != null) {
        List<ProgramRecord> services = Lists.newArrayList();
        for (Map.Entry<String, ServiceSpecification> entry : spec.getServices().entrySet()) {
          ServiceSpecification specification = entry.getValue();
          services.add(new ProgramRecord(ProgramType.SERVICE, appId, specification.getName(),
                                         specification.getName(), specification.getDescription()));
        }
        responder.sendJson(HttpResponseStatus.OK, services);
      } else {
        responder.sendStatus(HttpResponseStatus.NOT_FOUND);
      }
View Full Code Here

                         @PathParam("app-id") String appId,
                         @PathParam("service-id") String serviceId) {

    try {
      String accountId = getAuthenticatedAccountId(request);
      ServiceSpecification spec = getServiceSpecification(accountId, appId, serviceId);
      if (spec != null) {
        responder.sendJson(HttpResponseStatus.OK, new ServiceMeta(
          spec.getName(), spec.getName(), spec.getDescription(), spec.getRunnables().keySet()));
      } else {
        responder.sendStatus(HttpResponseStatus.NOT_FOUND);
      }
    } catch (SecurityException e) {
      responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
View Full Code Here

  }

  @Nullable
  private RuntimeSpecification getRuntimeSpecification(String accountId, String appId, String serviceName,
                                                        String runnableName) throws OperationException {
    ServiceSpecification specification = getServiceSpecification(accountId, appId, serviceName);
    if (specification != null) {
      Map<String, RuntimeSpecification> runtimeSpecs =  specification.getRunnables();
      return runtimeSpecs.containsKey(runnableName) ? runtimeSpecs.get(runnableName) : null;
    } else {
      return null;
    }
  }
View Full Code Here

    ProgramType processorType = program.getType();
    Preconditions.checkNotNull(processorType, "Missing processor type.");
    Preconditions.checkArgument(processorType == ProgramType.SERVICE, "Only SERVICE process type is supported.");

    final ServiceSpecification serviceSpec = appSpec.getServices().get(program.getName());
    Preconditions.checkNotNull(serviceSpec, "Missing ServiceSpecification for %s", program.getName());

    // Launch service runnables program runners
    LOG.info("Launching distributed service: {}:{}", program.getName(), serviceSpec.getName());

    TwillController controller = launcher.launch(new ServiceTwillApplication(program, serviceSpec, hConfFile,
                                                                             cConfFile, eventHandler));

    DistributedServiceRunnableInstanceUpdater instanceUpdater = new DistributedServiceRunnableInstanceUpdater(
View Full Code Here

TOP

Related Classes of co.cask.cdap.api.service.ServiceSpecification

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.