當前位置: 首頁>>代碼示例>>Java>>正文


Java RuntimeSpecification類代碼示例

本文整理匯總了Java中org.apache.twill.api.RuntimeSpecification的典型用法代碼示例。如果您正苦於以下問題:Java RuntimeSpecification類的具體用法?Java RuntimeSpecification怎麽用?Java RuntimeSpecification使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RuntimeSpecification類屬於org.apache.twill.api包,在下文中一共展示了RuntimeSpecification類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: RunningContainers

import org.apache.twill.api.RuntimeSpecification; //導入依賴的package包/類
RunningContainers(TwillRuntimeSpecification twillRuntimeSpec, String appId, TwillRunResources appMasterResources,
                  ZKClient zookeeperClient, Location applicationLocation,
                  Map<String, RuntimeSpecification> runnables,
                  EventHandler eventHandler) {
  containers = HashBasedTable.create();
  runnableInstances = Maps.newHashMap();
  completedContainerCount = Maps.newHashMap();
  startSequence = Lists.newLinkedList();
  containerLock = new ReentrantLock();
  containerChange = containerLock.newCondition();
  resourceReport = new DefaultResourceReport(appId, appMasterResources);
  zkClient = zookeeperClient;
  containerStats = HashMultimap.create();
  this.applicationLocation = applicationLocation;
  this.runnableNames = runnables.keySet();
  this.logLevels = new TreeMap<>();
  this.maxRetries = Maps.newHashMap(twillRuntimeSpec.getMaxRetries());
  this.numRetries = Maps.newHashMap();
  this.eventHandler = eventHandler;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:21,代碼來源:RunningContainers.java

示例2: serialize

import org.apache.twill.api.RuntimeSpecification; //導入依賴的package包/類
@Override
public JsonElement serialize(TwillSpecification src, Type typeOfSrc, JsonSerializationContext context) {
  JsonObject json = new JsonObject();
  json.addProperty("name", src.getName());
  json.add("runnables", context.serialize(src.getRunnables(),
                                          new TypeToken<Map<String, RuntimeSpecification>>() { }.getType()));
  json.add("orders", context.serialize(src.getOrders(),
                                       new TypeToken<List<TwillSpecification.Order>>() { }.getType()));
  json.add("placementPolicies", context.serialize(
    src.getPlacementPolicies(), new TypeToken<List<TwillSpecification.PlacementPolicy>>() { }.getType()));
  EventHandlerSpecification eventHandler = src.getEventHandler();
  if (eventHandler != null) {
    json.add("handler", context.serialize(eventHandler, EventHandlerSpecification.class));
  }

  return json;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:18,代碼來源:TwillSpecificationCodec.java

示例3: deserialize

import org.apache.twill.api.RuntimeSpecification; //導入依賴的package包/類
@Override
public TwillSpecification deserialize(JsonElement json, Type typeOfT,
                                      JsonDeserializationContext context) throws JsonParseException {
  JsonObject jsonObj = json.getAsJsonObject();

  String name = jsonObj.get("name").getAsString();
  Map<String, RuntimeSpecification> runnables = context.deserialize(
    jsonObj.get("runnables"), new TypeToken<Map<String, RuntimeSpecification>>() { }.getType());
  List<TwillSpecification.Order> orders = context.deserialize(
    jsonObj.get("orders"), new TypeToken<List<TwillSpecification.Order>>() { }.getType());
  List<TwillSpecification.PlacementPolicy> placementPolicies = context.deserialize(
    jsonObj.get("placementPolicies"), new TypeToken<List<TwillSpecification.PlacementPolicy>>() { }.getType());

  JsonElement handler = jsonObj.get("handler");
  EventHandlerSpecification eventHandler = null;
  if (handler != null && !handler.isJsonNull()) {
    eventHandler = context.deserialize(handler, EventHandlerSpecification.class);
  }

  return new DefaultTwillSpecification(name, runnables, orders, placementPolicies, eventHandler);
}
 
開發者ID:apache,項目名稱:twill,代碼行數:22,代碼來源:TwillSpecificationCodec.java

示例4: TwillRuntimeSpecificationAdapter

import org.apache.twill.api.RuntimeSpecification; //導入依賴的package包/類
private TwillRuntimeSpecificationAdapter() {
  gson = new GsonBuilder()
            .serializeNulls()
            .registerTypeAdapter(TwillRuntimeSpecification.class, new TwillRuntimeSpecificationCodec())
            .registerTypeAdapter(TwillSpecification.class, new TwillSpecificationCodec())
            .registerTypeAdapter(TwillSpecification.Order.class, new TwillSpecificationOrderCoder())
            .registerTypeAdapter(TwillSpecification.PlacementPolicy.class,
                                 new TwillSpecificationPlacementPolicyCoder())
            .registerTypeAdapter(EventHandlerSpecification.class, new EventHandlerSpecificationCoder())
            .registerTypeAdapter(RuntimeSpecification.class, new RuntimeSpecificationCodec())
            .registerTypeAdapter(TwillRunnableSpecification.class, new TwillRunnableSpecificationCodec())
            .registerTypeAdapter(ResourceSpecification.class, new ResourceSpecificationCodec())
            .registerTypeAdapter(LocalFile.class, new LocalFileCodec())
            .registerTypeAdapterFactory(new TwillSpecificationTypeAdapterFactory())
            .create();
}
 
開發者ID:apache,項目名稱:twill,代碼行數:17,代碼來源:TwillRuntimeSpecificationAdapter.java

示例5: createContainerJar

import org.apache.twill.api.RuntimeSpecification; //導入依賴的package包/類
private void createContainerJar(ApplicationBundler bundler, Map<String, LocalFile> localFiles) throws IOException {
  try {
    Set<Class<?>> classes = Sets.newIdentityHashSet();
    classes.add(TwillContainerMain.class);
    classes.addAll(dependencies);

    ClassLoader classLoader = getClassLoader();
    for (RuntimeSpecification spec : twillSpec.getRunnables().values()) {
      classes.add(classLoader.loadClass(spec.getRunnableSpecification().getClassName()));
    }

    LOG.debug("Create and copy {}", Constants.Files.CONTAINER_JAR);
    Location location = createTempLocation(Constants.Files.CONTAINER_JAR);
    bundler.createBundle(location, classes, resources);
    LOG.debug("Done {}", Constants.Files.CONTAINER_JAR);

    localFiles.put(Constants.Files.CONTAINER_JAR, createLocalFile(Constants.Files.CONTAINER_JAR, location));

  } catch (ClassNotFoundException e) {
    throw Throwables.propagate(e);
  }
}
 
開發者ID:chtyim,項目名稱:incubator-twill,代碼行數:23,代碼來源:YarnTwillPreparer.java

示例6: DefaultTwillSpecification

import org.apache.twill.api.RuntimeSpecification; //導入依賴的package包/類
public DefaultTwillSpecification(String name, Map<String, RuntimeSpecification> runnables,
                                 List<Order> orders, List<PlacementPolicy> placementPolicies,
                                 EventHandlerSpecification eventHandler) {
  this.name = name;
  this.runnables = Collections.unmodifiableMap(new HashMap<String, RuntimeSpecification>(runnables));
  this.orders = Collections.unmodifiableList(new ArrayList<Order>(orders));
  this.placementPolicies = placementPolicies;
  this.eventHandler = eventHandler;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:10,代碼來源:DefaultTwillSpecification.java

示例7: ExpectedContainers

import org.apache.twill.api.RuntimeSpecification; //導入依賴的package包/類
ExpectedContainers(TwillSpecification twillSpec) {
  Map<String, ExpectedCount> expectedCounts = Maps.newHashMap();
  long now = System.currentTimeMillis();
  for (RuntimeSpecification runtimeSpec : twillSpec.getRunnables().values()) {
    expectedCounts.put(runtimeSpec.getName(),
                       new ExpectedCount(runtimeSpec.getResourceSpecification().getInstances(), now));
  }
  this.expectedCounts = expectedCounts;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:10,代碼來源:ExpectedContainers.java

示例8: RunnableContainerRequest

import org.apache.twill.api.RuntimeSpecification; //導入依賴的package包/類
RunnableContainerRequest(TwillSpecification.Order.Type orderType,
                         Map<AllocationSpecification, Collection<RuntimeSpecification>> requests,
                         boolean isReadyToBeProvisioned) {
  this.orderType = orderType;
  this.requests = requests.entrySet().iterator();
  this.isReadyToBeProvisioned = isReadyToBeProvisioned;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:8,代碼來源:RunnableContainerRequest.java

示例9: manageBlacklist

import org.apache.twill.api.RuntimeSpecification; //導入依賴的package包/類
/**
 * Manage Blacklist for a given request.
 */
private void manageBlacklist(Map.Entry<AllocationSpecification, ? extends Collection<RuntimeSpecification>> request) {
  amClient.clearBlacklist();

  //Check the allocation strategy
  AllocationSpecification allocationSpec = request.getKey();
  if (!allocationSpec.getType().equals(AllocationSpecification.Type.ALLOCATE_ONE_INSTANCE_AT_A_TIME)) {
    return;
  }

  //Check the placement policy
  String runnableName = allocationSpec.getRunnableName();
  TwillSpecification.PlacementPolicy placementPolicy = placementPolicyManager.getPlacementPolicy(runnableName);
  if (placementPolicy == null || placementPolicy.getType() != TwillSpecification.PlacementPolicy.Type.DISTRIBUTED) {
    return;
  }

  //Update blacklist with hosts which are running DISTRIBUTED runnables
  for (String runnable : placementPolicy.getNames()) {
    for (ContainerInfo containerInfo : runningContainers.getContainerInfo(runnable)) {
      // Yarn Resource Manager may include port in the node name depending on the setting
      // YarnConfiguration.RM_SCHEDULER_INCLUDE_PORT_IN_NODE_NAME. It is safe to add both
      // the names (with and without port) to the blacklist.
      LOG.debug("Adding {} to host blacklist", containerInfo.getHost().getHostName());
      amClient.addToBlacklist(containerInfo.getHost().getHostName());
      amClient.addToBlacklist(containerInfo.getHost().getHostName() + ":" + containerInfo.getPort());
    }
  }
}
 
開發者ID:apache,項目名稱:twill,代碼行數:32,代碼來源:ApplicationMasterService.java

示例10: addAllocationSpecification

import org.apache.twill.api.RuntimeSpecification; //導入依賴的package包/類
/**
 * Helper method to create {@link org.apache.twill.internal.appmaster.RunnableContainerRequest}.
 */
private void addAllocationSpecification(AllocationSpecification allocationSpecification,
                                        Map<AllocationSpecification, Collection<RuntimeSpecification>> map,
                                        RuntimeSpecification runtimeSpec) {
  if (!map.containsKey(allocationSpecification)) {
    map.put(allocationSpecification, Lists.<RuntimeSpecification>newLinkedList());
  }
  map.get(allocationSpecification).add(runtimeSpec);
}
 
開發者ID:apache,項目名稱:twill,代碼行數:12,代碼來源:ApplicationMasterService.java

示例11: addContainerRequests

import org.apache.twill.api.RuntimeSpecification; //導入依賴的package包/類
/**
 * Adds container requests with the given resource capability for each runtime.
 */
private void addContainerRequests(Resource capability,
                                  Collection<RuntimeSpecification> runtimeSpecs,
                                  Queue<ProvisionRequest> provisioning,
                                  AllocationSpecification.Type allocationType) {
  for (RuntimeSpecification runtimeSpec : runtimeSpecs) {
    String name = runtimeSpec.getName();
    int newContainers = expectedContainers.getExpected(name) - runningContainers.count(name);
    if (newContainers > 0) {
      if (allocationType.equals(AllocationSpecification.Type.ALLOCATE_ONE_INSTANCE_AT_A_TIME)) {
        //Spawning 1 instance at a time
        newContainers = 1;
      }

      // TODO: Allow user to set priority?
      LOG.info("Request {} containers with capability {} for runnable {}", newContainers, capability, name);
      YarnAMClient.ContainerRequestBuilder builder = amClient.addContainerRequest(capability, newContainers);
      builder.setPriority(0);

      TwillSpecification.PlacementPolicy placementPolicy = placementPolicyManager.getPlacementPolicy(name);
      if (placementPolicy != null) {
        builder.addHosts(placementPolicy.getHosts())
               .addRacks(placementPolicy.getRacks());
      }

      String requestId = builder.apply();
      provisioning.add(new ProvisionRequest(runtimeSpec, requestId, newContainers, allocationType));
    }
  }
}
 
開發者ID:apache,項目名稱:twill,代碼行數:33,代碼來源:ApplicationMasterService.java

示例12: ProvisionRequest

import org.apache.twill.api.RuntimeSpecification; //導入依賴的package包/類
ProvisionRequest(RuntimeSpecification runtimeSpec, String requestId, int requestCount,
                 AllocationSpecification.Type type) {
  this.runtimeSpec = runtimeSpec;
  this.requestId = requestId;
  this.requestCount = requestCount;
  this.type = type;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:8,代碼來源:ProvisionRequest.java

示例13: populateRunnableLocalFiles

import org.apache.twill.api.RuntimeSpecification; //導入依賴的package包/類
/**
 * Based on the given {@link TwillSpecification}, upload LocalFiles to Yarn Cluster.
 * @param twillSpec The {@link TwillSpecification} for populating resource.
 */
private Multimap<String, LocalFile> populateRunnableLocalFiles(TwillSpecification twillSpec) throws IOException {
  Multimap<String, LocalFile> localFiles = HashMultimap.create();

  LOG.debug("Populating Runnable LocalFiles");
  for (Map.Entry<String, RuntimeSpecification> entry: twillSpec.getRunnables().entrySet()) {
    String runnableName = entry.getKey();
    for (LocalFile localFile : entry.getValue().getLocalFiles()) {
      Location location;

      URI uri = localFile.getURI();
      if (appLocation.toURI().getScheme().equals(uri.getScheme())) {
        // If the source file location is having the same scheme as the target location, no need to copy
        location = appLocation.getLocationFactory().create(uri);
      } else {
        URL url = uri.toURL();
        LOG.debug("Create and copy {} : {}", runnableName, url);
        // Preserves original suffix for expansion.
        location = copyFromURL(url, createTempLocation(Paths.addExtension(url.getFile(), localFile.getName())));
        LOG.debug("Done {} : {}", runnableName, url);
      }

      localFiles.put(runnableName,
                     new DefaultLocalFile(localFile.getName(), location.toURI(), location.lastModified(),
                                          location.length(), localFile.isArchive(), localFile.getPattern()));
    }
  }
  LOG.debug("Done Runnable LocalFiles");
  return localFiles;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:34,代碼來源:YarnTwillPreparer.java

示例14: saveSpecification

import org.apache.twill.api.RuntimeSpecification; //導入依賴的package包/類
private TwillRuntimeSpecification saveSpecification(TwillSpecification spec, Path targetFile) throws IOException {
  final Multimap<String, LocalFile> runnableLocalFiles = populateRunnableLocalFiles(spec);

  // Rewrite LocalFiles inside twillSpec
  Map<String, RuntimeSpecification> runtimeSpec = Maps.transformEntries(
    spec.getRunnables(), new Maps.EntryTransformer<String, RuntimeSpecification, RuntimeSpecification>() {
      @Override
      public RuntimeSpecification transformEntry(String key, RuntimeSpecification value) {
        return new DefaultRuntimeSpecification(value.getName(), value.getRunnableSpecification(),
                                               value.getResourceSpecification(), runnableLocalFiles.get(key));
      }
    });

  // Serialize into a local temp file.
  LOG.debug("Creating {}", targetFile);
  try (Writer writer = Files.newBufferedWriter(targetFile, StandardCharsets.UTF_8)) {
    EventHandlerSpecification eventHandler = spec.getEventHandler();
    if (eventHandler == null) {
      eventHandler = new LogOnlyEventHandler().configure();
    }
    TwillSpecification newTwillSpec = new DefaultTwillSpecification(spec.getName(), runtimeSpec, spec.getOrders(),
                                                                    spec.getPlacementPolicies(), eventHandler);
    Map<String, String> configMap = Maps.newHashMap();
    for (Map.Entry<String, String> entry : config) {
      if (entry.getKey().startsWith("twill.")) {
        configMap.put(entry.getKey(), entry.getValue());
      }
    }

    TwillRuntimeSpecification twillRuntimeSpec = new TwillRuntimeSpecification(
      newTwillSpec, appLocation.getLocationFactory().getHomeLocation().getName(),
      appLocation.toURI(), zkConnectString, runId, twillSpec.getName(),
      config.get(YarnConfiguration.RM_SCHEDULER_ADDRESS),
      logLevels, maxRetries, configMap, runnableConfigs);
    TwillRuntimeSpecificationAdapter.create().toJson(twillRuntimeSpec, writer);
    LOG.debug("Done {}", targetFile);
    return twillRuntimeSpec;
  }
}
 
開發者ID:apache,項目名稱:twill,代碼行數:40,代碼來源:YarnTwillPreparer.java

示例15: serialize

import org.apache.twill.api.RuntimeSpecification; //導入依賴的package包/類
@Override
public JsonElement serialize(RuntimeSpecification src, Type typeOfSrc, JsonSerializationContext context) {
  JsonObject json = new JsonObject();
  json.addProperty("name", src.getName());
  json.add("runnable", context.serialize(src.getRunnableSpecification(), TwillRunnableSpecification.class));
  json.add("resources", context.serialize(src.getResourceSpecification(), ResourceSpecification.class));
  json.add("files", context.serialize(src.getLocalFiles(), new TypeToken<Collection<LocalFile>>() { }.getType()));

  return json;
}
 
開發者ID:apache,項目名稱:twill,代碼行數:11,代碼來源:RuntimeSpecificationCodec.java


注:本文中的org.apache.twill.api.RuntimeSpecification類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。