use of io.cdap.cdap.cli.util.RowMaker in project cdap by caskdata.
the class ListArtifactVersionsCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
String scopeStr = arguments.getOptional(ArgumentName.SCOPE.toString());
String artifactName = arguments.get(ArgumentName.ARTIFACT_NAME.toString());
List<ArtifactSummary> artifactSummaries;
if (scopeStr == null) {
artifactSummaries = artifactClient.listVersions(cliConfig.getCurrentNamespace(), artifactName);
} else {
ArtifactScope scope = ArtifactScope.valueOf(scopeStr.toUpperCase());
artifactSummaries = artifactClient.listVersions(cliConfig.getCurrentNamespace(), artifactName, scope);
}
Table table = Table.builder().setHeader("name", "version", "scope").setRows(artifactSummaries, new RowMaker<ArtifactSummary>() {
@Override
public List<?> makeRow(ArtifactSummary object) {
return Lists.newArrayList(object.getName(), object.getVersion(), object.getScope().name());
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of io.cdap.cdap.cli.util.RowMaker in project cdap by caskdata.
the class ListArtifactsCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
List<ArtifactSummary> artifactSummaries;
String artifactScope = arguments.getOptional(ArgumentName.SCOPE.toString());
if (artifactScope == null) {
artifactSummaries = artifactClient.list(cliConfig.getCurrentNamespace());
} else {
artifactSummaries = artifactClient.list(cliConfig.getCurrentNamespace(), ArtifactScope.valueOf(artifactScope.toUpperCase()));
}
Table table = Table.builder().setHeader("name", "version", "scope").setRows(artifactSummaries, new RowMaker<ArtifactSummary>() {
@Override
public List<?> makeRow(ArtifactSummary object) {
return Lists.newArrayList(object.getName(), object.getVersion(), object.getScope().name());
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of io.cdap.cdap.cli.util.RowMaker in project cdap by caskdata.
the class ListWorkflowSchedulesCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
String[] programIdParts = arguments.get(ElementType.WORKFLOW.getArgumentName().toString()).split("\\.");
if (programIdParts.length < 2) {
throw new CommandInputError(this);
}
final String appId = programIdParts[0];
String workflowName = programIdParts[1];
WorkflowId workflowId = cliConfig.getCurrentNamespace().app(appId).workflow(workflowName);
List<ScheduleDetail> list = scheduleClient.listSchedules(workflowId);
Table table = Table.builder().setHeader("application", "program", "program type", "name", "description", "trigger", "timeoutMillis", "properties").setRows(list, new RowMaker<ScheduleDetail>() {
@Override
public List<?> makeRow(ScheduleDetail object) {
return Lists.newArrayList(appId, object.getProgram().getProgramName(), object.getProgram().getProgramType().name(), object.getName(), object.getDescription(), object.getTrigger(), object.getTimeoutMillis(), GSON.toJson(object.getProperties()));
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of io.cdap.cdap.cli.util.RowMaker in project cdap by caskdata.
the class ListRolesCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
String principalType = arguments.getOptional(ArgumentName.PRINCIPAL_TYPE.toString());
String principalName = arguments.getOptional(ArgumentName.PRINCIPAL_NAME.toString());
Set<Role> roles;
if (!(Strings.isNullOrEmpty(principalType) && Strings.isNullOrEmpty(principalName))) {
roles = client.listRoles(new Principal(principalName, Principal.PrincipalType.valueOf(principalType.toUpperCase())));
} else {
roles = client.listAllRoles();
}
Table table = Table.builder().setHeader("Role").setRows(Lists.newArrayList(roles), new RowMaker<Role>() {
@Override
public List<?> makeRow(Role role) {
return Lists.newArrayList(role.getName());
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of io.cdap.cdap.cli.util.RowMaker in project cdap by caskdata.
the class CLITestBase method testNamespacesOutput.
private void testNamespacesOutput(String command, final List<NamespaceMeta> expected) throws Exception {
CLIMain cliMain = getCliMain();
CLIConfig cliConfig = getCliConfig();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream output = new PrintStream(outputStream);
Table table = Table.builder().setHeader("name", "description", "config").setRows(expected, new RowMaker<NamespaceMeta>() {
@Override
public List<?> makeRow(NamespaceMeta object) {
return Lists.newArrayList(object.getName(), object.getDescription(), NamespaceCommandUtils.prettyPrintNamespaceConfigCLI(object.getConfig()));
}
}).build();
cliMain.getTableRenderer().render(cliConfig, output, table);
final String expectedOutput = outputStream.toString();
testCommand(command, new Function<String, Void>() {
@Nullable
@Override
public Void apply(@Nullable String output) {
Assert.assertNotNull(output);
Assert.assertEquals(expectedOutput, output);
return null;
}
});
}
Aggregations