Main run function for the application master

@throws YarnException
@throws IOException
559454
@SuppressWarnings({"unchecked"})
    public void run() throws Exception {
        LOG.info("Starting JstormMaster");
        Credentials credentials =
                UserGroupInformation.getCurrentUser().getCredentials();
        DataOutputBuffer dob = new DataOutputBuffer();
        credentials.writeTokenStorageToStream(dob);
        // Now remove the AM->RM token so that containers cannot access it.
        Iterator<Token<?>> iter = credentials.getAllTokens().iterator();
        LOG.info("Executing with tokens:");
        while (iter.hasNext()) {
            Token<?> token = iter.next();
            LOG.info(token);
            if (token.getKind().equals(AMRMTokenIdentifier.KIND_NAME)) {
                iter.remove();
            }
        }
        jstormMasterContext.allTokens = ByteBuffer.wrap(dob.getData(), 0, dob.getLength());

        // Create appSubmitterUgi and add original tokens to it
        String appSubmitterUserName =
                System.getenv(ApplicationConstants.Environment.USER.name());
        appSubmitterUgi =
                UserGroupInformation.createRemoteUser(appSubmitterUserName);
        appSubmitterUgi.addCredentials(credentials);


        AMRMClientAsync.CallbackHandler allocListener = new RMCallbackHandler();
        amRMClient = AMRMClientAsync.createAMRMClientAsync(JOYConstants.AM_RM_CLIENT_INTERVAL, allocListener);
        jstormMasterContext.amRMClient = amRMClient;
        amRMClient.init(conf);
        amRMClient.start();

        containerListener = createNMCallbackHandler();
        nmClientAsync = new NMClientAsyncImpl(containerListener);
        nmClientAsync.init(conf);
        nmClientAsync.start();

        startTimelineClient(conf);
        if (timelineClient != null) {
            publishApplicationAttemptEvent(timelineClient, jstormMasterContext.appAttemptID.toString(),
                    DSEvent.DS_APP_ATTEMPT_START, jstormMasterContext.domainId, appSubmitterUgi);
        }


        // Register self with ResourceManager
        // This will start heartbeating to the RM
        jstormMasterContext.appMasterHostname = NetUtils.getHostname();
        //get available port
        buildPortScanner();
        jstormMasterContext.appMasterThriftPort = portScanner.getAvailablePort();

        //since appMasterRpcPort not used yet,  set appMasterRpcPort to appMasterThriftPort
        jstormMasterContext.appMasterRpcPort = jstormMasterContext.appMasterThriftPort;

        RegisterApplicationMasterResponse response = amRMClient
                .registerApplicationMaster(jstormMasterContext.appMasterHostname, jstormMasterContext.appMasterRpcPort,
                        jstormMasterContext.appMasterTrackingUrl);
        // Dump out information about cluster capability as seen by the
        // resource manager
        jstormMasterContext.maxMemory = response.getMaximumResourceCapability().getMemory();
        LOG.info("Max mem capability of resources in this cluster " + jstormMasterContext.maxMemory);

        jstormMasterContext.maxVcores = response.getMaximumResourceCapability().getVirtualCores();
        LOG.info("Max vcores capability of resources in this cluster " + jstormMasterContext.maxVcores);

        // A resource ask cannot exceed the max.
        if (jstormMasterContext.containerMemory > jstormMasterContext.maxMemory) {
            LOG.info("Container memory specified above max threshold of cluster."
                    + " Using max value." + ", specified=" + jstormMasterContext.containerMemory + ", max="
                    + jstormMasterContext.maxMemory);
            jstormMasterContext.containerMemory = jstormMasterContext.maxMemory;
        }

        if (jstormMasterContext.containerVirtualCores > jstormMasterContext.maxVcores) {
            LOG.info("Container virtual cores specified above max threshold of cluster."
                    + " Using max value." + ", specified=" + jstormMasterContext.containerVirtualCores + ", max="
                    + jstormMasterContext.maxVcores);
            jstormMasterContext.containerVirtualCores = jstormMasterContext.maxVcores;
        }

        List<Container> previousAMRunningContainers =
                response.getContainersFromPreviousAttempts();
        LOG.info(jstormMasterContext.appAttemptID + " received " + previousAMRunningContainers.size()
                + " previous attempts' running containers on AM registration.");
        jstormMasterContext.numAllocatedContainers.addAndGet(previousAMRunningContainers.size());

        //Setup RegistryOperations
        registryOperations = RegistryOperationsFactory.createInstance(JOYConstants.YARN_REGISTRY, conf);
        setupInitialRegistryPaths();
        registryOperations.start();

        //add previous AM containers to supervisor and nimbus container list
        for (Container container : previousAMRunningContainers) {

            String containerPath = RegistryUtils.componentPath(
                    JOYConstants.APP_TYPE, jstormMasterContext.instanceName,
                    container.getId().getApplicationAttemptId().getApplicationId().toString(), container.getId().toString());
            ServiceRecord sr = null;
            try {
                if (!registryOperations.exists(containerPath)) {

                    String contianerHost = container.getNodeId().getHost();
                    registryOperations.mknode(containerPath, true);
                    sr = new ServiceRecord();
                    sr.set(JOYConstants.HOST, contianerHost);
                    sr.set(YarnRegistryAttributes.YARN_ID, container.getId().toString());
                    sr.description = JOYConstants.CONTAINER;
                    sr.set(YarnRegistryAttributes.YARN_PERSISTENCE,
                            PersistencePolicies.CONTAINER);
                    registryOperations.bind(containerPath, sr, BindFlags.OVERWRITE);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

            if (container.getPriority().getPriority() == 0)
                jstormMasterContext.supervisorContainers.add(container);
            else if (container.getPriority().getPriority() == 1) {
                jstormMasterContext.nimbusContainers.add(container);
            }
        }

        jstormMasterContext.requestBlockingQueue = new LinkedBlockingQueue<ContainerRequest>();

        jstormMasterContext.service_user_name = RegistryUtils.currentUser();

        jstormMasterContext.instanceName = conf.get(JOYConstants.INSTANCE_NAME_KEY);
        this.jstormMasterContext.user = conf.get(JOYConstants.JSTORM_YARN_USER);
        this.jstormMasterContext.password = conf.get(JOYConstants.JSTORM_YARN_PASSWORD);
        this.jstormMasterContext.oldPassword = conf.get(JOYConstants.JSTORM_YARN_OLD_PASSWORD);

        LOG.info("find available port for am rpc server which is : " + jstormMasterContext.appMasterThriftPort);

        String appPath = RegistryUtils.servicePath(
                JOYConstants.APP_TYPE, jstormMasterContext.instanceName, jstormMasterContext.appAttemptID.getApplicationId().toString());
        String instancePath = RegistryUtils.serviceclassPath(
                JOYConstants.APP_TYPE, jstormMasterContext.instanceName);

        LOG.info("Registering application " + jstormMasterContext.appAttemptID.getApplicationId().toString());

        ServiceRecord application = setupServiceRecord();
        jstormMasterContext.nimbusDataDirPrefix = conf.get(JOYConstants.INSTANCE_DATA_DIR_KEY);
        LOG.info("generate instancePath on zk , path is:" + instancePath);

        if (registryOperations.exists(instancePath)) {
            ServiceRecord previousRegister = registryOperations.resolve(instancePath);
            application.set(JOYConstants.NIMBUS_HOST, previousRegister.get(JOYConstants.NIMBUS_HOST, JOYConstants.EMPTY));
            application.set(JOYConstants.NIMBUS_CONTAINER, previousRegister.get(JOYConstants.NIMBUS_CONTAINER, JOYConstants.EMPTY));
            application.set(JOYConstants.NIMBUS_LOCAL_DIR, previousRegister.get(JOYConstants.NIMBUS_LOCAL_DIR, JOYConstants.EMPTY));

            jstormMasterContext.previousNimbusHost = previousRegister.get(JOYConstants.NIMBUS_HOST, "");

            Date now = new Date();
            Map<String, ServiceRecord> apps = RegistryUtils.listServiceRecords(registryOperations, instancePath);
            for (String subAppPath : apps.keySet()) {
                LOG.info("existApp:" + subAppPath);
                ServiceRecord subApp = apps.get(subAppPath);
                Long lastHeatBeatTime = 0l;
                try {
                    lastHeatBeatTime = Long.parseLong(subApp.get(JOYConstants.APP_HEARTBEAT_TIME));
                } catch (Exception e) {
                    LOG.error(e);
                }
                if (now.getTime() - lastHeatBeatTime > 5 * JOYConstants.HEARTBEAT_TIME_INTERVAL
                        || lastHeatBeatTime > now.getTime() || subAppPath.trim().equals(appPath.trim())) {
                    LOG.info("application " + subAppPath + " not response , delete it!");
                    registryOperations.delete(subAppPath, true);
                }
            }
        }

        if (!jstormMasterContext.done) {
            jstormMasterContext.config = conf;
            registryOperations.mknode(appPath, true);
            registryOperations.bind(instancePath, application, BindFlags.OVERWRITE);
            ServiceRecord previousRegister = registryOperations.resolve(instancePath);
            LOG.info("previousRegister:" + previousRegister.toString());
            LOG.info("register path: " + instancePath);
            AMServer as = new AMServer(jstormMasterContext.appMasterThriftPort);
            as.Start(this);
        }
    }
1089020
public static void main(String[] args) throws IOException {
		ExampleHelpers.configureLogging();
		JsonSerializationProcessor.printDocumentation();

		JsonSerializationProcessor jsonSerializationProcessor = new JsonSerializationProcessor();
		ExampleHelpers.processEntitiesFromWikidataDump(jsonSerializationProcessor);
		jsonSerializationProcessor.close();
	}
115256
public void run() {

        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && logger.isLoggable(Level.FINER)) {
            logger.logp(Level.FINER, CLASS_NAME, "run", "enter");
        }

        String docRoot = null, threadParam = null;

        Container container = webapp.getModuleContainer();
        if (container != null) {
            hasContainer = true;
        } else {
            docRoot = webapp.getRealPath("/");
        }
        /*
         * First we gather information about the webapp and the parameters that
         * were specified.
         */
        //appName = webapp.getWebAppName();
        appName = webapp.getWebAppConfig().getApplicationName();

        //Get the maximum length of the files that we will only compile.... the rest are also classloaded
        _minLength = options.getPrepareJSPs() * 1024;

        if (options.getPrepareJSPsClassloadChanged() != null) {
            onlyCLChanged = true;
            _startAt = Constants.PREPARE_JSPS_DEFAULT_STARTAT;
        } else {
            _startAt = options.getPrepareJSPsClassload();
        }

        _threads = options.getPrepareJSPThreadCount();

        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()) {
            logger.logp(Level.INFO, CLASS_NAME, "run", "PrepareJspHelper executing on application [" + this.appName + "]");
        }

        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && logger.isLoggable(Level.FINE)) {
            logger.logp(Level.FINE, CLASS_NAME, "run", "PrepareJspHelper: Document Root: " + docRoot);
            logger.logp(Level.FINE, CLASS_NAME, "run", "PrepareJspHelper: File size minimum (in bytes): " + _minLength);
            logger.logp(Level.FINE, CLASS_NAME, "run", "PrepareJspHelper: Number of threads: " + _threads);

            if (onlyCLChanged) {
                logger.logp(Level.FINE, CLASS_NAME, "run", "PrepareJspHelper: Only classloading out-of-date (changed) JSPs.");
            } else {
                logger.logp(Level.FINE, CLASS_NAME, "run", "PrepareJspHelper: Classloading JSPs starting at JSP number " + _startAt);
            }

        }

        if (container != null) {
            createListOfEntries(container);
        }

        //Create worker threads and let them start compiling.
        try {
            Thread[] threads = new Thread[_threads];
            int i;
            for (i = 0; i < _threads; i++) {
                PrepareJspHelperThread helper = new PrepareJspHelperThread(this, docRoot, container);
                threads[i] = new Thread(helper, "PrepareJspHelperThread " + i);
                threads[i].setDaemon(true);
                threads[i].start();
            }
            //now lets wait for all the threads to die.
            for (i = 0; i < _threads; i++) {
                try {
                    threads[i].join();
                } catch (Throwable th) {
                    if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && logger.isLoggable(Level.WARNING)) {
                        logger.logp(Level.WARNING, CLASS_NAME, "run", "Pretouch Thread died during execution.", th);
                    }
                }
            }
        } catch (Exception ex) {
            logger.logp(Level.WARNING, CLASS_NAME, "run", "Unexpected exception while running pretouch.", ex);
        }

        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && logger.isLoggable(Level.INFO)) {
            logger.logp(Level.INFO, CLASS_NAME, "run", "PrepareJspHelper in group [" + appName + "]: All " + _counter + " jsp files have been processed.");
        }

        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && logger.isLoggable(Level.FINER)) {
            logger.logp(Level.FINER, CLASS_NAME, "run", "< run");
        }
    }
201609
function main() {
    const options = queryOptions();
    switch (options.porting) {
        case 'build':
            runBuild(options)
            .catch((reason) => {
                console.error(reason);
                process.exit(1);
            });
            break;
        case 'arrange':
            runArrange(options);
            break;
        case 'rebase':
            runRebase(options);
            break;
        case 'clean':
            runClean(options);
            break;
    }
}
1049954
function(master)
{
    var self = this;

    this.methods   = {};
    this.processes = {};
    this.master    = master;

    // Inject predefined methods
    var defaultIPCPath = __dirname + '/ipc/';
    fs.readdirSync(defaultIPCPath).forEach(function(file) {

        if (!file.match(/\.js$/)) {
            return;
        }

        var ObjectClass = require(defaultIPCPath + file);
        var obj         = new ObjectClass({master: master});
        var className   = file.replace(/\.js$/i, '');

        Object.getOwnPropertyNames(ObjectClass.prototype).forEach(function(method) {

            if ('constructor' === method) {
                return;
            }

            self.addMethod(className + '.' + method, obj[method], obj);
        });
    });
}
1217124
def run(self):
        
        luigi.LocalTarget(path=self.fixture).copy(self.output().path)
738073
function main() {
  config = createConfig(process.argv.slice(2));

  if (config.options.help) {
    config.options.showHelp(NODE_DEBUG_MODE);
    process.exit();
  }

  if (config.options.version) {
    config.options.showVersion();
    process.exit();
  }

  process.on('SIGINT', function() {
     process.exit();
  });

  startInspectorProcess(function(error, result) {
    if (error) {
      console.error(formatNodeInspectorError(error));
      process.exit(1);
    }

    var url = result.address.url;
    var isUnixSocket = result.address.isUnixSocket;

    startDebuggedProcess(function(error) {
      if (error) {
        console.error('Cannot start %s: %s', config.subproc.script, error.message || error);
        process.exit(2);
      }

      openBrowserAndPrintInfo(url, isUnixSocket);
    });
  });
}
304878
public void run() {
        synchronized (this) {
            started = true;
        }
        finished = false;
        finish = false;

        try {
            while (true) {
                waitForInput(is);

                if (finish || Thread.interrupted()) {
                    break;
                }

                int availableBytes = is.available();
                byte[] buf = new byte[availableBytes];
                int actualBytesRead = is.read(buf, 0, availableBytes);

                if (actualBytesRead <= 0 || finish || Thread.interrupted()) {
                    break;
                }
                os.write(buf, 0, actualBytesRead);
                if (autoflush) {
                    os.flush();
                }
            }
            os.flush();
        } catch (InterruptedException ie) {
            // likely PumpStreamHandler trying to stop us
        } catch (Exception e) {
            synchronized (this) {
                exception = e;
            }
        } finally {
            if (closeWhenExhausted) {
                FileUtils.close(os);
            }
            finished = true;
            synchronized (this) {
                notifyAll();
            }
        }
    }
1210539
public void run() {
    while (running) {
      try {
        LOG.info("FileFixer continuing to run...");
        doFindFiles();
      } catch (Exception e) {
        LOG.error(StringUtils.stringifyException(e));
      } catch (Error err) {
        LOG.error("Exiting after encountering " +
                    StringUtils.stringifyException(err));
        shutdown();
        throw err;
      }
      try {
        // Sleep before proceeding to fix more files.
        Thread.sleep(blockFixInterval);
      } catch (InterruptedException ie) {
        LOG.error("Encountering InturruptedException " +
                   StringUtils.stringifyException(ie));
      }
    }
  }
197008
def main(**kwargs):
    """"""
    options = ApplicationOptions(**kwargs)
    Event.configure(is_logging_enabled=options.event_logging)
    application = Application(options)
    application.run(options.definition)
47644
public void run() {
        try {
            ServerSocket serverSocket = new ServerSocket(url.getPort());
            while (true) {
                // Create one script per socket connection.
                // This is purposefully not caching the Script
                // so that the script source file can be changed on the fly,
                // as each connection is made to the server.
                //FIXME: Groovy has other mechanisms specifically for watching to see if source code changes.
                // We should probably be using that here.
                // See also the comment about the fact we recompile a script that can't change.
                Script script = groovy.parse(source);
                new GroovyClientConnection(script, autoOutput, serverSocket.accept());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
820819
public synchronized void start() throws IOException {
    Preconditions.checkState(mProcess == null, "Process is already running");
    String java = PathUtils.concatPath(System.getProperty("java.home"), "bin", "java");
    String classpath = System.getProperty("java.class.path");
    List<String> args = new ArrayList<>(Arrays.asList(java, "-cp", classpath));
    for (Entry<PropertyKey, String> entry : mConf.entrySet()) {
      args.add(String.format("-D%s=%s", entry.getKey().toString(), entry.getValue()));
    }
    args.add(mClazz.getCanonicalName());
    ProcessBuilder pb = new ProcessBuilder(args);
    pb.redirectError(mOutFile);
    pb.redirectOutput(mOutFile);
    mProcess = pb.start();
  }
1277098
public void start() {
    mMasterProcess = AlluxioMasterProcess.Factory.create();
    Runnable runMaster = new Runnable() {
      @Override
      public void run() {
        try {
          LOG.info("Starting Alluxio master {}.", mMasterProcess);
          mMasterProcess.start();
        } catch (InterruptedException e) {
          // this is expected
        } catch (Exception e) {
          // Log the exception as the RuntimeException will be caught and handled silently by JUnit
          LOG.error("Start master error", e);
          throw new RuntimeException(e + " \n Start Master Error \n" + e.getMessage(), e);
        }
      }
    };
    mMasterThread = new Thread(runMaster);
    mMasterThread.setName("MasterThread-" + System.identityHashCode(mMasterThread));
    mMasterThread.start();
    TestUtils.waitForReady(mMasterProcess);
    // Don't start a secondary master when using the Raft journal.
    if (ServerConfiguration.getEnum(PropertyKey.MASTER_JOURNAL_TYPE,
        JournalType.class) == JournalType.EMBEDDED) {
      return;
    }
    if (!mIncludeSecondary) {
      return;
    }
    mSecondaryMaster = new AlluxioSecondaryMaster();
    Runnable runSecondaryMaster = new Runnable() {
      @Override
      public void run() {
        try {
          LOG.info("Starting secondary master {}.", mSecondaryMaster);
          mSecondaryMaster.start();
        } catch (InterruptedException e) {
          // this is expected
        } catch (Exception e) {
          // Log the exception as the RuntimeException will be caught and handled silently by JUnit
          LOG.error("Start secondary master error", e);
          throw new RuntimeException(e + " \n Start Secondary Master Error \n" + e.getMessage(), e);
        }
      }
    };
    mSecondaryMasterThread = new Thread(runSecondaryMaster);
    mSecondaryMasterThread
        .setName("SecondaryMasterThread-" + System.identityHashCode(mSecondaryMasterThread));
    mSecondaryMasterThread.start();
    TestUtils.waitForReady(mSecondaryMaster);
  }
994464
@SuppressWarnings("static-access")
	public static void main(String[] args) throws IOException {		
		Option configDirOpt = OptionBuilder.withArgName("config directory").hasArg().withDescription(
			"Specify configuration directory.").create("configDir");
		// tempDir option is used by the YARN client.
		Option tempDir = OptionBuilder.withArgName("temporary directory (overwrites configured option)")
				.hasArg().withDescription(
				"Specify temporary directory.").create(ARG_CONF_DIR);
		configDirOpt.setRequired(true);
		tempDir.setRequired(false);
		Options options = new Options();
		options.addOption(configDirOpt);
		options.addOption(tempDir);
		

		CommandLineParser parser = new GnuParser();
		CommandLine line = null;
		try {
			line = parser.parse(options, args);
		} catch (ParseException e) {
			System.err.println("CLI Parsing failed. Reason: " + e.getMessage());
			System.exit(FAILURE_RETURN_CODE);
		}

		String configDir = line.getOptionValue(configDirOpt.getOpt(), null);
		String tempDirVal = line.getOptionValue(tempDir.getOpt(), null);

		// First, try to load global configuration
		GlobalConfiguration.loadConfiguration(configDir);
		if(tempDirVal != null // the YARN TM runner has set a value for the temp dir
				// the configuration does not contain a temp direcory
				&& GlobalConfiguration.getString(ConfigConstants.TASK_MANAGER_TMP_DIR_KEY, null) == null) {
			Configuration c = GlobalConfiguration.getConfiguration();
			c.setString(ConfigConstants.TASK_MANAGER_TMP_DIR_KEY, tempDirVal);
			LOG.info("Setting temporary directory to "+tempDirVal);
			GlobalConfiguration.includeConfiguration(c);
		}
		System.err.println("Configuration "+GlobalConfiguration.getConfiguration());
		LOG.info("Current user "+UserGroupInformation.getCurrentUser().getShortUserName());
		
		{
			// log the available JVM memory
			long maxMemoryMiBytes = Runtime.getRuntime().maxMemory() >>> 20;
			LOG.info("Starting TaskManager in a JVM with " + maxMemoryMiBytes + " MiBytes maximum heap size.");
		}
		
		// Create a new task manager object
		try {
			new TaskManager();
		} catch (Exception e) {
			LOG.fatal("Taskmanager startup failed: " + e.getMessage(), e);
			System.exit(FAILURE_RETURN_CODE);
		}
		
		// park the main thread to keep the JVM alive (all other threads may be daemon threads)
		Object mon = new Object();
		synchronized (mon) {
			try {
				mon.wait();
			} catch (InterruptedException ex) {}
		}
	}
648964
function main() {
	// TODO: move loading of inputs into main function
	check(lookupQType(typeDecl.global,[]), {key: snapshot.global}, '', false, null, '<global>');
	if (program.missing) {
		findSuggestions()
	}
	if (program.coverage) {
		printCoverage();
	}
	if (program.stats) {
		console.log("# heap objects = " + snapshot.heap.length)
		console.log("# call signatures = " + num_callsigs_analyzed)
	}
}
166348
@Override
  protected void run() throws Exception {
    final ResourceLoader resourceLoader = new MojoResourceLoader(getRuntimeRealm(), getScriptpath());
    final Map<String, Object> context = createContext();
    final Map<String, Object> options = Maps.newHashMap();
    final ConsoleWindow console = getRuntime().createConsoleWindow();

    WindowHandle handle = console.open(getRuntimeRealm(), resourceLoader, context, options);
    handle.await();
  }
298521
public void run() {
    String hostName = host != null ? host : "localhost";
    ServerTools.print("Starting LanguageTool " + JLanguageTool.VERSION +
            " (build date: " + JLanguageTool.BUILD_DATE + ", " + JLanguageTool.GIT_SHORT_ID + ") server on " + getProtocol() + "://" + hostName + ":" + port  + "...");
    server.start();
    isRunning = true;
    ServerTools.print("Server started");
  }