示例#1
0
  @Override
  public Boolean call() {
    SchedulerStateManagerAdaptor statemgr = Runtime.schedulerStateManagerAdaptor(runtime);
    TopologyAPI.Topology topology = Runtime.topology(runtime);
    String topologyName = Context.topologyName(config);

    // get the packed plan
    packing.initialize(config, runtime);
    PackingPlan packedPlan = packing.pack();
    if (packedPlan == null) {
      LOG.severe("Failed to pack a valid PackingPlan. Check the config.");
      return false;
    }

    // Add the instanceDistribution to the runtime
    Config ytruntime =
        Config.newBuilder()
            .putAll(runtime)
            .put(Keys.instanceDistribution(), packedPlan.getInstanceDistribution())
            .put(Keys.componentRamMap(), packedPlan.getComponentRamDistribution())
            .build();

    // initialize the launcher
    launcher.initialize(config, ytruntime);

    Boolean result;

    // Set topology def first since we determine whether a topology is running
    // by checking the existence of topology def
    // store the trimmed topology definition into the state manager
    result = statemgr.setTopology(trimTopology(topology), topologyName);
    if (result == null || !result) {
      LOG.severe("Failed to set topology definition");
      return false;
    }

    // store the execution state into the state manager
    ExecutionEnvironment.ExecutionState executionState = createExecutionState();

    result = statemgr.setExecutionState(executionState, topologyName);
    if (result == null || !result) {
      LOG.severe("Failed to set execution state");
      statemgr.deleteTopology(topologyName);
      return false;
    }

    // launch the topology, clear the state if it fails
    if (!launcher.launch(packedPlan)) {
      statemgr.deleteExecutionState(topologyName);
      statemgr.deleteTopology(topologyName);
      LOG.log(Level.SEVERE, "Failed to launch topology");
      return false;
    }

    return true;
  }