Ejemplo n.º 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;
  }
Ejemplo n.º 2
0
  public ExecutionEnvironment.ExecutionState createExecutionState() {
    String releaseUsername = Context.buildUser(config);
    // TODO(mfu): Currently we leave release tag empty
    String releaseTag = "";
    String releaseVersion = Context.buildVersion(config);

    TopologyAPI.Topology topology = Runtime.topology(runtime);

    ExecutionEnvironment.ExecutionState.Builder builder =
        ExecutionEnvironment.ExecutionState.newBuilder();

    // set the topology name, id, submitting user and time
    builder
        .setTopologyName(topology.getName())
        .setTopologyId(topology.getId())
        .setSubmissionTime(System.currentTimeMillis() / 1000)
        .setSubmissionUser(System.getProperty("user.name"))
        .setCluster(Context.cluster(config))
        .setRole(Context.role(config))
        .setEnviron(Context.environ(config));

    // build the heron release state
    ExecutionEnvironment.HeronReleaseState.Builder releaseBuilder =
        ExecutionEnvironment.HeronReleaseState.newBuilder();

    releaseBuilder.setReleaseUsername(releaseUsername);
    releaseBuilder.setReleaseTag(releaseTag);
    releaseBuilder.setReleaseVersion(releaseVersion);

    builder.setReleaseState(releaseBuilder);
    if (builder.isInitialized()) {
      return builder.build();
    } else {
      throw new RuntimeException("Failed to create execution state");
    }
  }
Ejemplo n.º 3
0
  /**
   * Submit a topology 1. Instantiate necessary resources 2. Valid whether it is legal to submit a
   * topology 3. Call LauncherRunner
   */
  public void submitTopology() throws TopologySubmissionException {
    // 1. Do prepare work
    // create an instance of state manager
    String statemgrClass = Context.stateManagerClass(config);
    IStateManager statemgr;

    // Create an instance of the launcher class
    String launcherClass = Context.launcherClass(config);
    ILauncher launcher;

    // create an instance of the uploader class
    String uploaderClass = Context.uploaderClass(config);
    IUploader uploader;

    // create an instance of state manager
    try {
      statemgr = ReflectionUtils.newInstance(statemgrClass);
    } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
      throw new TopologySubmissionException(
          String.format("Failed to instantiate state manager class '%s'", statemgrClass), e);
    }

    // create an instance of launcher
    try {
      launcher = ReflectionUtils.newInstance(launcherClass);
    } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
      throw new LauncherException(
          String.format("Failed to instantiate launcher class '%s'", launcherClass), e);
    }

    // create an instance of uploader
    try {
      uploader = ReflectionUtils.newInstance(uploaderClass);
    } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
      throw new UploaderException(
          String.format("Failed to instantiate uploader class '%s'", uploaderClass), e);
    }

    // Put it in a try block so that we can always clean resources
    try {
      // initialize the state manager
      statemgr.initialize(config);

      // TODO(mfu): timeout should read from config
      SchedulerStateManagerAdaptor adaptor = new SchedulerStateManagerAdaptor(statemgr, 5000);

      validateSubmit(adaptor, topology.getName());

      // 2. Try to submit topology if valid
      // invoke method to submit the topology
      LOG.log(Level.FINE, "Topology {0} to be submitted", topology.getName());

      // Firstly, try to upload necessary packages
      URI packageURI = uploadPackage(uploader);

      // Secondly, try to submit a topology
      // build the runtime config
      Config runtime =
          Config.newBuilder()
              .putAll(LauncherUtils.getInstance().getPrimaryRuntime(topology, adaptor))
              .put(Keys.topologyPackageUri(), packageURI)
              .put(Keys.launcherClassInstance(), launcher)
              .build();

      callLauncherRunner(runtime);
    } catch (LauncherException | PackingException e) {
      // we undo uploading of topology package only if launcher fails to
      // launch topology, which will throw LauncherException or PackingException
      uploader.undo();
      throw e;
    } finally {
      SysUtils.closeIgnoringExceptions(uploader);
      SysUtils.closeIgnoringExceptions(launcher);
      SysUtils.closeIgnoringExceptions(statemgr);
    }
  }