List of usage examples for java.util EnumSet noneOf
public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType)
From source file:com.netflix.genie.web.controllers.JobRestController.java
/** * Get jobs for given filter criteria.//w w w . j a v a 2 s . c o m * * @param id id for job * @param name name of job (can be a SQL-style pattern such as HIVE%) * @param user user who submitted job * @param statuses statuses of jobs to find * @param tags tags for the job * @param clusterName the name of the cluster * @param clusterId the id of the cluster * @param commandName the name of the command run by the job * @param commandId the id of the command run by the job * @param minStarted The time which the job had to start after in order to be return (inclusive) * @param maxStarted The time which the job had to start before in order to be returned (exclusive) * @param minFinished The time which the job had to finish after in order to be return (inclusive) * @param maxFinished The time which the job had to finish before in order to be returned (exclusive) * @param page page information for job * @param assembler The paged resources assembler to use * @return successful response, or one with HTTP error code * @throws GenieException For any error */ @RequestMapping(method = RequestMethod.GET, produces = MediaTypes.HAL_JSON_VALUE) @ResponseStatus(HttpStatus.OK) public PagedResources<JobSearchResultResource> findJobs( @RequestParam(value = "id", required = false) final String id, @RequestParam(value = "name", required = false) final String name, @RequestParam(value = "user", required = false) final String user, @RequestParam(value = "status", required = false) final Set<String> statuses, @RequestParam(value = "tag", required = false) final Set<String> tags, @RequestParam(value = "clusterName", required = false) final String clusterName, @RequestParam(value = "clusterId", required = false) final String clusterId, @RequestParam(value = "commandName", required = false) final String commandName, @RequestParam(value = "commandId", required = false) final String commandId, @RequestParam(value = "minStarted", required = false) final Long minStarted, @RequestParam(value = "maxStarted", required = false) final Long maxStarted, @RequestParam(value = "minFinished", required = false) final Long minFinished, @RequestParam(value = "maxFinished", required = false) final Long maxFinished, @PageableDefault(sort = { "created" }, direction = Sort.Direction.DESC) final Pageable page, final PagedResourcesAssembler<JobSearchResult> assembler) throws GenieException { log.info("[getJobs] Called with " + "[id | jobName | user | statuses | clusterName " + "| clusterId | minStarted | maxStarted | minFinished | maxFinished | page]"); log.info("{} | {} | {} | {} | {} | {} | {} | {} | {} | {} | {} | {} | {} | {}", id, name, user, statuses, tags, clusterName, clusterId, commandName, commandId, minStarted, maxStarted, minFinished, maxFinished, page); Set<JobStatus> enumStatuses = null; if (statuses != null && !statuses.isEmpty()) { enumStatuses = EnumSet.noneOf(JobStatus.class); for (final String status : statuses) { if (StringUtils.isNotBlank(status)) { enumStatuses.add(JobStatus.parse(status)); } } } // Build the self link which will be used for the next, previous, etc links final Link self = ControllerLinkBuilder .linkTo(ControllerLinkBuilder.methodOn(JobRestController.class).findJobs(id, name, user, statuses, tags, clusterName, clusterId, commandName, commandId, minStarted, maxStarted, minFinished, maxFinished, page, assembler)) .withSelfRel(); return assembler.toResource( this.jobSearchService.findJobs(id, name, user, enumStatuses, tags, clusterName, clusterId, commandName, commandId, minStarted == null ? null : new Date(minStarted), maxStarted == null ? null : new Date(maxStarted), minFinished == null ? null : new Date(minFinished), maxFinished == null ? null : new Date(maxFinished), page), this.jobSearchResultResourceAssembler, self); }
From source file:se.trixon.mapollage.Operation.java
private boolean generateFileList() throws IOException { mListener.onOperationLog(""); mListener.onOperationLog(Dict.GENERATING_FILELIST.toString()); PathMatcher pathMatcher = mProfileSource.getPathMatcher(); EnumSet<FileVisitOption> fileVisitOptions; if (mProfileSource.isFollowLinks()) { fileVisitOptions = EnumSet.of(FileVisitOption.FOLLOW_LINKS); } else {/*w w w. ja v a 2 s . com*/ fileVisitOptions = EnumSet.noneOf(FileVisitOption.class); } File file = mProfileSource.getDir(); if (file.isDirectory()) { FileVisitor fileVisitor = new FileVisitor(pathMatcher, mFiles, file, this); try { if (mProfileSource.isRecursive()) { Files.walkFileTree(file.toPath(), fileVisitOptions, Integer.MAX_VALUE, fileVisitor); } else { Files.walkFileTree(file.toPath(), fileVisitOptions, 1, fileVisitor); } if (fileVisitor.isInterrupted()) { return false; } } catch (IOException ex) { throw new IOException(String.format("E000 %s", file.getAbsolutePath())); } } else if (file.isFile() && pathMatcher.matches(file.toPath().getFileName())) { mFiles.add(file); } if (mFiles.isEmpty()) { mListener.onOperationFinished(Dict.FILELIST_EMPTY.toString(), 0); } else { Collections.sort(mFiles); } return true; }
From source file:org.lilyproject.indexer.model.indexerconf.LilyIndexerConfBuilder.java
private void buildDynamicFields() throws Exception { List<Element> fields = DYNAMIC_INDEX_FIELDS.get().evalAsNativeElementList(doc); for (Element fieldEl : fields) { String matchNamespaceAttr = DocumentHelper.getAttribute(fieldEl, "matchNamespace", false); String matchNameAttr = DocumentHelper.getAttribute(fieldEl, "matchName", false); String matchTypeAttr = DocumentHelper.getAttribute(fieldEl, "matchType", false); String matchScopeAttr = DocumentHelper.getAttribute(fieldEl, "matchScope", false); String nameAttr = DocumentHelper.getAttribute(fieldEl, "name", true); WildcardPattern matchNamespace = null; if (matchNamespaceAttr != null) { // If the matchNamespace attr does not contain a wildcard expression, and its value // happens to be an existing namespace prefix, than substitute the prefix for the full URI. if (!WildcardPattern.isWildcardExpression(matchNamespaceAttr)) { String uri = fieldEl.lookupNamespaceURI(matchNamespaceAttr); if (uri != null) { matchNamespaceAttr = uri; }/*from ww w.j ava2 s.c o m*/ } matchNamespace = new WildcardPattern(matchNamespaceAttr); } WildcardPattern matchName = null; if (matchNameAttr != null) { matchName = new WildcardPattern(matchNameAttr); } TypePattern matchTypes = null; if (matchTypeAttr != null) { matchTypes = new TypePattern(matchTypeAttr); } Set<Scope> matchScopes = null; if (matchScopeAttr != null) { matchScopes = EnumSet.noneOf(Scope.class); for (String scope : COMMA_SPLITTER.split(matchScopeAttr)) { matchScopes.add(Scope.valueOf(scope)); } if (matchScopes.isEmpty()) { matchScopes = null; } } // Be gentle to users of Lily 1.0 and warn them about attributes that are not supported anymore if (DocumentHelper.getAttribute(fieldEl, "matchMultiValue", false) != null) { log.warn( "The attribute matchMultiValue on dynamicField is not supported anymore, it will be ignored."); } if (DocumentHelper.getAttribute(fieldEl, "matchHierarchical", false) != null) { log.warn( "The attribute matchHierarchical on dynamicField is not supported anymore, it will be ignored."); } Set<String> variables = new HashSet<String>(); variables.add("namespace"); variables.add("name"); variables.add("type"); variables.add("baseType"); variables.add("nestedType"); variables.add("nestedBaseType"); variables.add("deepestNestedBaseType"); if (matchName != null && matchName.hasWildcard()) { variables.add("nameMatch"); } if (matchNamespace != null && matchNamespace.hasWildcard()) { variables.add("namespaceMatch"); } NameTemplate name; try { name = new NameTemplateParser().parse(fieldEl, nameAttr, new DynamicFieldNameTemplateValidator(variables)); } catch (NameTemplateException nte) { throw new IndexerConfException("Error in name template: " + nameAttr + " at " + LocationAttributes.getLocationString(fieldEl), nte); } boolean extractContent = DocumentHelper.getBooleanAttribute(fieldEl, "extractContent", false); String formatter = DocumentHelper.getAttribute(fieldEl, "formatter", false); if (formatter != null && !conf.getFormatters().hasFormatter(formatter)) { throw new IndexerConfException("Formatter does not exist: " + formatter + " at " + LocationAttributes.getLocationString(fieldEl)); } boolean continue_ = DocumentHelper.getBooleanAttribute(fieldEl, "continue", false); DynamicIndexField field = new DynamicIndexField(matchNamespace, matchName, matchTypes, matchScopes, name, extractContent, continue_, formatter); conf.addDynamicIndexField(field); } }
From source file:org.opencb.opencga.catalog.auth.authorization.CatalogAuthorizationManager.java
private IndividualAclEntry resolveIndividualPermissions(long studyId, String userId, String groupId, Map<String, IndividualAclEntry> userAclMap) throws CatalogException { if (userId.equals(ANONYMOUS)) { if (userAclMap.containsKey(userId)) { return userAclMap.get(userId); } else {//from w w w.ja v a2 s . co m return transformStudyAclToIndividualAcl(getStudyAclBelonging(studyId, userId, groupId)); } } // Registered user EnumSet<IndividualAclEntry.IndividualPermissions> permissions = EnumSet .noneOf(IndividualAclEntry.IndividualPermissions.class); boolean flagPermissionFound = false; if (userAclMap.containsKey(userId)) { permissions.addAll(userAclMap.get(userId).getPermissions()); flagPermissionFound = true; } if (StringUtils.isNotEmpty(groupId) && userAclMap.containsKey(groupId)) { permissions.addAll(userAclMap.get(groupId).getPermissions()); flagPermissionFound = true; } if (userAclMap.containsKey(ANONYMOUS)) { permissions.addAll(userAclMap.get(ANONYMOUS).getPermissions()); flagPermissionFound = true; } if (userAclMap.containsKey(OTHER_USERS_ID)) { permissions.addAll(userAclMap.get(OTHER_USERS_ID).getPermissions()); flagPermissionFound = true; } if (flagPermissionFound) { return new IndividualAclEntry(userId, permissions); } else { return transformStudyAclToIndividualAcl(getStudyAclBelonging(studyId, userId, groupId)); } }
From source file:org.dcm4che3.tool.dcmqrscp.DcmQRSCP.java
private static void configureTransferCapability(DcmQRSCP<InstanceLocator> main, CommandLine cl) throws IOException { ApplicationEntity ae = main.ae;/*w ww .j av a 2s . com*/ EnumSet<QueryOption> queryOptions = cl.hasOption("relational") ? EnumSet.of(QueryOption.RELATIONAL) : EnumSet.noneOf(QueryOption.class); boolean storage = !cl.hasOption("no-storage") && main.isWriteable(); if (storage && cl.hasOption("all-storage")) { TransferCapability tc = new TransferCapability(null, "*", TransferCapability.Role.SCP, "*"); tc.setQueryOptions(queryOptions); ae.addTransferCapability(tc); } else { ae.addTransferCapability(new TransferCapability(null, UID.VerificationSOPClass, TransferCapability.Role.SCP, UID.ImplicitVRLittleEndian)); Properties storageSOPClasses = CLIUtils.loadProperties( cl.getOptionValue("storage-sop-classes", "resource:storage-sop-classes.properties"), null); if (storage) addTransferCapabilities(ae, storageSOPClasses, TransferCapability.Role.SCP, null); if (!cl.hasOption("no-retrieve")) { addTransferCapabilities(ae, storageSOPClasses, TransferCapability.Role.SCU, null); Properties p = CLIUtils.loadProperties( cl.getOptionValue("retrieve-sop-classes", "resource:retrieve-sop-classes.properties"), null); addTransferCapabilities(ae, p, TransferCapability.Role.SCP, queryOptions); } if (!cl.hasOption("no-query")) { Properties p = CLIUtils.loadProperties( cl.getOptionValue("query-sop-classes", "resource:query-sop-classes.properties"), null); addTransferCapabilities(ae, p, TransferCapability.Role.SCP, queryOptions); } } if (storage) main.openDicomDir(); else main.openDicomDirForReadOnly(); }
From source file:sx.blah.discord.handle.impl.obj.Guild.java
@Override @Deprecated/*from ww w. j av a 2s .c o m*/ public void deleteGuild() { if (ownerID != client.getOurUser().getLongID()) throw new MissingPermissionsException("You must be the guild owner to delete guilds!", EnumSet.noneOf(Permissions.class)); ((DiscordClientImpl) client).REQUESTS.DELETE.makeRequest(DiscordEndpoints.GUILDS + getStringID()); }
From source file:org.apache.hadoop.yarn.client.api.impl.TestYarnClient.java
@Test(timeout = 10000) public void testGetApplications() throws YarnException, IOException { Configuration conf = new Configuration(); final YarnClient client = new MockYarnClient(); client.init(conf);/*w w w .ja v a2 s .c om*/ client.start(); List<ApplicationReport> expectedReports = ((MockYarnClient) client).getReports(); List<ApplicationReport> reports = client.getApplications(); Assert.assertEquals(reports, expectedReports); Set<String> appTypes = new HashSet<String>(); appTypes.add("YARN"); appTypes.add("NON-YARN"); reports = client.getApplications(appTypes, null); Assert.assertEquals(reports.size(), 2); Assert.assertTrue((reports.get(0).getApplicationType().equals("YARN") && reports.get(1).getApplicationType().equals("NON-YARN")) || (reports.get(1).getApplicationType().equals("YARN") && reports.get(0).getApplicationType().equals("NON-YARN"))); for (ApplicationReport report : reports) { Assert.assertTrue(expectedReports.contains(report)); } EnumSet<YarnApplicationState> appStates = EnumSet.noneOf(YarnApplicationState.class); appStates.add(YarnApplicationState.FINISHED); appStates.add(YarnApplicationState.FAILED); reports = client.getApplications(null, appStates); Assert.assertEquals(reports.size(), 2); Assert.assertTrue((reports.get(0).getApplicationType().equals("NON-YARN") && reports.get(1).getApplicationType().equals("NON-MAPREDUCE")) || (reports.get(1).getApplicationType().equals("NON-YARN") && reports.get(0).getApplicationType().equals("NON-MAPREDUCE"))); for (ApplicationReport report : reports) { Assert.assertTrue(expectedReports.contains(report)); } reports = client.getApplications(appTypes, appStates); Assert.assertEquals(reports.size(), 1); Assert.assertTrue((reports.get(0).getApplicationType().equals("NON-YARN"))); for (ApplicationReport report : reports) { Assert.assertTrue(expectedReports.contains(report)); } client.stop(); }
From source file:org.apache.hadoop.hdfs.DFSOutputStream.java
/** * Flushes out to all replicas of the block. The data is in the buffers * of the DNs but not necessarily in the DN's OS buffers. * * It is a synchronous operation. When it returns, * it guarantees that flushed data become visible to new readers. * It is not guaranteed that data has been flushed to * persistent store on the datanode. /*from www. ja va2 s. c o m*/ * Block allocations are persisted on namenode. */ @Override public void hflush() throws IOException { TraceScope scope = dfsClient.newPathTraceScope("hflush", src); try { flushOrSync(false, EnumSet.noneOf(SyncFlag.class)); } finally { scope.close(); } }
From source file:org.apache.hadoop.yarn.client.cli.TestYarnCLI.java
@Test public void testGetApplications() throws Exception { ApplicationCLI cli = createAndGetAppCLI(); ApplicationId applicationId = ApplicationId.newInstance(1234, 5); ApplicationReport newApplicationReport = ApplicationReport.newInstance(applicationId, ApplicationAttemptId.newInstance(applicationId, 1), "user", "queue", "appname", "host", 124, null, YarnApplicationState.RUNNING, "diagnostics", "url", 0, 0, FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.53789f, "YARN", null); List<ApplicationReport> applicationReports = new ArrayList<ApplicationReport>(); applicationReports.add(newApplicationReport); ApplicationId applicationId2 = ApplicationId.newInstance(1234, 6); ApplicationReport newApplicationReport2 = ApplicationReport.newInstance(applicationId2, ApplicationAttemptId.newInstance(applicationId2, 2), "user2", "queue2", "appname2", "host2", 125, null, YarnApplicationState.FINISHED, "diagnostics2", "url2", 2, 2, FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.63789f, "NON-YARN", null); applicationReports.add(newApplicationReport2); ApplicationId applicationId3 = ApplicationId.newInstance(1234, 7); ApplicationReport newApplicationReport3 = ApplicationReport.newInstance(applicationId3, ApplicationAttemptId.newInstance(applicationId3, 3), "user3", "queue3", "appname3", "host3", 126, null, YarnApplicationState.RUNNING, "diagnostics3", "url3", 3, 3, FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.73789f, "MAPREDUCE", null); applicationReports.add(newApplicationReport3); ApplicationId applicationId4 = ApplicationId.newInstance(1234, 8); ApplicationReport newApplicationReport4 = ApplicationReport.newInstance(applicationId4, ApplicationAttemptId.newInstance(applicationId4, 4), "user4", "queue4", "appname4", "host4", 127, null, YarnApplicationState.FAILED, "diagnostics4", "url4", 4, 4, FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.83789f, "NON-MAPREDUCE", null); applicationReports.add(newApplicationReport4); ApplicationId applicationId5 = ApplicationId.newInstance(1234, 9); ApplicationReport newApplicationReport5 = ApplicationReport.newInstance(applicationId5, ApplicationAttemptId.newInstance(applicationId5, 5), "user5", "queue5", "appname5", "host5", 128, null, YarnApplicationState.ACCEPTED, "diagnostics5", "url5", 5, 5, FinalApplicationStatus.KILLED, null, "N/A", 0.93789f, "HIVE", null); applicationReports.add(newApplicationReport5); ApplicationId applicationId6 = ApplicationId.newInstance(1234, 10); ApplicationReport newApplicationReport6 = ApplicationReport.newInstance(applicationId6, ApplicationAttemptId.newInstance(applicationId6, 6), "user6", "queue6", "appname6", "host6", 129, null, YarnApplicationState.SUBMITTED, "diagnostics6", "url6", 6, 6, FinalApplicationStatus.KILLED, null, "N/A", 0.99789f, "PIG", null); applicationReports.add(newApplicationReport6); // Test command yarn application -list // if the set appStates is empty, RUNNING state will be automatically added // to the appStates list // the output of yarn application -list should be the same as // equals to yarn application -list --appStates RUNNING,ACCEPTED,SUBMITTED Set<String> appType1 = new HashSet<String>(); EnumSet<YarnApplicationState> appState1 = EnumSet.noneOf(YarnApplicationState.class); appState1.add(YarnApplicationState.RUNNING); appState1.add(YarnApplicationState.ACCEPTED); appState1.add(YarnApplicationState.SUBMITTED); when(client.getApplications(appType1, appState1)) .thenReturn(getApplicationReports(applicationReports, appType1, appState1, false)); int result = cli.run(new String[] { "application", "-list" }); assertEquals(0, result);/*from www . j av a 2 s .c om*/ verify(client).getApplications(appType1, appState1); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintWriter pw = new PrintWriter(baos); pw.println("Total number of applications (application-types: " + appType1 + " and states: " + appState1 + ")" + ":" + 4); pw.print(" Application-Id\t Application-Name"); pw.print("\t Application-Type"); pw.print("\t User\t Queue\t State\t "); pw.print("Final-State\t Progress"); pw.println("\t Tracking-URL"); pw.print(" application_1234_0005\t "); pw.print("appname\t YARN\t user\t "); pw.print("queue\t RUNNING\t "); pw.print("SUCCEEDED\t 53.79%"); pw.println("\t N/A"); pw.print(" application_1234_0007\t "); pw.print("appname3\t MAPREDUCE\t user3\t "); pw.print("queue3\t RUNNING\t "); pw.print("SUCCEEDED\t 73.79%"); pw.println("\t N/A"); pw.print(" application_1234_0009\t "); pw.print("appname5\t HIVE\t user5\t "); pw.print("queue5\t ACCEPTED\t "); pw.print("KILLED\t 93.79%"); pw.println("\t N/A"); pw.print(" application_1234_0010\t "); pw.print("appname6\t PIG\t user6\t "); pw.print("queue6\t SUBMITTED\t "); pw.print("KILLED\t 99.79%"); pw.println("\t N/A"); pw.close(); String appsReportStr = baos.toString("UTF-8"); Assert.assertEquals(appsReportStr, sysOutStream.toString()); verify(sysOut, times(1)).write(any(byte[].class), anyInt(), anyInt()); //Test command yarn application -list --appTypes apptype1,apptype2 //the output should be the same as // yarn application -list --appTypes apptyp1, apptype2 --appStates // RUNNING,ACCEPTED,SUBMITTED sysOutStream.reset(); Set<String> appType2 = new HashSet<String>(); appType2.add("YARN"); appType2.add("NON-YARN"); EnumSet<YarnApplicationState> appState2 = EnumSet.noneOf(YarnApplicationState.class); appState2.add(YarnApplicationState.RUNNING); appState2.add(YarnApplicationState.ACCEPTED); appState2.add(YarnApplicationState.SUBMITTED); when(client.getApplications(appType2, appState2)) .thenReturn(getApplicationReports(applicationReports, appType2, appState2, false)); result = cli.run(new String[] { "application", "-list", "-appTypes", "YARN, ,, NON-YARN", " ,, ,," }); assertEquals(0, result); verify(client).getApplications(appType2, appState2); baos = new ByteArrayOutputStream(); pw = new PrintWriter(baos); pw.println("Total number of applications (application-types: " + appType2 + " and states: " + appState2 + ")" + ":" + 1); pw.print(" Application-Id\t Application-Name"); pw.print("\t Application-Type"); pw.print("\t User\t Queue\t State\t "); pw.print("Final-State\t Progress"); pw.println("\t Tracking-URL"); pw.print(" application_1234_0005\t "); pw.print("appname\t YARN\t user\t "); pw.print("queue\t RUNNING\t "); pw.print("SUCCEEDED\t 53.79%"); pw.println("\t N/A"); pw.close(); appsReportStr = baos.toString("UTF-8"); Assert.assertEquals(appsReportStr, sysOutStream.toString()); verify(sysOut, times(2)).write(any(byte[].class), anyInt(), anyInt()); //Test command yarn application -list --appStates appState1,appState2 sysOutStream.reset(); Set<String> appType3 = new HashSet<String>(); EnumSet<YarnApplicationState> appState3 = EnumSet.noneOf(YarnApplicationState.class); appState3.add(YarnApplicationState.FINISHED); appState3.add(YarnApplicationState.FAILED); when(client.getApplications(appType3, appState3)) .thenReturn(getApplicationReports(applicationReports, appType3, appState3, false)); result = cli .run(new String[] { "application", "-list", "--appStates", "FINISHED ,, , FAILED", ",,FINISHED" }); assertEquals(0, result); verify(client).getApplications(appType3, appState3); baos = new ByteArrayOutputStream(); pw = new PrintWriter(baos); pw.println("Total number of applications (application-types: " + appType3 + " and states: " + appState3 + ")" + ":" + 2); pw.print(" Application-Id\t Application-Name"); pw.print("\t Application-Type"); pw.print("\t User\t Queue\t State\t "); pw.print("Final-State\t Progress"); pw.println("\t Tracking-URL"); pw.print(" application_1234_0006\t "); pw.print("appname2\t NON-YARN\t user2\t "); pw.print("queue2\t FINISHED\t "); pw.print("SUCCEEDED\t 63.79%"); pw.println("\t N/A"); pw.print(" application_1234_0008\t "); pw.print("appname4\t NON-MAPREDUCE\t user4\t "); pw.print("queue4\t FAILED\t "); pw.print("SUCCEEDED\t 83.79%"); pw.println("\t N/A"); pw.close(); appsReportStr = baos.toString("UTF-8"); Assert.assertEquals(appsReportStr, sysOutStream.toString()); verify(sysOut, times(3)).write(any(byte[].class), anyInt(), anyInt()); // Test command yarn application -list --appTypes apptype1,apptype2 // --appStates appstate1,appstate2 sysOutStream.reset(); Set<String> appType4 = new HashSet<String>(); appType4.add("YARN"); appType4.add("NON-YARN"); EnumSet<YarnApplicationState> appState4 = EnumSet.noneOf(YarnApplicationState.class); appState4.add(YarnApplicationState.FINISHED); appState4.add(YarnApplicationState.FAILED); when(client.getApplications(appType4, appState4)) .thenReturn(getApplicationReports(applicationReports, appType4, appState4, false)); result = cli.run(new String[] { "application", "-list", "--appTypes", "YARN,NON-YARN", "--appStates", "FINISHED ,, , FAILED" }); assertEquals(0, result); verify(client).getApplications(appType2, appState2); baos = new ByteArrayOutputStream(); pw = new PrintWriter(baos); pw.println("Total number of applications (application-types: " + appType4 + " and states: " + appState4 + ")" + ":" + 1); pw.print(" Application-Id\t Application-Name"); pw.print("\t Application-Type"); pw.print("\t User\t Queue\t State\t "); pw.print("Final-State\t Progress"); pw.println("\t Tracking-URL"); pw.print(" application_1234_0006\t "); pw.print("appname2\t NON-YARN\t user2\t "); pw.print("queue2\t FINISHED\t "); pw.print("SUCCEEDED\t 63.79%"); pw.println("\t N/A"); pw.close(); appsReportStr = baos.toString("UTF-8"); Assert.assertEquals(appsReportStr, sysOutStream.toString()); verify(sysOut, times(4)).write(any(byte[].class), anyInt(), anyInt()); //Test command yarn application -list --appStates with invalid appStates sysOutStream.reset(); result = cli.run(new String[] { "application", "-list", "--appStates", "FINISHED ,, , INVALID" }); assertEquals(-1, result); baos = new ByteArrayOutputStream(); pw = new PrintWriter(baos); pw.println("The application state INVALID is invalid."); pw.print("The valid application state can be one of the following: "); StringBuilder sb = new StringBuilder(); sb.append("ALL,"); for (YarnApplicationState state : YarnApplicationState.values()) { sb.append(state + ","); } String output = sb.toString(); pw.println(output.substring(0, output.length() - 1)); pw.close(); appsReportStr = baos.toString("UTF-8"); Assert.assertEquals(appsReportStr, sysOutStream.toString()); verify(sysOut, times(4)).write(any(byte[].class), anyInt(), anyInt()); //Test command yarn application -list --appStates all sysOutStream.reset(); Set<String> appType5 = new HashSet<String>(); EnumSet<YarnApplicationState> appState5 = EnumSet.noneOf(YarnApplicationState.class); appState5.add(YarnApplicationState.FINISHED); when(client.getApplications(appType5, appState5)) .thenReturn(getApplicationReports(applicationReports, appType5, appState5, true)); result = cli.run(new String[] { "application", "-list", "--appStates", "FINISHED ,, , ALL" }); assertEquals(0, result); verify(client).getApplications(appType5, appState5); baos = new ByteArrayOutputStream(); pw = new PrintWriter(baos); pw.println("Total number of applications (application-types: " + appType5 + " and states: " + appState5 + ")" + ":" + 6); pw.print(" Application-Id\t Application-Name"); pw.print("\t Application-Type"); pw.print("\t User\t Queue\t State\t "); pw.print("Final-State\t Progress"); pw.println("\t Tracking-URL"); pw.print(" application_1234_0005\t "); pw.print("appname\t YARN\t user\t "); pw.print("queue\t RUNNING\t "); pw.print("SUCCEEDED\t 53.79%"); pw.println("\t N/A"); pw.print(" application_1234_0006\t "); pw.print("appname2\t NON-YARN\t user2\t "); pw.print("queue2\t FINISHED\t "); pw.print("SUCCEEDED\t 63.79%"); pw.println("\t N/A"); pw.print(" application_1234_0007\t "); pw.print("appname3\t MAPREDUCE\t user3\t "); pw.print("queue3\t RUNNING\t "); pw.print("SUCCEEDED\t 73.79%"); pw.println("\t N/A"); pw.print(" application_1234_0008\t "); pw.print("appname4\t NON-MAPREDUCE\t user4\t "); pw.print("queue4\t FAILED\t "); pw.print("SUCCEEDED\t 83.79%"); pw.println("\t N/A"); pw.print(" application_1234_0009\t "); pw.print("appname5\t HIVE\t user5\t "); pw.print("queue5\t ACCEPTED\t "); pw.print("KILLED\t 93.79%"); pw.println("\t N/A"); pw.print(" application_1234_0010\t "); pw.print("appname6\t PIG\t user6\t "); pw.print("queue6\t SUBMITTED\t "); pw.print("KILLED\t 99.79%"); pw.println("\t N/A"); pw.close(); appsReportStr = baos.toString("UTF-8"); Assert.assertEquals(appsReportStr, sysOutStream.toString()); verify(sysOut, times(5)).write(any(byte[].class), anyInt(), anyInt()); // Test command yarn application user case insensitive sysOutStream.reset(); Set<String> appType6 = new HashSet<String>(); appType6.add("YARN"); appType6.add("NON-YARN"); EnumSet<YarnApplicationState> appState6 = EnumSet.noneOf(YarnApplicationState.class); appState6.add(YarnApplicationState.FINISHED); when(client.getApplications(appType6, appState6)) .thenReturn(getApplicationReports(applicationReports, appType6, appState6, false)); result = cli.run(new String[] { "application", "-list", "-appTypes", "YARN, ,, NON-YARN", "--appStates", "finished" }); assertEquals(0, result); verify(client).getApplications(appType6, appState6); baos = new ByteArrayOutputStream(); pw = new PrintWriter(baos); pw.println("Total number of applications (application-types: " + appType6 + " and states: " + appState6 + ")" + ":" + 1); pw.print(" Application-Id\t Application-Name"); pw.print("\t Application-Type"); pw.print("\t User\t Queue\t State\t "); pw.print("Final-State\t Progress"); pw.println("\t Tracking-URL"); pw.print(" application_1234_0006\t "); pw.print("appname2\t NON-YARN\t user2\t "); pw.print("queue2\t FINISHED\t "); pw.print("SUCCEEDED\t 63.79%"); pw.println("\t N/A"); pw.close(); appsReportStr = baos.toString("UTF-8"); Assert.assertEquals(appsReportStr, sysOutStream.toString()); verify(sysOut, times(6)).write(any(byte[].class), anyInt(), anyInt()); }