Repository: falcon Updated Branches: refs/heads/master 075f02c51 -> da767c2f6
http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/shell/src/main/java/org/apache/falcon/shell/commands/FalconEntityCommands.java ---------------------------------------------------------------------- diff --git a/shell/src/main/java/org/apache/falcon/shell/commands/FalconEntityCommands.java b/shell/src/main/java/org/apache/falcon/shell/commands/FalconEntityCommands.java new file mode 100644 index 0000000..35a6f2a --- /dev/null +++ b/shell/src/main/java/org/apache/falcon/shell/commands/FalconEntityCommands.java @@ -0,0 +1,330 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.falcon.shell.commands; + +import org.apache.falcon.ValidationUtil; +import org.apache.falcon.ResponseHelper; +import org.apache.falcon.entity.v0.EntityType; +import org.apache.falcon.resource.EntityList; +import org.apache.falcon.resource.FeedLookupResult; +import org.apache.falcon.resource.SchedulableEntityInstanceResult; +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; +import org.springframework.stereotype.Component; + +import java.io.File; + +import static org.apache.falcon.client.FalconCLIConstants.DEFINITION_OPT; +import static org.apache.falcon.client.FalconCLIConstants.DELETE_OPT; +import static org.apache.falcon.client.FalconCLIConstants.LOOKUP_OPT; +import static org.apache.falcon.client.FalconCLIConstants.SLA_MISS_ALERT_OPT; +import static org.apache.falcon.client.FalconCLIConstants.SUBMIT_ONLY_OPT; +import static org.apache.falcon.client.FalconCLIConstants.UPDATE_OPT; +import static org.apache.falcon.client.FalconCLIConstants.CLUSTER_OPT; +import static org.apache.falcon.client.FalconCLIConstants.CLUSTER_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.COLO_OPT; +import static org.apache.falcon.client.FalconCLIConstants.COLO_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.DEFINITION_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.DELETE_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.DEPENDENCY_OPT; +import static org.apache.falcon.client.FalconCLIConstants.DEPENDENCY_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.END_OPT; +import static org.apache.falcon.client.FalconCLIConstants.END_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.ENTITY_NAME_OPT; +import static org.apache.falcon.client.FalconCLIConstants.ENTITY_NAME_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.FIELDS_OPT; +import static org.apache.falcon.client.FalconCLIConstants.FIELDS_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.FILE_PATH_OPT; +import static org.apache.falcon.client.FalconCLIConstants.FILE_PATH_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.FILTER_BY_OPT; +import static org.apache.falcon.client.FalconCLIConstants.FILTER_BY_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.LIST_OPT; +import static org.apache.falcon.client.FalconCLIConstants.LIST_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.LOOKUP_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.NAMESEQ_OPT; +import static org.apache.falcon.client.FalconCLIConstants.NAMESEQ_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.NUM_INSTANCES_OPT; +import static org.apache.falcon.client.FalconCLIConstants.NUM_INSTANCES_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.NUM_RESULTS_OPT; +import static org.apache.falcon.client.FalconCLIConstants.NUM_RESULTS_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.OFFSET_OPT; +import static org.apache.falcon.client.FalconCLIConstants.OFFSET_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.ORDER_BY_OPT; +import static org.apache.falcon.client.FalconCLIConstants.ORDER_BY_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.PATH_OPT; +import static org.apache.falcon.client.FalconCLIConstants.PATH_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.PROPS_OPT; +import static org.apache.falcon.client.FalconCLIConstants.PROPS_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.RESUME_OPT; +import static org.apache.falcon.client.FalconCLIConstants.RESUME_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.SCHEDULE_OPT; +import static org.apache.falcon.client.FalconCLIConstants.SCHEDULE_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.SHOWSCHEDULER_OPT; +import static org.apache.falcon.client.FalconCLIConstants.SHOWSCHEDULER_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.SKIPDRYRUN_OPT; +import static org.apache.falcon.client.FalconCLIConstants.SKIPDRYRUN_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.SLA_MISS_ALERT_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.SORT_ORDER_OPT; +import static org.apache.falcon.client.FalconCLIConstants.SORT_ORDER_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.START_OPT; +import static org.apache.falcon.client.FalconCLIConstants.START_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.STATUS_OPT; +import static org.apache.falcon.client.FalconCLIConstants.STATUS_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.SUBMIT_AND_SCHEDULE_OPT; +import static org.apache.falcon.client.FalconCLIConstants.SUBMIT_AND_SCHEDULE_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.SUBMIT_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.SUMMARY_OPT; +import static org.apache.falcon.client.FalconCLIConstants.SUMMARY_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.SUSPEND_OPT; +import static org.apache.falcon.client.FalconCLIConstants.SUSPEND_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.TAGKEYS_OPT; +import static org.apache.falcon.client.FalconCLIConstants.TAGKEYS_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.TAGS_OPT; +import static org.apache.falcon.client.FalconCLIConstants.TAGS_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.TYPE_OPT; +import static org.apache.falcon.client.FalconCLIConstants.TYPE_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.UPDATE_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.VALIDATE_OPT; +import static org.apache.falcon.client.FalconCLIConstants.VALIDATE_OPT_DESCRIPTION; + +/** + * Entity Commands. + */ +@Component +public class FalconEntityCommands extends BaseFalconCommands { + public static final String ENTITY_PREFIX = "entity"; + public static final String ENTITY_COMMAND_PREFIX = ENTITY_PREFIX + " "; + + @CliCommand(value = ENTITY_COMMAND_PREFIX + SLA_MISS_ALERT_OPT, help = SLA_MISS_ALERT_OPT_DESCRIPTION) + public String slaAlert( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {ENTITY_NAME_OPT}, mandatory = false, help = ENTITY_NAME_OPT_DESCRIPTION) + final String entityName, + @CliOption(key = {COLO_OPT}, mandatory = false, help = COLO_OPT_DESCRIPTION, + unspecifiedDefaultValue = "*") final String colo, + @CliOption(key = {START_OPT}, mandatory = true, help = START_OPT_DESCRIPTION) final String start, + @CliOption(key = {END_OPT}, mandatory = false, help = END_OPT_DESCRIPTION) final String end + ) { + SchedulableEntityInstanceResult response = getFalconClient() + .getFeedSlaMissPendingAlerts(entityType.name().toLowerCase(), entityName, start, end, getColo(colo)); + return ResponseHelper.getString(response); + } + //The command here is submitOnly in place of submit as it conflicts with submitAndSchedule and tab feature will not + //work of shell + @CliCommand(value = ENTITY_COMMAND_PREFIX + SUBMIT_ONLY_OPT, help = SUBMIT_OPT_DESCRIPTION) + public String submit( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {FILE_PATH_OPT}, mandatory = true, help = FILE_PATH_OPT_DESCRIPTION) final File filePath + ) { + + return getFalconClient().submit(entityType.name().toLowerCase(), filePath.getPath(), + getDoAs()).getMessage(); + } + + @CliCommand(value = ENTITY_COMMAND_PREFIX + LOOKUP_OPT, help = LOOKUP_OPT_DESCRIPTION) + public String lookup( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {PATH_OPT}, mandatory = true, help = PATH_OPT_DESCRIPTION) final String feedInstancePath + ) { + + FeedLookupResult resp = getFalconClient().reverseLookUp(entityType.name().toLowerCase(), + feedInstancePath, getDoAs()); + return ResponseHelper.getString(resp); + } + + @CliCommand(value = ENTITY_COMMAND_PREFIX + UPDATE_OPT, help = UPDATE_OPT_DESCRIPTION) + public String update( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {ENTITY_NAME_OPT}, mandatory = true, help = ENTITY_NAME_OPT_DESCRIPTION) + final String entityName, + @CliOption(key = {FILE_PATH_OPT}, mandatory = true, help = FILE_PATH_OPT_DESCRIPTION) + final File filePath, + @CliOption(key = {SKIPDRYRUN_OPT}, mandatory = false, help = SKIPDRYRUN_OPT_DESCRIPTION, + unspecifiedDefaultValue = "false", specifiedDefaultValue = "true") boolean skipDryRun + ) { + return getFalconClient() + .update(entityType.name().toLowerCase(), entityName, filePath.getPath(), skipDryRun, getDoAs()) + .getMessage(); + } + + @CliCommand(value = ENTITY_COMMAND_PREFIX + SUBMIT_AND_SCHEDULE_OPT, help = SUBMIT_AND_SCHEDULE_OPT_DESCRIPTION) + public String submitAndSchedule( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {FILE_PATH_OPT}, mandatory = true, help = FILE_PATH_OPT_DESCRIPTION) final File filePath, + @CliOption(key = {SKIPDRYRUN_OPT}, mandatory = false, help = SKIPDRYRUN_OPT_DESCRIPTION, + unspecifiedDefaultValue = "false", specifiedDefaultValue = "true") boolean skipDryRun, + @CliOption(key = {PROPS_OPT}, mandatory = false, help = PROPS_OPT_DESCRIPTION) final String properties + ) { + + return getFalconClient() + .submitAndSchedule(entityType.name().toLowerCase(), filePath.getPath(), skipDryRun, getDoAs(), + properties) + .getMessage(); + } + + @CliCommand(value = ENTITY_COMMAND_PREFIX + VALIDATE_OPT, help = VALIDATE_OPT_DESCRIPTION) + public String validate( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {FILE_PATH_OPT}, mandatory = true, help = FILE_PATH_OPT_DESCRIPTION) final File filePath, + @CliOption(key = {SKIPDRYRUN_OPT}, mandatory = false, help = SKIPDRYRUN_OPT_DESCRIPTION, + unspecifiedDefaultValue = "false", specifiedDefaultValue = "true") boolean skipDryRun + ) { + + return getFalconClient() + .validate(entityType.name().toLowerCase(), filePath.getPath(), skipDryRun, getDoAs()) + .getMessage(); + } + + @CliCommand(value = ENTITY_COMMAND_PREFIX + SCHEDULE_OPT, help = SCHEDULE_OPT_DESCRIPTION) + public String schedule( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {ENTITY_NAME_OPT}, mandatory = true, help = ENTITY_NAME_OPT_DESCRIPTION) String entityName, + @CliOption(key = {COLO_OPT}, mandatory = false, help = COLO_OPT_DESCRIPTION, + unspecifiedDefaultValue = "*") final String colo, + @CliOption(key = {SKIPDRYRUN_OPT}, mandatory = false, help = SKIPDRYRUN_OPT_DESCRIPTION, + unspecifiedDefaultValue = "false", specifiedDefaultValue = "true") boolean skipDryRun, + @CliOption(key = {PROPS_OPT}, mandatory = false, help = PROPS_OPT_DESCRIPTION) final String properties + ) { + + return getFalconClient().schedule(entityType, entityName, colo, skipDryRun, getDoAs(), + properties).getMessage(); + } + + @CliCommand(value = ENTITY_COMMAND_PREFIX + SUSPEND_OPT, help = SUSPEND_OPT_DESCRIPTION) + public String suspend( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {ENTITY_NAME_OPT}, mandatory = true, help = ENTITY_NAME_OPT_DESCRIPTION) String entityName, + @CliOption(key = {COLO_OPT}, mandatory = false, help = COLO_OPT_DESCRIPTION, + unspecifiedDefaultValue = "*") final String colo + ) { + + return getFalconClient().suspend(entityType, entityName, colo, getDoAs()).getMessage(); + } + + @CliCommand(value = ENTITY_COMMAND_PREFIX + RESUME_OPT, help = RESUME_OPT_DESCRIPTION) + public String resume( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {ENTITY_NAME_OPT}, mandatory = true, help = ENTITY_NAME_OPT_DESCRIPTION) String entityName, + @CliOption(key = {COLO_OPT}, mandatory = false, help = COLO_OPT_DESCRIPTION, + unspecifiedDefaultValue = "*") final String colo + ) { + + return getFalconClient().resume(entityType, entityName, colo, getDoAs()).getMessage(); + } + + @CliCommand(value = ENTITY_COMMAND_PREFIX + DELETE_OPT, help = DELETE_OPT_DESCRIPTION) + public String delete( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {ENTITY_NAME_OPT}, mandatory = true, help = ENTITY_NAME_OPT_DESCRIPTION) String entityName + ) { + + return getFalconClient().delete(entityType, entityName, getDoAs()).getMessage(); + } + + @CliCommand(value = ENTITY_COMMAND_PREFIX + STATUS_OPT, help = STATUS_OPT_DESCRIPTION) + public String getStatus( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {ENTITY_NAME_OPT}, mandatory = true, help = ENTITY_NAME_OPT_DESCRIPTION) String entityName, + @CliOption(key = {COLO_OPT}, mandatory = false, help = COLO_OPT_DESCRIPTION, + unspecifiedDefaultValue = "*") final String colo, + @CliOption(key = {SHOWSCHEDULER_OPT}, mandatory = true, + help = SHOWSCHEDULER_OPT_DESCRIPTION) final boolean showScheduler + ) { + + return getFalconClient().getStatus(entityType, entityName, colo, getDoAs(), + showScheduler).getMessage(); + } + + @CliCommand(value = ENTITY_COMMAND_PREFIX + DEFINITION_OPT, help = DEFINITION_OPT_DESCRIPTION) + public String getDefinition( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {ENTITY_NAME_OPT}, mandatory = true, help = ENTITY_NAME_OPT_DESCRIPTION) String entityName + ) { + + return getFalconClient().getDefinition(entityType.name().toLowerCase(), + entityName, getDoAs()).toString(); + } + + @CliCommand(value = ENTITY_COMMAND_PREFIX + DEPENDENCY_OPT, help = DEPENDENCY_OPT_DESCRIPTION) + public String getDependency( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {ENTITY_NAME_OPT}, mandatory = true, help = ENTITY_NAME_OPT_DESCRIPTION) String entityName + ) { + + return getFalconClient().getDependency(entityType.name().toLowerCase(), entityName, + getDoAs()).toString(); + } + + // SUSPEND CHECKSTYLE CHECK ParameterNumberCheck + @CliCommand(value = ENTITY_COMMAND_PREFIX + LIST_OPT, help = LIST_OPT_DESCRIPTION) + public String list( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {FIELDS_OPT}, mandatory = false, help = FIELDS_OPT_DESCRIPTION) final String fields, + @CliOption(key = {ORDER_BY_OPT}, mandatory = false, help = ORDER_BY_OPT_DESCRIPTION) final String orderBy, + @CliOption(key = {SORT_ORDER_OPT}, mandatory = false, + help = SORT_ORDER_OPT_DESCRIPTION) final String sortOrder, + @CliOption(key = {FILTER_BY_OPT}, mandatory = false, + help = FILTER_BY_OPT_DESCRIPTION) final String filterBy, + @CliOption(key = {TAGS_OPT}, mandatory = false, help = TAGS_OPT_DESCRIPTION) final String filterTags, + @CliOption(key = {NAMESEQ_OPT}, mandatory = false, + help = NAMESEQ_OPT_DESCRIPTION) final String nameSubsequence, + @CliOption(key = {TAGKEYS_OPT}, mandatory = false, help = TAGKEYS_OPT_DESCRIPTION) final String tagKeywords, + @CliOption(key = {OFFSET_OPT}, mandatory = false, help = OFFSET_OPT_DESCRIPTION) final Integer offset, + @CliOption(key = {NUM_RESULTS_OPT}, mandatory = false, + help = NUM_RESULTS_OPT_DESCRIPTION) final Integer numResults + + ) { + ValidationUtil.validateEntityFields(fields); + ValidationUtil.validateOrderBy(orderBy, ENTITY_PREFIX); + ValidationUtil.validateFilterBy(filterBy, ENTITY_PREFIX); + EntityList entityList = getFalconClient().getEntityList(entityType.name().toLowerCase(), + fields, nameSubsequence, tagKeywords, filterBy, filterTags, orderBy, sortOrder, offset, + numResults, getDoAs()); + return entityList != null ? entityList.toString() : "No entity of type (" + entityType + ") found."; + } + + @CliCommand(value = ENTITY_COMMAND_PREFIX + SUMMARY_OPT, help = SUMMARY_OPT_DESCRIPTION) + public String summary( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {CLUSTER_OPT}, mandatory = true, help = CLUSTER_OPT_DESCRIPTION) final String cluster, + @CliOption(key = {START_OPT}, mandatory = false, help = START_OPT_DESCRIPTION) final String start, + @CliOption(key = {END_OPT}, mandatory = false, help = END_OPT_DESCRIPTION) final String end, + @CliOption(key = {FIELDS_OPT}, mandatory = false, help = FIELDS_OPT_DESCRIPTION) final String fields, + @CliOption(key = {ORDER_BY_OPT}, mandatory = false, help = ORDER_BY_OPT_DESCRIPTION) final String orderBy, + @CliOption(key = {SORT_ORDER_OPT}, mandatory = false, + help = SORT_ORDER_OPT_DESCRIPTION) final String sortOrder, + @CliOption(key = {FILTER_BY_OPT}, mandatory = false, help = FILTER_BY_OPT_DESCRIPTION) final String filterBy, + @CliOption(key = {TAGS_OPT}, mandatory = false, help = TAGS_OPT_DESCRIPTION) final String filterTags, + @CliOption(key = {OFFSET_OPT}, mandatory = false, help = OFFSET_OPT_DESCRIPTION) final Integer offset, + @CliOption(key = {NUM_RESULTS_OPT}, mandatory = false, + help = NUM_RESULTS_OPT_DESCRIPTION) final Integer numResults, + @CliOption(key = {NUM_INSTANCES_OPT}, mandatory = false, + help = NUM_INSTANCES_OPT_DESCRIPTION) final Integer numInstances + + ) { + ValidationUtil.validateEntityTypeForSummary(entityType.name().toLowerCase()); + ValidationUtil.validateEntityFields(fields); + ValidationUtil.validateFilterBy(filterBy, ENTITY_PREFIX); + ValidationUtil.validateOrderBy(orderBy, ENTITY_PREFIX); + return ResponseHelper.getString(getFalconClient().getEntitySummary( + entityType.name().toLowerCase(), cluster, start, end, fields, filterBy, filterTags, + orderBy, sortOrder, offset, numResults, numInstances, getDoAs())); + } + // RESUME CHECKSTYLE CHECK ParameterNumberCheck +} http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/shell/src/main/java/org/apache/falcon/shell/commands/FalconInstanceCommands.java ---------------------------------------------------------------------- diff --git a/shell/src/main/java/org/apache/falcon/shell/commands/FalconInstanceCommands.java b/shell/src/main/java/org/apache/falcon/shell/commands/FalconInstanceCommands.java new file mode 100644 index 0000000..f20e201 --- /dev/null +++ b/shell/src/main/java/org/apache/falcon/shell/commands/FalconInstanceCommands.java @@ -0,0 +1,358 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.falcon.shell.commands; + +import org.apache.falcon.ResponseHelper; +import org.apache.falcon.entity.v0.EntityType; + +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; + + +import static org.apache.falcon.client.FalconCLIConstants.COLO_OPT; +import static org.apache.falcon.client.FalconCLIConstants.COLO_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.DEPENDENCY_OPT; +import static org.apache.falcon.client.FalconCLIConstants.DEPENDENCY_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.END_OPT; +import static org.apache.falcon.client.FalconCLIConstants.END_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.ENTITY_NAME_OPT; +import static org.apache.falcon.client.FalconCLIConstants.ENTITY_NAME_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.FILE_PATH_OPT; +import static org.apache.falcon.client.FalconCLIConstants.FILE_PATH_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.FILTER_BY_OPT; +import static org.apache.falcon.client.FalconCLIConstants.FILTER_BY_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.LIST_OPT; +import static org.apache.falcon.client.FalconCLIConstants.NUM_RESULTS_OPT; +import static org.apache.falcon.client.FalconCLIConstants.NUM_RESULTS_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.OFFSET_OPT; +import static org.apache.falcon.client.FalconCLIConstants.OFFSET_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.ORDER_BY_OPT; +import static org.apache.falcon.client.FalconCLIConstants.ORDER_BY_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.RESUME_OPT; +import static org.apache.falcon.client.FalconCLIConstants.RESUME_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.SORT_ORDER_OPT; +import static org.apache.falcon.client.FalconCLIConstants.SORT_ORDER_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.START_OPT; +import static org.apache.falcon.client.FalconCLIConstants.START_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.STATUS_OPT; +import static org.apache.falcon.client.FalconCLIConstants.STATUS_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.SUMMARY_OPT; +import static org.apache.falcon.client.FalconCLIConstants.SUMMARY_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.SUSPEND_OPT; +import static org.apache.falcon.client.FalconCLIConstants.SUSPEND_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.TYPE_OPT; +import static org.apache.falcon.client.FalconCLIConstants.TYPE_OPT_DESCRIPTION; + +import static org.apache.falcon.ValidationUtil.validateFilterBy; +import static org.apache.falcon.ValidationUtil.validateOrderBy; +import static org.apache.falcon.client.FalconCLIConstants.ALL_ATTEMPTS; +import static org.apache.falcon.client.FalconCLIConstants.ALL_ATTEMPTS_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.CLUSTERS_OPT; +import static org.apache.falcon.client.FalconCLIConstants.CLUSTERS_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.FORCE_RERUN_FLAG; +import static org.apache.falcon.client.FalconCLIConstants.FORCE_RERUN_FLAG_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.KILL_OPT; +import static org.apache.falcon.client.FalconCLIConstants.KILL_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.LIFECYCLE_OPT; +import static org.apache.falcon.client.FalconCLIConstants.LIFECYCLE_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.LISTING_OPT; +import static org.apache.falcon.client.FalconCLIConstants.LISTING_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.LOG_OPT; +import static org.apache.falcon.client.FalconCLIConstants.LOG_OPT_DESCRIPTION; + +import static org.apache.falcon.client.FalconCLIConstants.PARARMS_OPT; +import static org.apache.falcon.client.FalconCLIConstants.PARARMS_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.RERUN_OPT; +import static org.apache.falcon.client.FalconCLIConstants.RERUN_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.RUNID_OPT; +import static org.apache.falcon.client.FalconCLIConstants.RUNID_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.RUNNING_OPT; +import static org.apache.falcon.client.FalconCLIConstants.RUNNING_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.SOURCECLUSTER_OPT; +import static org.apache.falcon.client.FalconCLIConstants.SOURCECLUSTER_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.TRIAGE_OPT; +import static org.apache.falcon.client.FalconCLIConstants.TRIAGE_OPT_DESCRIPTION; +import static org.apache.falcon.ValidationUtil.getLifeCycle; + +/** + * Instance commands. + */ +@Component +public class FalconInstanceCommands extends BaseFalconCommands { + public static final String INSTANCE_PREFIX = "instance"; + public static final String INSTANCE_COMMAND_PREFIX = INSTANCE_PREFIX + " "; + + @CliCommand(value = INSTANCE_COMMAND_PREFIX + TRIAGE_OPT, help = TRIAGE_OPT_DESCRIPTION) + public String triage( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {ENTITY_NAME_OPT}, mandatory = true, help = ENTITY_NAME_OPT_DESCRIPTION) + final String entityName, + @CliOption(key = {COLO_OPT}, mandatory = true, help = COLO_OPT_DESCRIPTION) + final String colo, + @CliOption(key = {START_OPT}, mandatory = false, help = START_OPT_DESCRIPTION) final String start + ) { + return getFalconClient().triage(entityType.name(), entityName, start, + getColo(colo)).toString(); + } + + @CliCommand(value = INSTANCE_COMMAND_PREFIX + DEPENDENCY_OPT, help = DEPENDENCY_OPT_DESCRIPTION) + public String dependency( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {ENTITY_NAME_OPT}, mandatory = true, help = ENTITY_NAME_OPT_DESCRIPTION) + final String entityName, + @CliOption(key = {COLO_OPT}, mandatory = true, help = COLO_OPT_DESCRIPTION) + final String colo, + @CliOption(key = {START_OPT}, mandatory = false, help = START_OPT_DESCRIPTION) final String start + ) { + return getFalconClient().getInstanceDependencies(entityType.name(), entityName, + start, getColo(colo)) + .toString(); + } + // SUSPEND CHECKSTYLE CHECK ParameterNumberCheck + @CliCommand(value = INSTANCE_COMMAND_PREFIX + RUNNING_OPT, help = RUNNING_OPT_DESCRIPTION) + public String running( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {ENTITY_NAME_OPT}, mandatory = true, help = ENTITY_NAME_OPT_DESCRIPTION) + final String entityName, + @CliOption(key = {COLO_OPT}, mandatory = true, help = COLO_OPT_DESCRIPTION) + final String colo, + @CliOption(key = {LIFECYCLE_OPT}, mandatory = false, help = LIFECYCLE_OPT_DESCRIPTION) + final String lifeCycle, + @CliOption(key = {ORDER_BY_OPT}, mandatory = false, help = ORDER_BY_OPT_DESCRIPTION) final String orderBy, + @CliOption(key = {SORT_ORDER_OPT}, mandatory = false, + help = SORT_ORDER_OPT_DESCRIPTION) final String sortOrder, + @CliOption(key = {FILTER_BY_OPT}, mandatory = false, + help = FILTER_BY_OPT_DESCRIPTION) final String filterBy, + @CliOption(key = {OFFSET_OPT}, mandatory = false, help = OFFSET_OPT_DESCRIPTION) final Integer offset, + @CliOption(key = {NUM_RESULTS_OPT}, mandatory = false, + help = NUM_RESULTS_OPT_DESCRIPTION) final Integer numResults + ) { + validateOrderBy(orderBy, INSTANCE_PREFIX); + validateFilterBy(filterBy, INSTANCE_PREFIX); + return ResponseHelper.getString(getFalconClient().getRunningInstances(entityType.name(), + entityName, colo, getLifeCycle(lifeCycle), filterBy, orderBy, sortOrder, offset, numResults, + getDoAs())); + } + + @CliCommand(value = {INSTANCE_COMMAND_PREFIX + STATUS_OPT, INSTANCE_COMMAND_PREFIX + LIST_OPT}, + help = STATUS_OPT_DESCRIPTION) + public String status( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {ENTITY_NAME_OPT}, mandatory = true, help = ENTITY_NAME_OPT_DESCRIPTION) + final String entityName, + @CliOption(key = {COLO_OPT}, mandatory = false, help = COLO_OPT_DESCRIPTION) + final String colo, + @CliOption(key = {START_OPT}, mandatory = false, help = START_OPT_DESCRIPTION) final String start, + @CliOption(key = {END_OPT}, mandatory = false, help = END_OPT_DESCRIPTION) final String end, + @CliOption(key = {LIFECYCLE_OPT}, mandatory = false, help = LIFECYCLE_OPT_DESCRIPTION) + final String lifeCycle, + @CliOption(key = {ORDER_BY_OPT}, mandatory = false, help = ORDER_BY_OPT_DESCRIPTION) final String orderBy, + @CliOption(key = {SORT_ORDER_OPT}, mandatory = false, + help = SORT_ORDER_OPT_DESCRIPTION) final String sortOrder, + @CliOption(key = {FILTER_BY_OPT}, mandatory = false, + help = FILTER_BY_OPT_DESCRIPTION) final String filterBy, + @CliOption(key = {OFFSET_OPT}, mandatory = false, help = OFFSET_OPT_DESCRIPTION) final Integer offset, + @CliOption(key = {NUM_RESULTS_OPT}, mandatory = false, + help = NUM_RESULTS_OPT_DESCRIPTION) final Integer numResults, + @CliOption(key = {ALL_ATTEMPTS}, mandatory = false, specifiedDefaultValue = "true", + help = ALL_ATTEMPTS_DESCRIPTION) final Boolean allAttempts + ) { + validateOrderBy(orderBy, INSTANCE_PREFIX); + validateFilterBy(filterBy, INSTANCE_PREFIX); + return ResponseHelper.getString(getFalconClient().getStatusOfInstances(entityType.name(), + entityName, start, end, getColo(colo), getLifeCycle(lifeCycle), filterBy, orderBy, sortOrder, + offset, numResults, getDoAs(), allAttempts)); + } + + @CliCommand(value = {INSTANCE_COMMAND_PREFIX + SUMMARY_OPT}, + help = SUMMARY_OPT_DESCRIPTION) + public String summary( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {ENTITY_NAME_OPT}, mandatory = true, help = ENTITY_NAME_OPT_DESCRIPTION) + final String entityName, + @CliOption(key = {COLO_OPT}, mandatory = true, help = COLO_OPT_DESCRIPTION) + final String colo, + @CliOption(key = {START_OPT}, mandatory = false, help = START_OPT_DESCRIPTION) final String start, + @CliOption(key = {END_OPT}, mandatory = false, help = END_OPT_DESCRIPTION) final String end, + @CliOption(key = {LIFECYCLE_OPT}, mandatory = false, help = LIFECYCLE_OPT_DESCRIPTION) + final String lifeCycle, + @CliOption(key = {ORDER_BY_OPT}, mandatory = false, help = ORDER_BY_OPT_DESCRIPTION) final String orderBy, + @CliOption(key = {SORT_ORDER_OPT}, mandatory = false, + help = SORT_ORDER_OPT_DESCRIPTION) final String sortOrder, + @CliOption(key = {FILTER_BY_OPT}, mandatory = false, + help = FILTER_BY_OPT_DESCRIPTION) final String filterBy + ) { + validateOrderBy(orderBy, INSTANCE_PREFIX); + validateFilterBy(filterBy, INSTANCE_PREFIX); + return ResponseHelper.getString(getFalconClient().getSummaryOfInstances(entityType.name(), + entityName, start, end, getColo(colo), getLifeCycle(lifeCycle), filterBy, orderBy, + sortOrder, getDoAs())); + } + + @CliCommand(value = {INSTANCE_COMMAND_PREFIX + KILL_OPT}, + help = KILL_OPT_DESCRIPTION) + public String kill( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {ENTITY_NAME_OPT}, mandatory = true, help = ENTITY_NAME_OPT_DESCRIPTION) + final String entityName, + @CliOption(key = {COLO_OPT}, mandatory = true, help = COLO_OPT_DESCRIPTION) + final String colo, + @CliOption(key = {START_OPT}, mandatory = true, help = START_OPT_DESCRIPTION) final String start, + @CliOption(key = {END_OPT}, mandatory = true, help = END_OPT_DESCRIPTION) final String end, + @CliOption(key = {CLUSTERS_OPT}, mandatory = false, help = CLUSTERS_OPT_DESCRIPTION) final String clusters, + @CliOption(key = {SOURCECLUSTER_OPT}, mandatory = false, help = SOURCECLUSTER_OPT_DESCRIPTION) + final String sourceClusters, + @CliOption(key = {LIFECYCLE_OPT}, mandatory = false, help = LIFECYCLE_OPT_DESCRIPTION) + final String lifeCycle + ) throws UnsupportedEncodingException { + return ResponseHelper.getString(getFalconClient().killInstances(entityType.name(), + entityName, start, end, getColo(colo), clusters, sourceClusters, getLifeCycle(lifeCycle), getDoAs())); + } + + @CliCommand(value = {INSTANCE_COMMAND_PREFIX + SUSPEND_OPT}, + help = SUSPEND_OPT_DESCRIPTION) + public String suspend( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {ENTITY_NAME_OPT}, mandatory = true, help = ENTITY_NAME_OPT_DESCRIPTION) + final String entityName, + @CliOption(key = {COLO_OPT}, mandatory = true, help = COLO_OPT_DESCRIPTION) + final String colo, + @CliOption(key = {START_OPT}, mandatory = true, help = START_OPT_DESCRIPTION) final String start, + @CliOption(key = {END_OPT}, mandatory = true, help = END_OPT_DESCRIPTION) final String end, + @CliOption(key = {CLUSTERS_OPT}, mandatory = false, help = CLUSTERS_OPT_DESCRIPTION) final String clusters, + @CliOption(key = {SOURCECLUSTER_OPT}, mandatory = false, help = SOURCECLUSTER_OPT_DESCRIPTION) + final String sourceClusters, + @CliOption(key = {LIFECYCLE_OPT}, mandatory = false, help = LIFECYCLE_OPT_DESCRIPTION) + final String lifeCycle + ) throws UnsupportedEncodingException { + return ResponseHelper.getString(getFalconClient().suspendInstances(entityType.name(), + entityName, start, end, getColo(colo), clusters, sourceClusters, getLifeCycle(lifeCycle), getDoAs())); + } + + @CliCommand(value = {INSTANCE_COMMAND_PREFIX + RESUME_OPT}, + help = RESUME_OPT_DESCRIPTION) + public String resume( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {ENTITY_NAME_OPT}, mandatory = true, help = ENTITY_NAME_OPT_DESCRIPTION) + final String entityName, + @CliOption(key = {COLO_OPT}, mandatory = true, help = COLO_OPT_DESCRIPTION) + final String colo, + @CliOption(key = {START_OPT}, mandatory = true, help = START_OPT_DESCRIPTION) final String start, + @CliOption(key = {END_OPT}, mandatory = true, help = END_OPT_DESCRIPTION) final String end, + @CliOption(key = {CLUSTERS_OPT}, mandatory = false, help = CLUSTERS_OPT_DESCRIPTION) final String clusters, + @CliOption(key = {SOURCECLUSTER_OPT}, mandatory = false, help = SOURCECLUSTER_OPT_DESCRIPTION) + final String sourceClusters, + @CliOption(key = {LIFECYCLE_OPT}, mandatory = false, help = LIFECYCLE_OPT_DESCRIPTION) + final String lifeCycle + ) throws UnsupportedEncodingException { + return ResponseHelper.getString(getFalconClient().resumeInstances(entityType.name(), + entityName, start, end, getColo(colo), clusters, sourceClusters, getLifeCycle(lifeCycle), getDoAs())); + } + + @CliCommand(value = {INSTANCE_COMMAND_PREFIX + RERUN_OPT}, + help = RERUN_OPT_DESCRIPTION) + public String rerun( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {ENTITY_NAME_OPT}, mandatory = true, help = ENTITY_NAME_OPT_DESCRIPTION) + final String entityName, + @CliOption(key = {COLO_OPT}, mandatory = true, help = COLO_OPT_DESCRIPTION) + final String colo, + @CliOption(key = {START_OPT}, mandatory = true, help = START_OPT_DESCRIPTION) final String start, + @CliOption(key = {END_OPT}, mandatory = true, help = END_OPT_DESCRIPTION) final String end, + @CliOption(key = {FILE_PATH_OPT}, mandatory = false, help = FILE_PATH_OPT_DESCRIPTION) + final String filePath, + @CliOption(key = {CLUSTERS_OPT}, mandatory = false, help = CLUSTERS_OPT_DESCRIPTION) final String clusters, + @CliOption(key = {SOURCECLUSTER_OPT}, mandatory = false, help = SOURCECLUSTER_OPT_DESCRIPTION) + final String sourceClusters, + @CliOption(key = {LIFECYCLE_OPT}, mandatory = false, help = LIFECYCLE_OPT_DESCRIPTION) + final String lifeCycle, + @CliOption(key = {FORCE_RERUN_FLAG}, mandatory = false, specifiedDefaultValue = "true", + help = FORCE_RERUN_FLAG_DESCRIPTION) final Boolean forceRerun + ) throws IOException { + return ResponseHelper.getString(getFalconClient().rerunInstances(entityType.name(), + entityName, start, end, filePath, getColo(colo), clusters, sourceClusters, getLifeCycle(lifeCycle), + forceRerun, getDoAs())); + } + + @CliCommand(value = {INSTANCE_COMMAND_PREFIX + LOG_OPT}, + help = LOG_OPT_DESCRIPTION) + public String log( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {ENTITY_NAME_OPT}, mandatory = true, help = ENTITY_NAME_OPT_DESCRIPTION) + final String entityName, + @CliOption(key = {COLO_OPT}, mandatory = true, help = COLO_OPT_DESCRIPTION) + final String colo, + @CliOption(key = {RUNID_OPT}, mandatory = true, help = RUNID_OPT_DESCRIPTION) + final String runId, + @CliOption(key = {START_OPT}, mandatory = false, help = START_OPT_DESCRIPTION) final String start, + @CliOption(key = {END_OPT}, mandatory = false, help = END_OPT_DESCRIPTION) final String end, + @CliOption(key = {CLUSTERS_OPT}, mandatory = false, help = CLUSTERS_OPT_DESCRIPTION) final String clusters, + @CliOption(key = {LIFECYCLE_OPT}, mandatory = false, help = LIFECYCLE_OPT_DESCRIPTION) + final String lifeCycle, + @CliOption(key = {ORDER_BY_OPT}, mandatory = false, help = ORDER_BY_OPT_DESCRIPTION) final String orderBy, + @CliOption(key = {SORT_ORDER_OPT}, mandatory = false, + help = SORT_ORDER_OPT_DESCRIPTION) final String sortOrder, + @CliOption(key = {FILTER_BY_OPT}, mandatory = false, + help = FILTER_BY_OPT_DESCRIPTION) final String filterBy, + @CliOption(key = {OFFSET_OPT}, mandatory = false, help = OFFSET_OPT_DESCRIPTION) final Integer offset, + @CliOption(key = {NUM_RESULTS_OPT}, mandatory = false, + help = NUM_RESULTS_OPT_DESCRIPTION) final Integer numResults + ) { + validateOrderBy(orderBy, INSTANCE_PREFIX); + validateFilterBy(filterBy, INSTANCE_PREFIX); + return ResponseHelper.getString(getFalconClient().getLogsOfInstances(entityType.name(), + entityName, start, end, getColo(colo), runId, getLifeCycle(lifeCycle), filterBy, orderBy, sortOrder, + offset, numResults, getDoAs())); + } + // RESUME CHECKSTYLE CHECK ParameterNumberCheck + @CliCommand(value = {INSTANCE_COMMAND_PREFIX + PARARMS_OPT}, + help = PARARMS_OPT_DESCRIPTION) + public String params( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {ENTITY_NAME_OPT}, mandatory = true, help = ENTITY_NAME_OPT_DESCRIPTION) + final String entityName, + @CliOption(key = {COLO_OPT}, mandatory = true, help = COLO_OPT_DESCRIPTION) + final String colo, + @CliOption(key = {START_OPT}, mandatory = false, help = START_OPT_DESCRIPTION) final String start, + @CliOption(key = {LIFECYCLE_OPT}, mandatory = false, help = LIFECYCLE_OPT_DESCRIPTION) + final String lifeCycle + ) throws IOException { + return ResponseHelper.getString(getFalconClient().getParamsOfInstance(entityType.name(), + entityName, start, getColo(colo), getLifeCycle(lifeCycle), getDoAs())); + } + + @CliCommand(value = {INSTANCE_COMMAND_PREFIX + LISTING_OPT}, + help = LISTING_OPT_DESCRIPTION) + public String listing( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final EntityType entityType, + @CliOption(key = {ENTITY_NAME_OPT}, mandatory = true, help = ENTITY_NAME_OPT_DESCRIPTION) + final String entityName, + @CliOption(key = {COLO_OPT}, mandatory = true, help = COLO_OPT_DESCRIPTION) + final String colo, + @CliOption(key = {START_OPT}, mandatory = false, help = START_OPT_DESCRIPTION) final String start, + @CliOption(key = {END_OPT}, mandatory = false, help = END_OPT_DESCRIPTION) final String end + ) { + return ResponseHelper.getString(getFalconClient().getFeedInstanceListing(entityType.name(), + entityName, start, end, getColo(colo), getDoAs())); + } +} http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/shell/src/main/java/org/apache/falcon/shell/commands/FalconMetadataCommands.java ---------------------------------------------------------------------- diff --git a/shell/src/main/java/org/apache/falcon/shell/commands/FalconMetadataCommands.java b/shell/src/main/java/org/apache/falcon/shell/commands/FalconMetadataCommands.java new file mode 100644 index 0000000..5b7f7e1 --- /dev/null +++ b/shell/src/main/java/org/apache/falcon/shell/commands/FalconMetadataCommands.java @@ -0,0 +1,162 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.falcon.shell.commands; + +import org.apache.commons.lang3.StringUtils; +import org.apache.falcon.entity.v0.EntityType; +import org.apache.falcon.metadata.RelationshipType; +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; +import org.springframework.stereotype.Component; + +import static org.apache.falcon.client.FalconCLIConstants.NAME_OPT; +import static org.apache.falcon.client.FalconCLIConstants.PIPELINE_OPT; +import static org.apache.falcon.client.FalconCLIConstants.RELATIONS_OPT; +import static org.apache.falcon.client.FalconCLIConstants.CLUSTER_OPT; +import static org.apache.falcon.client.FalconCLIConstants.CLUSTER_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.DIRECTION_OPT; +import static org.apache.falcon.client.FalconCLIConstants.DIRECTION_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.EDGE_CMD; +import static org.apache.falcon.client.FalconCLIConstants.EDGE_CMD_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.FEED_OPT; +import static org.apache.falcon.client.FalconCLIConstants.FEED_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.ID_OPT; +import static org.apache.falcon.client.FalconCLIConstants.ID_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.KEY_OPT; +import static org.apache.falcon.client.FalconCLIConstants.KEY_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.LINEAGE_OPT; +import static org.apache.falcon.client.FalconCLIConstants.LINEAGE_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.LIST_OPT; +import static org.apache.falcon.client.FalconCLIConstants.LIST_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.NAME_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.NUM_RESULTS_OPT; +import static org.apache.falcon.client.FalconCLIConstants.NUM_RESULTS_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.PIPELINE_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.PROCESS_OPT; +import static org.apache.falcon.client.FalconCLIConstants.PROCESS_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.RELATIONS_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.TYPE_OPT; +import static org.apache.falcon.client.FalconCLIConstants.TYPE_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.VALUE_OPT; +import static org.apache.falcon.client.FalconCLIConstants.VALUE_OPT_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.VERTEX_CMD; +import static org.apache.falcon.client.FalconCLIConstants.VERTEX_CMD_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.VERTEX_EDGES_CMD; +import static org.apache.falcon.client.FalconCLIConstants.VERTEX_EDGES_CMD_DESCRIPTION; +import static org.apache.falcon.client.FalconCLIConstants.VERTICES_CMD; +import static org.apache.falcon.client.FalconCLIConstants.VERTICES_CMD_DESCRIPTION; +import static org.apache.falcon.ValidationUtil.validateDimensionName; +import static org.apache.falcon.ValidationUtil.validateDimensionType; +import static org.apache.falcon.ValidationUtil.validateId; +import static org.apache.falcon.ValidationUtil.validateScheduleEntity; +import static org.apache.falcon.ValidationUtil.validateVertexEdgesCommand; +import static org.apache.falcon.ValidationUtil.validateVerticesCommand; + +/** + * Metadata commands. + */ +@Component +public class FalconMetadataCommands extends BaseFalconCommands { + public static final String METADATA_PREFIX = "metadata"; + public static final String METADATA_COMMAND_PREFIX = METADATA_PREFIX + " "; + + @CliCommand(value = {METADATA_COMMAND_PREFIX + LINEAGE_OPT}, help = LINEAGE_OPT_DESCRIPTION) + public String lineage( + @CliOption(key = {PIPELINE_OPT}, mandatory = true, help = PIPELINE_OPT_DESCRIPTION) final String pipeline + ) { + return getFalconClient().getEntityLineageGraph(pipeline, getDoAs()).getDotNotation(); + } + + @CliCommand(value = {METADATA_COMMAND_PREFIX + LIST_OPT}, help = LIST_OPT_DESCRIPTION) + public String list( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final String dimensionType, + @CliOption(key = {CLUSTER_OPT}, mandatory = false, help = CLUSTER_OPT_DESCRIPTION) final String cluster, + @CliOption(key = {FEED_OPT}, mandatory = false, help = FEED_OPT_DESCRIPTION) final String feed, + @CliOption(key = {PROCESS_OPT}, mandatory = false, help = PROCESS_OPT_DESCRIPTION) final String process, + @CliOption(key = {NUM_RESULTS_OPT}, mandatory = false, + help = NUM_RESULTS_OPT_DESCRIPTION) final Integer numResults + ) { + validateDimensionType(dimensionType.toUpperCase()); + if (!(dimensionType.toUpperCase()) + .equals(RelationshipType.REPLICATION_METRICS.name())) { + return getFalconClient().getDimensionList(dimensionType, cluster, getDoAs()); + } else { + String schedEntityType = null; + String schedEntityName = null; + if (StringUtils.isNotEmpty(feed)) { + schedEntityType = EntityType.getEnum(FEED_OPT).name(); + schedEntityName = feed; + } else if (StringUtils.isNotEmpty(process)) { + schedEntityType = EntityType.getEnum(PROCESS_OPT).name(); + schedEntityName = process; + } + validateScheduleEntity(schedEntityType, schedEntityName); + + return getFalconClient().getReplicationMetricsDimensionList(schedEntityType, schedEntityName, + numResults, getDoAs()); + } + } + + @CliCommand(value = {METADATA_COMMAND_PREFIX + RELATIONS_OPT}, help = RELATIONS_OPT_DESCRIPTION) + public String relations( + @CliOption(key = {TYPE_OPT}, mandatory = true, help = TYPE_OPT_DESCRIPTION) final String dimensionType, + @CliOption(key = {NAME_OPT}, mandatory = true, help = NAME_OPT_DESCRIPTION) final String dimensionName, + @CliOption(key = {CLUSTER_OPT}, mandatory = false, help = CLUSTER_OPT_DESCRIPTION) final String cluster, + @CliOption(key = {FEED_OPT}, mandatory = false, help = FEED_OPT_DESCRIPTION) final String feed, + @CliOption(key = {PROCESS_OPT}, mandatory = false, help = PROCESS_OPT_DESCRIPTION) final String process, + @CliOption(key = {NUM_RESULTS_OPT}, mandatory = false, + help = NUM_RESULTS_OPT_DESCRIPTION) final Integer numResults + ) { + validateDimensionType(dimensionType.toUpperCase()); + validateDimensionName(dimensionName, RELATIONS_OPT); + return getFalconClient().getDimensionRelations(dimensionType, dimensionName, getDoAs()); + } + + @CliCommand(value = {METADATA_COMMAND_PREFIX + VERTEX_CMD}, help = VERTEX_CMD_DESCRIPTION) + public String vertex( + @CliOption(key = {ID_OPT}, mandatory = true, help = ID_OPT_DESCRIPTION) final String id + ) { + validateId(id); + return getFalconClient().getVertex(id, getDoAs()); + } + @CliCommand(value = {METADATA_COMMAND_PREFIX + EDGE_CMD}, help = EDGE_CMD_DESCRIPTION) + public String edge( + @CliOption(key = {ID_OPT}, mandatory = true, help = ID_OPT_DESCRIPTION) final String id + ) { + validateId(id); + return getFalconClient().getEdge(id, getDoAs()); + } + @CliCommand(value = {METADATA_COMMAND_PREFIX + VERTICES_CMD}, help = VERTICES_CMD_DESCRIPTION) + public String vertices( + @CliOption(key = {KEY_OPT}, mandatory = true, help = KEY_OPT_DESCRIPTION) final String key, + @CliOption(key = {VALUE_OPT}, mandatory = true, help = VALUE_OPT_DESCRIPTION) final String value + ) { + validateVerticesCommand(key, value); + return getFalconClient().getVertices(key, value, getDoAs()); + } + @CliCommand(value = {METADATA_COMMAND_PREFIX + VERTEX_EDGES_CMD}, help = VERTEX_EDGES_CMD_DESCRIPTION) + public String vertexEdges( + @CliOption(key = {ID_OPT}, mandatory = true, help = ID_OPT_DESCRIPTION) final String id, + @CliOption(key = {DIRECTION_OPT}, mandatory = true, help = DIRECTION_OPT_DESCRIPTION) final String direction + ) { + validateVertexEdgesCommand(id, direction); + return getFalconClient().getVertexEdges(id, direction, getDoAs()); + } + +} http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/shell/src/main/java/org/apache/falcon/shell/commands/FalconProfileCommands.java ---------------------------------------------------------------------- diff --git a/shell/src/main/java/org/apache/falcon/shell/commands/FalconProfileCommands.java b/shell/src/main/java/org/apache/falcon/shell/commands/FalconProfileCommands.java new file mode 100644 index 0000000..20562af --- /dev/null +++ b/shell/src/main/java/org/apache/falcon/shell/commands/FalconProfileCommands.java @@ -0,0 +1,86 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.falcon.shell.commands; + +import org.apache.commons.io.IOUtils; +import org.apache.falcon.client.FalconCLIException; +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; +import org.springframework.shell.support.util.OsUtils; +import org.springframework.stereotype.Component; + +import javax.annotation.Nonnull; +import java.io.IOException; +import java.io.InputStream; +import java.util.Enumeration; +import java.util.Properties; + + +/** + * To update falcon.url. + */ +@Component +public class FalconProfileCommands extends BaseFalconCommands{ + + public static final String LIST_PROFILE = "listProfile"; + public static final String LIST_HELP = "lists the colos available to set in falcon.url"; + public static final String SET_PROFILE = "updateProfile"; + public static final String SET_HELP = "update falcon.url with new url"; + public static final String PROFILE = "profile"; + private static final String SHELL_PROPERTIES = "/shell.properties"; + private static Properties prop = new Properties(); + + static { + InputStream inputStream = null; + //Need new properties as clientProperties has the system properties as well + try { + inputStream = BaseFalconCommands.class.getResourceAsStream(SHELL_PROPERTIES); + if (inputStream != null) { + try { + prop.load(inputStream); + } catch (IOException e) { + throw new FalconCLIException(e); + } + } + } finally { + IOUtils.closeQuietly(inputStream); + } + } + + @CliCommand(value = LIST_PROFILE , help = LIST_HELP) + public String listProfile() { + StringBuilder stringBuilder = new StringBuilder(); + + Enumeration e = prop.propertyNames(); + while(e.hasMoreElements()){ + Object o = e.nextElement(); + stringBuilder.append(o.toString()).append(OsUtils.LINE_SEPARATOR); + } + return stringBuilder.toString(); + } + + @CliCommand(value = SET_PROFILE , help = SET_HELP) + public String setProfile(@CliOption(key = {PROFILE}, mandatory = true, help = "key") + @Nonnull final String key){ + Properties properties = getShellProperties(); + String profile = prop.getProperty(key); + properties.setProperty(FALCON_URL_PROPERTY, profile); + setClientProperty(FALCON_URL_PROPERTY, profile); + return FALCON_URL_PROPERTY +"="+profile; + } +} http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/shell/src/main/java/org/apache/falcon/shell/skel/FalconBanner.java ---------------------------------------------------------------------- diff --git a/shell/src/main/java/org/apache/falcon/shell/skel/FalconBanner.java b/shell/src/main/java/org/apache/falcon/shell/skel/FalconBanner.java new file mode 100644 index 0000000..0f62365 --- /dev/null +++ b/shell/src/main/java/org/apache/falcon/shell/skel/FalconBanner.java @@ -0,0 +1,64 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package org.apache.falcon.shell.skel; + +import org.apache.falcon.shell.commands.BaseFalconCommands; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; +import org.springframework.shell.plugin.support.DefaultBannerProvider; +import org.springframework.shell.support.util.OsUtils; +import org.springframework.stereotype.Component; + +/** + * The Class FalconBanner. + */ +@Component +@Order(Ordered.HIGHEST_PRECEDENCE) +public class FalconBanner extends DefaultBannerProvider { + + @Override + public String getBanner() { + return new StringBuilder() + .append("=======================================").append(OsUtils.LINE_SEPARATOR) + .append("* *").append(OsUtils.LINE_SEPARATOR) + .append("* Falcon CLI *").append(OsUtils.LINE_SEPARATOR) + .append("* *").append(OsUtils.LINE_SEPARATOR) + .append("=======================================").append(OsUtils.LINE_SEPARATOR) + .append("falcon.url:"+ BaseFalconCommands.getShellProperties().get("falcon.url")) + .append(OsUtils.LINE_SEPARATOR) + .toString(); + + } + + @Override + public String getWelcomeMessage() { + return "Welcome to Falcon CLI"; + } + + @Override + public String getVersion() { + return getClass().getPackage().getImplementationVersion(); + } + + @Override + public String getProviderName() { + return "Falcon CLI"; + } +} http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/shell/src/main/java/org/apache/falcon/shell/skel/FalconHistoryFileProvider.java ---------------------------------------------------------------------- diff --git a/shell/src/main/java/org/apache/falcon/shell/skel/FalconHistoryFileProvider.java b/shell/src/main/java/org/apache/falcon/shell/skel/FalconHistoryFileProvider.java new file mode 100644 index 0000000..397452b --- /dev/null +++ b/shell/src/main/java/org/apache/falcon/shell/skel/FalconHistoryFileProvider.java @@ -0,0 +1,46 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.falcon.shell.skel; + +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; +import org.springframework.shell.plugin.support.DefaultHistoryFileNameProvider; +import org.springframework.stereotype.Component; + +/** + * The Class FalconHistoryFileProvider. + */ +@Component +@Order(Ordered.HIGHEST_PRECEDENCE) +public class FalconHistoryFileProvider extends DefaultHistoryFileNameProvider { + + public String getHistoryFileName() { + return "falcon-cli-hist.log"; + } + + /* + * (non-Javadoc) + * + * @see org.springframework.shell.plugin.support.DefaultHistoryFileNameProvider#name() + */ + @Override + public String getProviderName() { + return "falcon client history provider"; + } +} http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/shell/src/main/java/org/apache/falcon/shell/skel/FalconPromptProvider.java ---------------------------------------------------------------------- diff --git a/shell/src/main/java/org/apache/falcon/shell/skel/FalconPromptProvider.java b/shell/src/main/java/org/apache/falcon/shell/skel/FalconPromptProvider.java new file mode 100644 index 0000000..738fc3b --- /dev/null +++ b/shell/src/main/java/org/apache/falcon/shell/skel/FalconPromptProvider.java @@ -0,0 +1,47 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.falcon.shell.skel; + +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; +import org.springframework.shell.plugin.support.DefaultPromptProvider; +import org.springframework.stereotype.Component; + +/** + * The Class FalconPromptProvider. + */ +@Component +@Order(Ordered.HIGHEST_PRECEDENCE) +public class FalconPromptProvider extends DefaultPromptProvider { + + @Override + public String getPrompt() { + return "falcon-shell>"; + } + + /* + * (non-Javadoc) + * + * @see org.springframework.shell.plugin.support.DefaultPromptProvider#name() + */ + @Override + public String getProviderName() { + return "falcon prompt provider"; + } +} http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/shell/src/main/resources/META-INF/spring/spring-shell-plugin.xml ---------------------------------------------------------------------- diff --git a/shell/src/main/resources/META-INF/spring/spring-shell-plugin.xml b/shell/src/main/resources/META-INF/spring/spring-shell-plugin.xml new file mode 100644 index 0000000..d7a6414 --- /dev/null +++ b/shell/src/main/resources/META-INF/spring/spring-shell-plugin.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> + + <context:component-scan base-package="org.apache.falcon.shell"/> + + <bean id="falconConnectionCommands" + class="org.apache.falcon.shell.commands.FalconConnectionCommands"> + </bean> + <bean id="falconEntityCommands" + class="org.apache.falcon.shell.commands.FalconEntityCommands"> + </bean> + <bean id="falconInstanceCommands" + class="org.apache.falcon.shell.commands.FalconInstanceCommands"> + </bean> +</beans> http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/shell/src/main/resources/shell.properties ---------------------------------------------------------------------- diff --git a/shell/src/main/resources/shell.properties b/shell/src/main/resources/shell.properties new file mode 100644 index 0000000..815e731 --- /dev/null +++ b/shell/src/main/resources/shell.properties @@ -0,0 +1,25 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +#################################################### +#### This is used for falcon packaging only. #### +#################################################### + +falcon.url=http://localhost:16000 +colo1=http://foo:15000 +colo2=http://bar:15000 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/shell/src/test/FalconConnectionCommandsTest.java ---------------------------------------------------------------------- diff --git a/shell/src/test/FalconConnectionCommandsTest.java b/shell/src/test/FalconConnectionCommandsTest.java new file mode 100644 index 0000000..21a3be4 --- /dev/null +++ b/shell/src/test/FalconConnectionCommandsTest.java @@ -0,0 +1,47 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.falcon.cli.commands; + +import org.apache.falcon.client.FalconCLIException; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * Tests for Connection commands. + */ +public class FalconConnectionCommandsTest extends FalconCLITest { + @DataProvider(name = "params-commands", parallel = false) + public Object[][] provideCommands() { + FalconCLIException e = new FalconCLIException(BaseFalconCommands.FALCON_URL_ABSENT); + return new Object[][]{ + {"get", null, e}, + {"set a=b", null, null}, + {"get", null, e}, + {"get a", null, e}, + {"set falcon.url=DUMMY", null, null}, + {"get", "{a=b, falcon.url=DUMMY}", null}, + {"get a", "b", null}, + }; + } + +// @Test(dataProvider = "params-commands") + public void testGetAndSetParams(String command, Object result, Throwable throwable) throws Throwable { + execute(command, result, throwable); + } +} http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/src/bin/falcon-shell ---------------------------------------------------------------------- diff --git a/src/bin/falcon-shell b/src/bin/falcon-shell new file mode 100644 index 0000000..9e2b7e5 --- /dev/null +++ b/src/bin/falcon-shell @@ -0,0 +1,39 @@ +#!/bin/bash +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. See accompanying LICENSE file. +# + +# resolve links - $0 may be a softlink +PRG="${0}" + +while [ -h "${PRG}" ]; do + ls=`ls -ld "${PRG}"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "${PRG}"`/"$link" + fi +done + +BASEDIR=`dirname ${PRG}` +BASEDIR=`cd ${BASEDIR}/..;pwd` +. ${BASEDIR}/bin/falcon-config.sh 'client' + +JAVA_PROPERTIES="$FALCON_OPTS" +while [[ ${1} =~ ^\-D ]]; do + JAVA_PROPERTIES="${JAVA_PROPERTIES} ${1}" + shift +done + +${JAVA_BIN} ${JAVA_PROPERTIES} -cp ${FALCONCPPATH} -Dfalcon.log.dir=$HOME -Dfalcon.app.type=shell org.springframework.shell.Bootstrap "${@}" \ No newline at end of file http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/src/conf/shell.properties ---------------------------------------------------------------------- diff --git a/src/conf/shell.properties b/src/conf/shell.properties new file mode 100644 index 0000000..815e731 --- /dev/null +++ b/src/conf/shell.properties @@ -0,0 +1,25 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +#################################################### +#### This is used for falcon packaging only. #### +#################################################### + +falcon.url=http://localhost:16000 +colo1=http://foo:15000 +colo2=http://bar:15000 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/src/main/assemblies/standalone-package.xml ---------------------------------------------------------------------- diff --git a/src/main/assemblies/standalone-package.xml b/src/main/assemblies/standalone-package.xml index c291697..cfc3a26 100644 --- a/src/main/assemblies/standalone-package.xml +++ b/src/main/assemblies/standalone-package.xml @@ -286,6 +286,12 @@ </file> <file> + <source>../shell/target/falcon-shell-${project.version}.jar</source> + <outputDirectory>client/lib</outputDirectory> + <fileMode>0644</fileMode> + </file> + + <file> <source>../prism/target/prism.keystore</source> <outputDirectory>conf</outputDirectory> <destName>prism.keystore</destName> http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/unit/src/main/java/org/apache/falcon/unit/FalconUnitClient.java ---------------------------------------------------------------------- diff --git a/unit/src/main/java/org/apache/falcon/unit/FalconUnitClient.java b/unit/src/main/java/org/apache/falcon/unit/FalconUnitClient.java index 1025ced..53073f0 100644 --- a/unit/src/main/java/org/apache/falcon/unit/FalconUnitClient.java +++ b/unit/src/main/java/org/apache/falcon/unit/FalconUnitClient.java @@ -39,7 +39,9 @@ import org.apache.falcon.resource.FeedLookupResult; import org.apache.falcon.resource.InstanceDependencyResult; import org.apache.falcon.resource.InstancesResult; import org.apache.falcon.resource.InstancesSummaryResult; +import org.apache.falcon.resource.LineageGraphResult; import org.apache.falcon.resource.SchedulableEntityInstanceResult; +import org.apache.falcon.resource.TriageResult; import org.apache.falcon.resource.admin.AdminResource; import org.apache.falcon.util.DateUtil; import org.apache.falcon.workflow.WorkflowEngineFactory; @@ -385,6 +387,75 @@ public class FalconUnitClient extends AbstractFalconClient { return null; } + @Override + public TriageResult triage(String name, String entityName, String start, String colo) { + return null; + } + // SUSPEND CHECKSTYLE CHECK ParameterNumberCheck + @Override + public InstancesResult getRunningInstances(String type, String entity, String colo, List<LifeCycle> lifeCycles, + String filterBy, String orderBy, String sortOrder, + Integer offset, Integer numResults, String doAsUser) { + return null; + } + // RESUME CHECKSTYLE CHECK ParameterNumberCheck + @Override + public FeedInstanceResult getFeedInstanceListing(String type, String entity, String start, String end, + String colo, String doAsUser) { + return null; + } + + @Override + public int getStatus(String doAsUser) { + return 200; + } + + @Override + public String getThreadDump(String doAs) { + return ""; + } + + @Override + public LineageGraphResult getEntityLineageGraph(String pipeline, String doAs) { + return null; + } + + @Override + public String getDimensionList(String dimensionType, String cluster, String doAs) { + return null; + } + + @Override + public String getReplicationMetricsDimensionList(String schedEntityType, String schedEntityName, + Integer numResults, String doAs) { + return null; + } + + @Override + public String getDimensionRelations(String dimensionType, String dimensionName, String doAs) { + return null; + } + + @Override + public String getVertex(String id, String doAs) { + return null; + } + + @Override + public String getVertices(String key, String value, String doAs) { + return null; + } + + @Override + public String getVertexEdges(String id, String direction, String doAs) { + return null; + } + + @Override + public String getEdge(String id, String doAs) { + return null; + } + private boolean checkAndUpdateCluster(Entity entity, EntityType entityType, String cluster) { if (entityType == EntityType.FEED) { return checkAndUpdateFeedClusters(entity, cluster); http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/webapp/src/test/java/org/apache/falcon/cli/FalconCLIIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/falcon/cli/FalconCLIIT.java b/webapp/src/test/java/org/apache/falcon/cli/FalconCLIIT.java index 4f72d82..5cdbf93 100644 --- a/webapp/src/test/java/org/apache/falcon/cli/FalconCLIIT.java +++ b/webapp/src/test/java/org/apache/falcon/cli/FalconCLIIT.java @@ -18,7 +18,7 @@ package org.apache.falcon.cli; -import org.apache.falcon.FalconCLIConstants; +import org.apache.falcon.client.FalconCLIConstants; import org.apache.falcon.entity.v0.SchemaHelper; import org.apache.falcon.metadata.RelationshipType; import org.apache.falcon.resource.TestContext; http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/webapp/src/test/java/org/apache/falcon/resource/TestContext.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/falcon/resource/TestContext.java b/webapp/src/test/java/org/apache/falcon/resource/TestContext.java index 42a5247..fd4d364 100644 --- a/webapp/src/test/java/org/apache/falcon/resource/TestContext.java +++ b/webapp/src/test/java/org/apache/falcon/resource/TestContext.java @@ -27,7 +27,7 @@ import com.sun.jersey.client.urlconnection.HTTPSProperties; import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.net.util.TrustManagerUtils; -import org.apache.falcon.FalconCLIConstants; +import org.apache.falcon.client.FalconCLIConstants; import org.apache.falcon.FalconException; import org.apache.falcon.FalconRuntimException; import org.apache.falcon.catalog.HiveCatalogService;
