Package org.apache.twill.api

Examples of org.apache.twill.api.RuntimeSpecification


    // For each order in the twillSpec, create container request for each runnable.
    for (TwillSpecification.Order order : twillSpec.getOrders()) {
      // Group container requests based on resource requirement.
      ImmutableMultimap.Builder<Resource, RuntimeSpecification> builder = ImmutableMultimap.builder();
      for (String runnableName : order.getNames()) {
        RuntimeSpecification runtimeSpec = twillSpec.getRunnables().get(runnableName);
        Resource capability = createCapability(runtimeSpec.getResourceSpecification());
        builder.put(capability, runtimeSpec);
      }
      requests.add(new RunnableContainerRequest(order.getType(), builder.build()));
    }
    return requests;
View Full Code Here


      public boolean apply(TwillSpecification.Order input) {
        return (input.getNames().contains(runnableName));
      }
    });

    RuntimeSpecification runtimeSpec = twillSpec.getRunnables().get(runnableName);
    Resource capability = createCapability(runtimeSpec.getResourceSpecification());
    return new RunnableContainerRequest(order.getType(), ImmutableMultimap.of(capability, runtimeSpec));
  }
View Full Code Here

      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,
                                                                           discoverables);
View Full Code Here

      RunId runId = arguments.hasOption(ProgramOptionConstants.RUN_ID)
        ? RunIds.fromString(arguments.getOption(ProgramOptionConstants.RUN_ID))
        : RunIds.generate();

      ServiceSpecification serviceSpec = appSpec.getServices().get(processorName);
      final RuntimeSpecification runtimeSpec = serviceSpec.getRunnables().get(runnableName);
      String className = runtimeSpec.getRunnableSpecification().getClassName();
      LOG.info("Getting class : {}", program.getMainClass().getName());
      Class<?> clz = Class.forName(className, true, program.getClassLoader());
      Preconditions.checkArgument(TwillRunnable.class.isAssignableFrom(clz), "%s is not a TwillRunnable.", clz);

      if (clz.isAssignableFrom(HttpServiceTwillRunnable.class)) {
        // Special case for running http services since we need to instantiate the http service
        // using the program classloader.
        delegate = new HttpServiceTwillRunnable(program, runId, cConf, runnableName, metricsCollectionService,
                                                discoveryServiceClient, datasetFramework,
                                                transactionSystemClient);
      } else if (clz.isAssignableFrom(ServiceWorkerTwillRunnable.class)) {
        delegate = new ServiceWorkerTwillRunnable(program, runId, runnableName, program.getClassLoader(), cConf,
                                                  metricsCollectionService, datasetFramework,
                                                  transactionSystemClient,
                                                  discoveryServiceClient);
      } else {
        delegate = (TwillRunnable) new InstantiatorFactory(false).get(TypeToken.of(clz)).create();
      }

      Reflections.visit(delegate, TypeToken.of(delegate.getClass()),
                        new MetricsFieldSetter(new ServiceRunnableMetrics(metricsCollectionService,
                                                                          program.getApplicationId(),
                                                                          program.getName(), runnableName,
                                                                          context.getInstanceId())),
                        new PropertyFieldSetter(runtimeSpec.getRunnableSpecification().getConfigs()));

      final String[] argArray = RuntimeArguments.toPosixArray(programOpts.getUserArguments());
      LoggingContextAccessor.setLoggingContext(new UserServiceLoggingContext(
        program.getAccountId(), program.getApplicationId(), program.getName(), runnableName));
      delegate.initialize(new ForwardingTwillContext(context) {
        @Override
        public String[] getApplicationArguments() {
          return argArray;
        }

        @Override
        public TwillRunnableSpecification getSpecification() {
          return runtimeSpec.getRunnableSpecification();
        }

        @Override
        public Cancellable announce(String runnable, int port) {
          String serviceContextPath = String.format("%s.%s.%s.%s", ProgramType.SERVICE.name().toLowerCase(),
View Full Code Here

    Location programLocation = program.getJarLocation();
    String programName = programLocation.getName();
    TwillSpecification.Builder.RunnableSetter runnableSetter = null;
    for (Map.Entry<String, RuntimeSpecification> entry : spec.getRunnables().entrySet()) {
      RuntimeSpecification runtimeSpec = entry.getValue();
      ResourceSpecification resourceSpec = runtimeSpec.getResourceSpecification();

      String runnableName = entry.getKey();
      runnableSetter = moreRunnable
        .add(runnableName, new ServiceTwillRunnable(runnableName, "hConf.xml", "cConf.xml"), resourceSpec)
        .withLocalFiles().add(programName, programLocation.toURI())
View Full Code Here

    // For each order in the twillSpec, create container request for each runnable.
    for (TwillSpecification.Order order : twillSpec.getOrders()) {
      // Group container requests based on resource requirement.
      ImmutableMultimap.Builder<Resource, RuntimeSpecification> builder = ImmutableMultimap.builder();
      for (String runnableName : order.getNames()) {
        RuntimeSpecification runtimeSpec = twillSpec.getRunnables().get(runnableName);
        Resource capability = createCapability(runtimeSpec.getResourceSpecification());
        builder.put(capability, runtimeSpec);
      }
      requests.add(new RunnableContainerRequest(order.getType(), builder.build()));
    }
    return requests;
View Full Code Here

      public boolean apply(TwillSpecification.Order input) {
        return (input.getNames().contains(runnableName));
      }
    });

    RuntimeSpecification runtimeSpec = twillSpec.getRunnables().get(runnableName);
    Resource capability = createCapability(runtimeSpec.getResourceSpecification());
    return new RunnableContainerRequest(order.getType(), ImmutableMultimap.of(capability, runtimeSpec));
  }
View Full Code Here

    // For each order in the twillSpec, create container request for each runnable.
    for (TwillSpecification.Order order : twillSpec.getOrders()) {
      // Group container requests based on resource requirement.
      ImmutableMultimap.Builder<Resource, RuntimeSpecification> builder = ImmutableMultimap.builder();
      for (String runnableName : order.getNames()) {
        RuntimeSpecification runtimeSpec = twillSpec.getRunnables().get(runnableName);
        Resource capability = createCapability(runtimeSpec.getResourceSpecification());
        builder.put(capability, runtimeSpec);
      }
      requests.add(new RunnableContainerRequest(order.getType(), builder.build()));
    }
    return requests;
View Full Code Here

      public boolean apply(TwillSpecification.Order input) {
        return (input.getNames().contains(runnableName));
      }
    });

    RuntimeSpecification runtimeSpec = twillSpec.getRunnables().get(runnableName);
    Resource capability = createCapability(runtimeSpec.getResourceSpecification());
    return new RunnableContainerRequest(order.getType(), ImmutableMultimap.of(capability, runtimeSpec));
  }
View Full Code Here

      Id.Program programId = Id.Program.from(accountId, appId, serviceId);
      if (!store.programExists(programId, ProgramType.SERVICE)) {
        responder.sendString(HttpResponseStatus.NOT_FOUND, "Runnable not found");
        return;
      }
      RuntimeSpecification specification = getRuntimeSpecification(accountId, appId, serviceId, runnableName);
      if (specification == null) {
        responder.sendStatus(HttpResponseStatus.NOT_FOUND);
      } else {
        responder.sendJson(HttpResponseStatus.OK, new ServiceInstances(
          specification.getResourceSpecification().getInstances(),
          getRunnableCount(accountId, appId, serviceId, runnableName
        )));
      }
    } catch (SecurityException e) {
      responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
View Full Code Here

TOP

Related Classes of org.apache.twill.api.RuntimeSpecification

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.