List of usage examples for java.lang IllegalArgumentException getLocalizedMessage
public String getLocalizedMessage()
From source file:com.keithandthegirl.ui.activity.GuestsDashboardFragment.java
@Override public void onPause() { Log.v(TAG, "onPause : enter"); super.onPause(); if (null != downloadReceiver) { try {// w ww . jav a 2 s . co m getActivity().unregisterReceiver(downloadReceiver); downloadReceiver = null; } catch (IllegalArgumentException e) { Log.e(TAG, e.getLocalizedMessage(), e); } } Log.v(TAG, "onPause : exit"); }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeWithPrecisionVTwo.java
private Map<String, String> checkDate(String precisionURI, Map<String, String[]> qp) { if (precisionURI == null) return Collections.emptyMap(); Map<String, String> errors = new HashMap<String, String>(); Integer year, month, day, hour, minute, second; //just check if the values for the precision parse to integers if (precisionURI.equals(VitroVocabulary.Precision.YEAR.uri())) { if (!canParseToNumber(getFieldName() + "-year", qp)) errors.put(getFieldName() + "-year", NON_INTEGER_YEAR); } else if (precisionURI.equals(VitroVocabulary.Precision.MONTH.uri())) { if (!canParseToNumber(getFieldName() + "-year", qp)) errors.put(getFieldName() + "-year", NON_INTEGER_YEAR); if (!canParseToNumber(getFieldName() + "-month", qp)) errors.put(getFieldName() + "-month", NON_INTEGER_MONTH); } else if (precisionURI.equals(VitroVocabulary.Precision.DAY.uri())) { if (!canParseToNumber(getFieldName() + "-year", qp)) errors.put(getFieldName() + "-year", NON_INTEGER_YEAR); if (!canParseToNumber(getFieldName() + "-month", qp)) errors.put(getFieldName() + "-month", NON_INTEGER_MONTH); if (!canParseToNumber(getFieldName() + "-day", qp)) errors.put(getFieldName() + "-day", NON_INTEGER_DAY); } else if (precisionURI.equals(VitroVocabulary.Precision.HOUR.uri())) { if (!canParseToNumber(getFieldName() + "-year", qp)) errors.put(getFieldName() + "-year", NON_INTEGER_YEAR); if (!canParseToNumber(getFieldName() + "-month", qp)) errors.put(getFieldName() + "-month", NON_INTEGER_MONTH); if (!canParseToNumber(getFieldName() + "-day", qp)) errors.put(getFieldName() + "-day", NON_INTEGER_DAY); if (!canParseToNumber(getFieldName() + "-hour", qp)) errors.put(getFieldName() + "-hour", NON_INTEGER_HOUR); } else if (precisionURI.equals(VitroVocabulary.Precision.MINUTE.uri())) { if (!canParseToNumber(getFieldName() + "-year", qp)) errors.put(getFieldName() + "-year", NON_INTEGER_YEAR); if (!canParseToNumber(getFieldName() + "-month", qp)) errors.put(getFieldName() + "-month", NON_INTEGER_MONTH); if (!canParseToNumber(getFieldName() + "-day", qp)) errors.put(getFieldName() + "-day", NON_INTEGER_DAY); if (!canParseToNumber(getFieldName() + "-hour", qp)) errors.put(getFieldName() + "-hour", NON_INTEGER_HOUR); if (!canParseToNumber(getFieldName() + "-minute", qp)) errors.put(getFieldName() + "-minute", NON_INTEGER_HOUR); } else if (precisionURI.equals(VitroVocabulary.Precision.SECOND.uri())) { if (!canParseToNumber(getFieldName() + "-year", qp)) errors.put(getFieldName() + "-year", NON_INTEGER_YEAR); if (!canParseToNumber(getFieldName() + "-month", qp)) errors.put(getFieldName() + "-month", NON_INTEGER_MONTH); if (!canParseToNumber(getFieldName() + "-day", qp)) errors.put(getFieldName() + "-day", NON_INTEGER_DAY); if (!canParseToNumber(getFieldName() + "-hour", qp)) errors.put(getFieldName() + "-hour", NON_INTEGER_HOUR); if (!canParseToNumber(getFieldName() + "-minute", qp)) errors.put(getFieldName() + "-minute", NON_INTEGER_HOUR); if (!canParseToNumber(getFieldName() + "-second", qp)) errors.put(getFieldName() + "-second", NON_INTEGER_SECOND); }/* ww w . ja va 2s. c o m*/ //check if we can make a valid date with these integers year = parseToInt(getFieldName() + "-year", qp); if (year == null) year = 1999; month = parseToInt(getFieldName() + "-month", qp); if (month == null) month = 1; day = parseToInt(getFieldName() + "-day", qp); if (day == null) day = 1; hour = parseToInt(getFieldName() + "-hour", qp); if (hour == null) hour = 0; minute = parseToInt(getFieldName() + "-minute", qp); if (minute == null) minute = 0; second = parseToInt(getFieldName() + "-second", qp); if (second == null) second = 0; //initialize to something so that we can be assured not to get //system date dependent behavior DateTime dateTime = new DateTime("1970-01-01T00:00:00Z"); try { dateTime = dateTime.withYear(year); } catch (IllegalArgumentException iae) { errors.put(getFieldName() + "-year", iae.getLocalizedMessage()); } try { dateTime = dateTime.withMonthOfYear(month); } catch (IllegalArgumentException iae) { errors.put(getFieldName() + "-month", iae.getLocalizedMessage()); } try { dateTime = dateTime.withDayOfMonth(day); } catch (IllegalArgumentException iae) { errors.put(getFieldName() + "-day", iae.getLocalizedMessage()); } try { dateTime = dateTime.withHourOfDay(hour); } catch (IllegalArgumentException iae) { errors.put(getFieldName() + "-hour", iae.getLocalizedMessage()); } try { dateTime = dateTime.withSecondOfMinute(second); } catch (IllegalArgumentException iae) { errors.put(getFieldName() + "-second", iae.getLocalizedMessage()); } return errors; }
From source file:it.geosolutions.geobatch.geotiff.retile.GeotiffRetiler.java
public Queue<FileSystemEvent> execute(Queue<FileSystemEvent> events) throws ActionException { try {/*from ww w . ja v a 2 s.c o m*/ if (configuration == null) { final String message = "GeotiffRetiler::execute(): flow configuration is null."; if (LOGGER.isErrorEnabled()) LOGGER.error(message); throw new ActionException(this, message); } if (events.size() == 0) { throw new ActionException(this, "GeotiffRetiler::execute(): Unable to process an empty events queue."); } if (LOGGER.isInfoEnabled()) LOGGER.info("GeotiffRetiler::execute(): Starting with processing..."); listenerForwarder.started(); // The return final Queue<FileSystemEvent> ret = new LinkedList<FileSystemEvent>(); while (events.size() > 0) { FileSystemEvent event = events.remove(); File eventFile = event.getSource(); FileSystemEventType eventType = event.getEventType(); if (eventFile.exists() && eventFile.canRead() && eventFile.canWrite()) { /* * If here: we can start retiler actions on the incoming file event */ if (eventFile.isDirectory()) { File[] fileList = eventFile.listFiles(); int size = fileList.length; for (int progress = 0; progress < size; progress++) { File inFile = fileList[progress]; final String absolutePath = inFile.getAbsolutePath(); final String inputFileName = FilenameUtils.getName(absolutePath); if (LOGGER.isInfoEnabled()) LOGGER.info("is going to retile: " + inputFileName); try { listenerForwarder.setTask("GeotiffRetiler"); File tiledTiffFile = File.createTempFile(inFile.getName(), "_tiled.tif", getTempDir()); if (tiledTiffFile.exists()) { // file already exists // check write permission if (!tiledTiffFile.canWrite()) { final String message = "Unable to over-write the temporary file called: " + tiledTiffFile.getAbsolutePath() + "\nCheck permissions."; if (LOGGER.isErrorEnabled()) { LOGGER.error(message); } throw new IllegalArgumentException(message); } } else if (!tiledTiffFile.createNewFile()) { final String message = "Unable to create temporary file called: " + tiledTiffFile.getAbsolutePath(); if (LOGGER.isErrorEnabled()) { LOGGER.error(message); } throw new IllegalArgumentException(message); } final double compressionRatio = getConfiguration().getCompressionRatio(); final String compressionType = getConfiguration().getCompressionScheme(); reTile(inFile, tiledTiffFile, compressionRatio, compressionType, getConfiguration().getTileW(), getConfiguration().getTileH(), getConfiguration().isForceToBigTiff()); String extension = FilenameUtils.getExtension(inputFileName); if (!extension.contains("tif")) { extension = "tif"; } final String outputFileName = FilenameUtils.getFullPath(absolutePath) + FilenameUtils.getBaseName(inputFileName) + "." + extension; final File outputFile = new File(outputFileName); // do we need to remove the input? FileUtils.copyFile(tiledTiffFile, outputFile); FileUtils.deleteQuietly(tiledTiffFile); // set the output /* * COMMENTED OUT 21 Feb 2011: simone: If the event represents a Dir * we have to return a Dir. Do not matter failing files. * * carlo: we may also want to check if a file is already tiled! * * File outputFile=reTile(inFile); if (outputFile!=null){ //TODO: * here we use the same event for each file in the ret.add(new * FileSystemEvent(outputFile, eventType)); } */ } catch (UnsupportedOperationException uoe) { listenerForwarder.failed(uoe); if (LOGGER.isWarnEnabled()) LOGGER.warn(uoe.getLocalizedMessage(), uoe); continue; } catch (IOException ioe) { listenerForwarder.failed(ioe); if (LOGGER.isWarnEnabled()) LOGGER.warn(ioe.getLocalizedMessage(), ioe); continue; } catch (IllegalArgumentException iae) { listenerForwarder.failed(iae); if (LOGGER.isWarnEnabled()) LOGGER.warn(iae.getLocalizedMessage(), iae); continue; } finally { listenerForwarder.setProgress((progress * 100) / ((size != 0) ? size : 1)); listenerForwarder.progressing(); } } if (LOGGER.isInfoEnabled()) LOGGER.info("SUCCESSFULLY completed work on: " + event.getSource()); // add the directory to the return ret.add(event); } else { // file is not a directory try { listenerForwarder.setTask("GeotiffRetiler"); File tiledTiffFile = File.createTempFile(eventFile.getName(), "_tiled.tif", eventFile.getParentFile()); if (tiledTiffFile.exists()) { // file already exists // check write permission if (!tiledTiffFile.canWrite()) { final String message = "Unable to over-write the temporary file called: " + tiledTiffFile.getAbsolutePath() + "\nCheck permissions."; if (LOGGER.isErrorEnabled()) { LOGGER.error(message); } throw new IllegalArgumentException(message); } } else if (!tiledTiffFile.createNewFile()) { final String message = "Unable to create temporary file called: " + tiledTiffFile.getAbsolutePath(); if (LOGGER.isErrorEnabled()) { LOGGER.error(message); } throw new IllegalArgumentException(message); } final double compressionRatio = getConfiguration().getCompressionRatio(); final String compressionType = getConfiguration().getCompressionScheme(); reTile(eventFile, tiledTiffFile, compressionRatio, compressionType, getConfiguration().getTileW(), getConfiguration().getTileH(), getConfiguration().isForceToBigTiff()); String extension = FilenameUtils.getExtension(eventFile.getName()); if (!extension.contains("tif")) { extension = "tif"; } final String outputFileName = FilenameUtils.getFullPath(eventFile.getAbsolutePath()) + FilenameUtils.getBaseName(eventFile.getName()) + "." + extension; final File outputFile = new File(outputFileName); // do we need to remove the input? FileUtils.copyFile(tiledTiffFile, outputFile); FileUtils.deleteQuietly(tiledTiffFile); if (LOGGER.isInfoEnabled()) LOGGER.info("SUCCESSFULLY completed work on: " + event.getSource()); listenerForwarder.setProgress(100); ret.add(new FileSystemEvent(outputFile, eventType)); } catch (UnsupportedOperationException uoe) { listenerForwarder.failed(uoe); if (LOGGER.isWarnEnabled()) LOGGER.warn(uoe.getLocalizedMessage(), uoe); continue; } catch (IOException ioe) { listenerForwarder.failed(ioe); if (LOGGER.isWarnEnabled()) LOGGER.warn(ioe.getLocalizedMessage(), ioe); continue; } catch (IllegalArgumentException iae) { listenerForwarder.failed(iae); if (LOGGER.isWarnEnabled()) LOGGER.warn(iae.getLocalizedMessage(), iae); continue; } finally { listenerForwarder.setProgress((100) / ((events.size() != 0) ? events.size() : 1)); listenerForwarder.progressing(); } } } else { final String message = "The passed file event refers to a not existent " + "or not readable/writeable file! File: " + eventFile.getAbsolutePath(); if (LOGGER.isWarnEnabled()) LOGGER.warn(message); final IllegalArgumentException iae = new IllegalArgumentException(message); listenerForwarder.failed(iae); } } // endwile listenerForwarder.completed(); // return if (ret.size() > 0) { events.clear(); return ret; } else { /* * If here: we got an error no file are set to be returned the input queue is * returned */ return events; } } catch (Exception t) { if (LOGGER.isErrorEnabled()) LOGGER.error(t.getLocalizedMessage(), t); final ActionException exc = new ActionException(this, t.getLocalizedMessage(), t); listenerForwarder.failed(exc); throw exc; } }
From source file:org.deegree.services.wmts.controller.WMTSController.java
@Override public void doKVP(Map<String, String> map, HttpServletRequest request, HttpResponseBuffer response, List<FileItem> multiParts) throws ServletException, IOException { RequestUtils.getCurrentThreadRequestParameters().set(map); try {//from www.j a v a 2s. c om ImplementationMetadata<?> serviceInfo = ((OWSProvider) getMetadata().getProvider()) .getImplementationMetadata(); String v = map.get("VERSION"); Version version = v == null ? serviceInfo.getSupportedConfigVersions().iterator().next() : parseVersion(v); WMTSRequestType req; try { req = (WMTSRequestType) ((ImplementationMetadata) serviceInfo) .getRequestTypeByName(map.get("REQUEST")); } catch (IllegalArgumentException e) { sendException(new OWSException("'" + map.get("REQUEST") + "' is not a supported WMTS operation.", OPERATION_NOT_SUPPORTED), response); return; } catch (NullPointerException e) { sendException(new OWSException("The REQUEST parameter is missing.", OPERATION_NOT_SUPPORTED), response); return; } try { dispatcher.handleRequest(req, response, map, version); } catch (OWSException e) { LOG.debug("The response is an exception with the message '{}'", e.getLocalizedMessage()); LOG.trace("Stack trace of OWSException being sent", e); sendException(e, response); } } finally { RequestUtils.getCurrentThreadRequestParameters().remove(); } }
From source file:com.keithandthegirl.ui.activity.EpisodesFragment.java
@Override public void onPause() { Log.v(TAG, "onPause : enter"); super.onPause(); // Unregister for broadcast if (null != episodesReceiver) { try {/* w ww. j av a2 s . c o m*/ getActivity().unregisterReceiver(episodesReceiver); episodesReceiver = null; } catch (IllegalArgumentException e) { Log.e(TAG, e.getLocalizedMessage(), e); } } if (null != downloadReceiver) { try { getActivity().unregisterReceiver(downloadReceiver); downloadReceiver = null; } catch (IllegalArgumentException e) { Log.e(TAG, e.getLocalizedMessage(), e); } } if (mBound) { getActivity().unbindService(mConnection); } Log.v(TAG, "onPause : exit"); }
From source file:org.mythtv.client.ui.dvr.EpisodeFragment.java
@Override public void onStop() { Log.v(TAG, "onStop : enter"); super.onStop(); // Unregister for broadcast if (null != recordedRemovedReceiver) { try {/*www. j ava2s .co m*/ getActivity().unregisterReceiver(recordedRemovedReceiver); } catch (IllegalArgumentException e) { Log.e(TAG, e.getLocalizedMessage(), e); } } if (null != liveStreamReceiver) { try { getActivity().unregisterReceiver(liveStreamReceiver); } catch (IllegalArgumentException e) { Log.e(TAG, e.getLocalizedMessage(), e); } } Log.v(TAG, "onStop : exit"); }
From source file:org.kalypso.ogc.gml.loader.SldLoader.java
@Override public Object load(final IPoolableObjectType key, final IProgressMonitor monitor) throws LoaderException { final String source = key.getLocation(); final URL context = key.getContext(); try {/*from w ww . j a va 2 s . c o m*/ monitor.beginTask(Messages.getString("org.kalypso.ogc.gml.loader.SldLoader.1"), 1000); //$NON-NLS-1$ if (CatalogUtilities.isCatalogResource(source)) return loadFromCatalog(context, source); /* Local url: sld and resources reside at the same location */ final URL sldLocation = m_urlResolver.resolveURL(context, source); return loadFromUrl(sldLocation, sldLocation); } catch (final IllegalArgumentException e) { // This one may happen, because the platform-URL-connector does not always throw correct MalformedURLExceptions, // but throws this one, when opening the stream... e.printStackTrace(); // REMARK: we no not pass the exception to the next level her (hence the printStackTrace) // in order to have a nicer error dialog later (avoids the same line aperaring twice in the details-panel) final LoaderException loaderException = new LoaderException(e.getLocalizedMessage()); setStatus(loaderException.getStatus()); throw loaderException; } catch (final MalformedURLException e) { e.printStackTrace(); // REMARK: we no not pass the exception to the next level her (hence the printStackTrace) // in order to have a nicer error dialog later (avoids the same line aperaring twice in the details-panel) final LoaderException loaderException = new LoaderException(e.getLocalizedMessage()); setStatus(loaderException.getStatus()); throw loaderException; } catch (final IOException e) { e.printStackTrace(); // REMARK: we no not pass the exception to the next level her (hence the printStackTrace) // in order to have a nicer error dialog later (avoids the same line aperaring twice in the details-panel) final LoaderException loaderException = new LoaderException(e.getLocalizedMessage()); setStatus(loaderException.getStatus()); throw loaderException; } catch (final XMLParsingException e) { e.printStackTrace(); // REMARK: we no not pass the exception to the next level her (hence the printStackTrace) // in order to have a nicer error dialog later (avoids the same line aperaring twice in the details-panel) final LoaderException loaderException = new LoaderException(e.getLocalizedMessage()); setStatus(loaderException.getStatus()); throw loaderException; } catch (final CoreException e) { final IStatus status = e.getStatus(); setStatus(status); if (!status.matches(IStatus.CANCEL)) e.printStackTrace(); throw new LoaderException(e.getStatus()); } finally { monitor.done(); } }
From source file:de.dmarcini.bt.homelight.HomeLightMainActivity.java
@Override protected void onPause() { super.onPause(); if (BuildConfig.DEBUG) { Log.v(TAG, "onPause()"); }/* w ww . j av a2 s .c o m*/ try { unregisterReceiver(btGattBroadcastGattUpdateReceiver); } catch (IllegalArgumentException ex) { Log.e(TAG, "Error while unregister Reciver: " + ex.getLocalizedMessage()); } }
From source file:ffx.potential.parsers.ConversionFilter.java
/** * Automatically sets atom-specific flags, particularly nouse and inactive, * and apply harmonic restraints. Intended to be called at the end of * convert() implementations.//from w w w . j a v a2 s .co m */ public void applyAtomProperties() { /** * What may be a more elegant implementation is to make convert() a * public concrete, but skeletal method, and then have convert() * call a protected abstract readFile method for each implementation. */ Atom[] molaAtoms = activeMolecularAssembly.getAtomArray(); int nmolaAtoms = molaAtoms.length; String[] nouseKeys = properties.getStringArray("nouse"); for (String nouseKey : nouseKeys) { try { int[] nouseRange = parseAtNumArg("nouse", nouseKey, nmolaAtoms); logger.log(Level.INFO, String.format(" Atoms %d-%d set to be not " + "used", nouseRange[0] + 1, nouseRange[1] + 1)); for (int i = nouseRange[0]; i <= nouseRange[1]; i++) { molaAtoms[i].setUse(false); } } catch (IllegalArgumentException ex) { logger.log(Level.INFO, ex.getLocalizedMessage()); } } String[] inactiveKeys = properties.getStringArray("inactive"); for (String inactiveKey : inactiveKeys) { try { int[] inactiveRange = parseAtNumArg("inactive", inactiveKey, nmolaAtoms); logger.log(Level.INFO, String.format(" Atoms %d-%d set to be not " + "used", inactiveRange[0] + 1, inactiveRange[1] + 1)); for (int i = inactiveRange[0]; i <= inactiveRange[1]; i++) { molaAtoms[i].setActive(false); } } catch (IllegalArgumentException ex) { logger.log(Level.INFO, ex.getLocalizedMessage()); } } coordRestraints = new ArrayList<>(); String[] cRestraintStrings = properties.getStringArray("restraint"); for (String coordRestraint : cRestraintStrings) { String[] toks = coordRestraint.split("\\s+"); double forceconst = Double.parseDouble(toks[0]); logger.info(String.format( " Adding lambda-disabled coordinate restraint " + "with force constant %10.4f", forceconst)); Set<Atom> restraintAtoms = new HashSet<>(); for (int i = 1; i < toks.length; i++) { try { int[] nouseRange = parseAtNumArg("restraint", toks[i], nmolaAtoms); logger.info(String.format(" Adding atoms %d-%d to restraint", nouseRange[0], nouseRange[1])); for (int j = nouseRange[0]; j <= nouseRange[1]; j++) { restraintAtoms.add(molaAtoms[j]); } } catch (IllegalArgumentException ex) { boolean atomFound = false; for (Atom atom : molaAtoms) { if (atom.getName().equalsIgnoreCase(toks[i])) { atomFound = true; restraintAtoms.add(atom); } } if (atomFound) { logger.info(String.format(" Added atoms with name %s to restraint", toks[i])); } else { logger.log(Level.INFO, ex.getLocalizedMessage()); } } } if (!restraintAtoms.isEmpty()) { Atom[] ats = restraintAtoms.toArray(new Atom[restraintAtoms.size()]); coordRestraints.add(new CoordRestraint(ats, forceField, false, forceconst)); } else { logger.warning(String.format(" Empty or unparseable restraint argument %s", coordRestraint)); } } String[] lamRestraintStrings = properties.getStringArray("lamrestraint"); for (String coordRestraint : lamRestraintStrings) { String[] toks = coordRestraint.split("\\s+"); double forceconst = Double.parseDouble(toks[0]); logger.info(String.format(" Adding lambda-enabled coordinate restraint " + "with force constant %10.4f", forceconst)); Set<Atom> restraintAtoms = new HashSet<>(); for (int i = 1; i < toks.length; i++) { try { int[] nouseRange = parseAtNumArg("restraint", toks[i], nmolaAtoms); logger.info(String.format(" Adding atoms %d-%d to restraint", nouseRange[0], nouseRange[1])); for (int j = nouseRange[0]; j <= nouseRange[1]; j++) { restraintAtoms.add(molaAtoms[j]); } } catch (IllegalArgumentException ex) { boolean atomFound = false; for (Atom atom : molaAtoms) { if (atom.getName().equalsIgnoreCase(toks[i])) { atomFound = true; restraintAtoms.add(atom); } } if (atomFound) { logger.info(String.format(" Added atoms with name %s to restraint", toks[i])); } else { logger.log(Level.INFO, ex.getLocalizedMessage()); } } } if (!restraintAtoms.isEmpty()) { Atom[] ats = restraintAtoms.toArray(new Atom[restraintAtoms.size()]); coordRestraints.add(new CoordRestraint(ats, forceField, true, forceconst)); } else { logger.warning(String.format(" Empty or unparseable restraint argument %s", coordRestraint)); } } String[] noElStrings = properties.getStringArray("noElectro"); for (String noE : noElStrings) { String[] toks = noE.split("\\s+"); for (String tok : toks) { try { int[] noERange = parseAtNumArg("noElectro", tok, nmolaAtoms); for (int i = noERange[0]; i <= noERange[1]; i++) { molaAtoms[i].setElectrostatics(false); } logger.log(Level.INFO, String.format(" Disabled electrostatics " + "for atoms %d-%d", noERange[0] + 1, noERange[1] + 1)); } catch (IllegalArgumentException ex) { boolean atomFound = false; for (Atom atom : molaAtoms) { if (atom.getName().equalsIgnoreCase(tok)) { atomFound = true; atom.setElectrostatics(false); } } if (atomFound) { logger.info(String.format(" Disabled electrostatics for atoms with name %s", tok)); } else { logger.log(Level.INFO, String.format(" No electrostatics " + "input %s could not be parsed as a numerical " + "range or atom type present in assembly", tok)); } } } } }
From source file:org.apache.hadoop.yarn.client.cli.RMAdminCLI.java
@Override public int run(String[] args) throws Exception { YarnConfiguration yarnConf = getConf() == null ? new YarnConfiguration() : new YarnConfiguration(getConf()); boolean isHAEnabled = yarnConf.getBoolean(YarnConfiguration.RM_HA_ENABLED, YarnConfiguration.DEFAULT_RM_HA_ENABLED); if (args.length < 1) { printUsage("", isHAEnabled); return -1; }/*from w ww. java 2 s . c om*/ int exitCode = -1; int i = 0; String cmd = args[i++]; exitCode = 0; if ("-help".equals(cmd)) { if (i < args.length) { printUsage(args[i], isHAEnabled); } else { printHelp("", isHAEnabled); } return exitCode; } if (USAGE.containsKey(cmd)) { if (isHAEnabled) { return super.run(args); } System.out.println("Cannot run " + cmd + " when ResourceManager HA is not enabled"); return -1; } // // verify that we have enough command line parameters // if ("-refreshAdminAcls".equals(cmd) || "-refreshQueues".equals(cmd) || "-refreshNodesResources".equals(cmd) || "-refreshServiceAcl".equals(cmd) || "-refreshUserToGroupsMappings".equals(cmd) || "-refreshSuperUserGroupsConfiguration".equals(cmd)) { if (args.length != 1) { printUsage(cmd, isHAEnabled); return exitCode; } } try { if ("-refreshQueues".equals(cmd)) { exitCode = refreshQueues(); } else if ("-refreshNodes".equals(cmd)) { exitCode = handleRefreshNodes(args, cmd, isHAEnabled); } else if ("-refreshNodesResources".equals(cmd)) { exitCode = refreshNodesResources(); } else if ("-refreshUserToGroupsMappings".equals(cmd)) { exitCode = refreshUserToGroupsMappings(); } else if ("-refreshSuperUserGroupsConfiguration".equals(cmd)) { exitCode = refreshSuperUserGroupsConfiguration(); } else if ("-refreshAdminAcls".equals(cmd)) { exitCode = refreshAdminAcls(); } else if ("-refreshServiceAcl".equals(cmd)) { exitCode = refreshServiceAcls(); } else if ("-refreshClusterMaxPriority".equals(cmd)) { exitCode = refreshClusterMaxPriority(); } else if ("-getGroups".equals(cmd)) { String[] usernames = Arrays.copyOfRange(args, i, args.length); exitCode = getGroups(usernames); } else if ("-updateNodeResource".equals(cmd)) { exitCode = handleUpdateNodeResource(args, cmd, isHAEnabled); } else if ("-addToClusterNodeLabels".equals(cmd)) { exitCode = handleAddToClusterNodeLabels(args, cmd, isHAEnabled); } else if ("-removeFromClusterNodeLabels".equals(cmd)) { exitCode = handleRemoveFromClusterNodeLabels(args, cmd, isHAEnabled); } else if ("-replaceLabelsOnNode".equals(cmd)) { exitCode = handleReplaceLabelsOnNodes(args, cmd, isHAEnabled); } else { exitCode = -1; System.err.println(cmd.substring(1) + ": Unknown command"); printUsage("", isHAEnabled); } } catch (IllegalArgumentException arge) { exitCode = -1; System.err.println(cmd.substring(1) + ": " + arge.getLocalizedMessage()); printUsage(cmd, isHAEnabled); } catch (RemoteException e) { // // This is a error returned by hadoop server. Print // out the first line of the error message, ignore the stack trace. exitCode = -1; try { String[] content; content = e.getLocalizedMessage().split("\n"); System.err.println(cmd.substring(1) + ": " + content[0]); } catch (Exception ex) { System.err.println(cmd.substring(1) + ": " + ex.getLocalizedMessage()); } } catch (Exception e) { exitCode = -1; System.err.println(cmd.substring(1) + ": " + e.getLocalizedMessage()); } if (null != localNodeLabelsManager) { localNodeLabelsManager.stop(); } return exitCode; }