http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/cli/src/main/java/org/apache/falcon/cli/commands/FalconEntityCommands.java ---------------------------------------------------------------------- diff --git a/cli/src/main/java/org/apache/falcon/cli/commands/FalconEntityCommands.java b/cli/src/main/java/org/apache/falcon/cli/commands/FalconEntityCommands.java deleted file mode 100644 index 427ba1c..0000000 --- a/cli/src/main/java/org/apache/falcon/cli/commands/FalconEntityCommands.java +++ /dev/null @@ -1,326 +0,0 @@ -/** - * 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.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.FalconCLIConstants.DEFINITION_OPT; -import static org.apache.falcon.FalconCLIConstants .DELETE_OPT; -import static org.apache.falcon.FalconCLIConstants .LOOKUP_OPT; -import static org.apache.falcon.FalconCLIConstants.SLA_MISS_ALERT_OPT; -import static org.apache.falcon.FalconCLIConstants.SUBMIT_OPT; -import static org.apache.falcon.FalconCLIConstants.UPDATE_OPT; -import static org.apache.falcon.cli.FalconCLI.validateEntityTypeForSummary; -import static org.apache.falcon.cli.FalconCLI.validateFilterBy; -import static org.apache.falcon.cli.FalconCLI.validateOrderBy; -import static org.apache.falcon.cli.FalconEntityCLI.CLUSTER_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.CLUSTER_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.COLO_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.COLO_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.DEFINITION_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.DELETE_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.DEPENDENCY_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.DEPENDENCY_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.END_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.END_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.ENTITY_NAME_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.ENTITY_NAME_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.FIELDS_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.FIELDS_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.FILE_PATH_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.FILE_PATH_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.FILTER_BY_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.FILTER_BY_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.LIST_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.LIST_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.LOOKUP_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.NAMESEQ_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.NAMESEQ_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.NUM_INSTANCES_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.NUM_INSTANCES_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.NUM_RESULTS_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.NUM_RESULTS_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.OFFSET_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.OFFSET_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.ORDER_BY_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.ORDER_BY_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.PATH_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.PATH_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.PROPS_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.PROPS_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.RESUME_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.RESUME_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.SCHEDULE_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.SCHEDULE_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.SHOWSCHEDULER_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.SHOWSCHEDULER_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.SKIPDRYRUN_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.SKIPDRYRUN_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.SLA_MISS_ALERT_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.SORT_ORDER_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.SORT_ORDER_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.START_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.START_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.STATUS_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.STATUS_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.SUBMIT_AND_SCHEDULE_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.SUBMIT_AND_SCHEDULE_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.SUBMIT_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.SUMMARY_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.SUMMARY_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.SUSPEND_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.SUSPEND_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.TAGKEYS_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.TAGKEYS_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.TAGS_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.TAGS_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.TYPE_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.TYPE_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.UPDATE_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.VALIDATE_OPT; -import static org.apache.falcon.cli.FalconEntityCLI.VALIDATE_OPT_DESCRIPTION; -import static org.apache.falcon.cli.FalconEntityCLI.validateEntityFields; - -/** - * 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); - } - - @CliCommand(value = ENTITY_COMMAND_PREFIX + SUBMIT_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 - - ) { - validateEntityFields(fields); - validateOrderBy(orderBy, ENTITY_PREFIX); - 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 - - ) { - validateEntityTypeForSummary(entityType.name().toLowerCase()); - validateEntityFields(fields); - validateFilterBy(filterBy, ENTITY_PREFIX); - 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/cli/src/main/java/org/apache/falcon/cli/commands/FalconInstanceCommands.java ---------------------------------------------------------------------- diff --git a/cli/src/main/java/org/apache/falcon/cli/commands/FalconInstanceCommands.java b/cli/src/main/java/org/apache/falcon/cli/commands/FalconInstanceCommands.java deleted file mode 100644 index 5b62cf0..0000000 --- a/cli/src/main/java/org/apache/falcon/cli/commands/FalconInstanceCommands.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * 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.springframework.stereotype.Component; - -/** - * Instance commands. - */ -@Component -public class FalconInstanceCommands extends BaseFalconCommands { - -} http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/cli/src/main/java/org/apache/falcon/cli/skel/FalconBanner.java ---------------------------------------------------------------------- diff --git a/cli/src/main/java/org/apache/falcon/cli/skel/FalconBanner.java b/cli/src/main/java/org/apache/falcon/cli/skel/FalconBanner.java deleted file mode 100644 index 03c56c9..0000000 --- a/cli/src/main/java/org/apache/falcon/cli/skel/FalconBanner.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * 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.skel; - -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) - .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/cli/src/main/java/org/apache/falcon/cli/skel/FalconHistoryFileProvider.java ---------------------------------------------------------------------- diff --git a/cli/src/main/java/org/apache/falcon/cli/skel/FalconHistoryFileProvider.java b/cli/src/main/java/org/apache/falcon/cli/skel/FalconHistoryFileProvider.java deleted file mode 100644 index 74d003a..0000000 --- a/cli/src/main/java/org/apache/falcon/cli/skel/FalconHistoryFileProvider.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * 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.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/cli/src/main/java/org/apache/falcon/cli/skel/FalconPromptProvider.java ---------------------------------------------------------------------- diff --git a/cli/src/main/java/org/apache/falcon/cli/skel/FalconPromptProvider.java b/cli/src/main/java/org/apache/falcon/cli/skel/FalconPromptProvider.java deleted file mode 100644 index d8ead5b..0000000 --- a/cli/src/main/java/org/apache/falcon/cli/skel/FalconPromptProvider.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 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.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/cli/src/main/resources/META-INF/spring/spring-shell-plugin.xml ---------------------------------------------------------------------- diff --git a/cli/src/main/resources/META-INF/spring/spring-shell-plugin.xml b/cli/src/main/resources/META-INF/spring/spring-shell-plugin.xml deleted file mode 100644 index bd0fed4..0000000 --- a/cli/src/main/resources/META-INF/spring/spring-shell-plugin.xml +++ /dev/null @@ -1,40 +0,0 @@ -<?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.cli"/> - - <bean id="falconConnectionCommands" - class="org.apache.falcon.cli.commands.FalconConnectionCommands"> - </bean> - <bean id="falconEntityCommands" - class="org.apache.falcon.cli.commands.FalconEntityCommands"> - </bean> - <bean id="falconInstanceCommands" - class="org.apache.falcon.cli.commands.FalconInstanceCommands"> - </bean> -</beans> http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/cli/src/test/java/org/apache/falcon/cli/commands/FalconConnectionCommandsTest.java ---------------------------------------------------------------------- diff --git a/cli/src/test/java/org/apache/falcon/cli/commands/FalconConnectionCommandsTest.java b/cli/src/test/java/org/apache/falcon/cli/commands/FalconConnectionCommandsTest.java deleted file mode 100644 index d6ad6f9..0000000 --- a/cli/src/test/java/org/apache/falcon/cli/commands/FalconConnectionCommandsTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 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/client/src/main/java/org/apache/falcon/FalconCLIConstants.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/falcon/FalconCLIConstants.java b/client/src/main/java/org/apache/falcon/FalconCLIConstants.java deleted file mode 100644 index bcf3fe6..0000000 --- a/client/src/main/java/org/apache/falcon/FalconCLIConstants.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * 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; - -/** -* FalconCLI Constants. -*/ -public final class FalconCLIConstants { - private FalconCLIConstants(){ - - } - public static final String ENV_FALCON_DEBUG = "FALCON_DEBUG"; - public static final String DEBUG_OPTION = "debug"; - public static final String URL_OPTION = "url"; - public static final String DEFINITION_OPT = "definition"; - public static final String LOOKUP_OPT = "lookup"; - public static final String SLA_MISS_ALERT_OPT = "slaAlert"; - public static final String TOUCH_OPT = "touch"; - public static final String ADMIN_CMD = "admin"; - public static final String HELP_CMD = "help"; - public static final String METADATA_CMD = "metadata"; - public static final String ENTITY_CMD = "entity"; - public static final String INSTANCE_CMD = "instance"; - public static final String EXTENSION_CMD = "extension"; - public static final String SAFE_MODE_OPT = "setsafemode"; - public static final String TYPE_OPT = "type"; - public static final String COLO_OPT = "colo"; - public static final String CLUSTER_OPT = "cluster"; - public static final String FEED_OPT = "feed"; - public static final String PROCESS_OPT = "process"; - public static final String ENTITY_NAME_OPT = "name"; - public static final String FILE_PATH_OPT = "file"; - public static final String VERSION_OPT = "version"; - public static final String SUBMIT_OPT = "submit"; - public static final String UPDATE_OPT = "update"; - public static final String UPDATE_CLUSTER_DEPENDENTS_OPT = "updateClusterDependents"; - public static final String DELETE_OPT = "delete"; - public static final String SUBMIT_AND_SCHEDULE_OPT = "submitAndSchedule"; - public static final String VALIDATE_OPT = "validate"; - public static final String SCHEDULE_OPT = "schedule"; - public static final String SUSPEND_OPT = "suspend"; - public static final String RESUME_OPT = "resume"; - public static final String STATUS_OPT = "status"; - public static final String SUMMARY_OPT = "summary"; - public static final String DEPENDENCY_OPT = "dependency"; - public static final String LIST_OPT = "list"; - public static final String SKIPDRYRUN_OPT = "skipDryRun"; - public static final String FIELDS_OPT = "fields"; - public static final String INSTANCE_STATUS_OPT = "instanceStatus"; - public static final String NAMESEQ_OPT = "nameseq"; - public static final String TAGKEYS_OPT = "tagkeys"; - public static final String FILTER_BY_OPT = "filterBy"; - public static final String ORDER_BY_OPT = "orderBy"; - public static final String SORT_ORDER_OPT = "sortOrder"; - public static final String OFFSET_OPT = "offset"; - public static final String NUM_RESULTS_OPT = "numResults"; - public static final String START_OPT = "start"; - public static final String END_OPT = "end"; - public static final String CURRENT_COLO = "current.colo"; - public static final String CLIENT_PROPERTIES = "/client.properties"; - public static final String DO_AS_OPT = "doAs"; - public static final String RELATIONS_OPT = "relations"; - public static final String PIPELINE_OPT = "pipeline"; - public static final String NAME_OPT = "name"; -} http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/client/src/main/java/org/apache/falcon/ValidationUtil.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/falcon/ValidationUtil.java b/client/src/main/java/org/apache/falcon/ValidationUtil.java new file mode 100644 index 0000000..cdf1f05 --- /dev/null +++ b/client/src/main/java/org/apache/falcon/ValidationUtil.java @@ -0,0 +1,199 @@ +/** + * 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; + +import org.apache.commons.lang3.StringUtils; +import org.apache.falcon.client.FalconCLIConstants; +import org.apache.falcon.client.FalconCLIException; +import org.apache.falcon.entity.v0.EntityType; +import org.apache.falcon.metadata.RelationshipType; +import org.apache.falcon.resource.EntityList; +import org.apache.falcon.resource.InstancesResult; +import org.apache.falcon.resource.InstancesSummaryResult; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * All the validation methods to check the params from CLI and Shell. + */ +public final class ValidationUtil { + + private ValidationUtil(){} + + public static void validateEntityFields(String fields) { + if (StringUtils.isEmpty(fields)) { + return; + } + String[] fieldsList = fields.split(","); + for (String s : fieldsList) { + try { + EntityList.EntityFieldList.valueOf(s.toUpperCase()); + } catch (IllegalArgumentException ie) { + throw new FalconCLIException("Invalid fields argument : " + FalconCLIConstants.FIELDS_OPT); + } + } + } + + public static void validateOrderBy(String orderBy, String action) { + if (StringUtils.isBlank(orderBy)) { + return; + } + if (action.equals("instance")) { + if (Arrays.asList(new String[]{"status", "cluster", "starttime", "endtime"}) + .contains(orderBy.toLowerCase())) { + return; + } + } else if (action.equals("entity")) { + if (Arrays.asList(new String[] {"type", "name"}).contains(orderBy.toLowerCase())) { + return; + } + } else if (action.equals("summary")) { + if (Arrays.asList(new String[]{"cluster"}) + .contains(orderBy.toLowerCase())) { + return; + } + } + throw new FalconCLIException("Invalid orderBy argument : " + orderBy); + } + + public static void validateFilterBy(String filterBy, String filterType) { + if (StringUtils.isBlank(filterBy)) { + return; + } + String[] filterSplits = filterBy.split(","); + for (String s : filterSplits) { + String[] tempKeyVal = s.split(":", 2); + try { + if (filterType.equals("entity")) { + EntityList.EntityFilterByFields.valueOf(tempKeyVal[0].toUpperCase()); + } else if (filterType.equals("instance")) { + InstancesResult.InstanceFilterFields.valueOf(tempKeyVal[0].toUpperCase()); + }else if (filterType.equals("summary")) { + InstancesSummaryResult.InstanceSummaryFilterFields.valueOf(tempKeyVal[0].toUpperCase()); + } else { + throw new IllegalArgumentException("Invalid API call: filterType is not valid"); + } + } catch (IllegalArgumentException ie) { + throw new FalconCLIException("Invalid filterBy argument : " + tempKeyVal[0] + " in : " + s); + } + } + } + + public static void validateEntityTypeForSummary(String type) { + EntityType entityType = EntityType.getEnum(type); + if (!entityType.isSchedulable()) { + throw new FalconCLIException("Invalid entity type " + entityType + + " for EntitySummary API. Valid options are feed or process"); + } + } + + public static List<LifeCycle> getLifeCycle(String lifeCycleValue) { + if (lifeCycleValue != null) { + String[] lifeCycleValues = lifeCycleValue.split(","); + List<LifeCycle> lifeCycles = new ArrayList<LifeCycle>(); + try { + for (String lifeCycle : lifeCycleValues) { + lifeCycles.add(LifeCycle.valueOf(lifeCycle.toUpperCase().trim())); + } + } catch (IllegalArgumentException e) { + throw new FalconCLIException("Invalid life cycle values: " + lifeCycles, e); + } + return lifeCycles; + } + return null; + } + + public static void validateDimensionName(String dimensionName, String action) { + if (StringUtils.isBlank(dimensionName)) { + throw new FalconCLIException("Dimension ID cannot be empty or null for action " + action); + } + } + + public static void validateDimensionType(String dimensionType) { + if (StringUtils.isBlank(dimensionType) + || dimensionType.contains("INSTANCE")) { + throw new FalconCLIException("Invalid value provided for queryParam \"type\" " + dimensionType); + } + try { + RelationshipType.valueOf(dimensionType); + } catch (IllegalArgumentException iae) { + throw new FalconCLIException("Invalid value provided for queryParam \"type\" " + dimensionType); + } + } + + public static void validateId(String id) { + if (id == null || id.length() == 0) { + throw new FalconCLIException("Missing argument: id"); + } + } + + public static void validateScheduleEntity(String schedEntityType, String schedEntityName) { + if (StringUtils.isBlank(schedEntityType)) { + throw new FalconCLIException("Entity must be schedulable type : -feed/process"); + } + + if (StringUtils.isBlank(schedEntityName)) { + throw new FalconCLIException("Entity name is missing"); + } + } + + public static void validateVertexEdgesCommand(String id, String direction) { + if (id == null || id.length() == 0) { + throw new FalconCLIException("Missing argument: id"); + } + + if (direction == null || direction.length() == 0) { + throw new FalconCLIException("Missing argument: direction"); + } + } + + public static void validateVerticesCommand(String key, String value) { + if (key == null || key.length() == 0) { + throw new FalconCLIException("Missing argument: key"); + } + + if (value == null || value.length() == 0) { + throw new FalconCLIException("Missing argument: value"); + } + } + + public static void validatePipelineName(String pipeline) { + if (StringUtils.isBlank(pipeline)) { + throw new FalconCLIException("Invalid value for pipeline"); + } + } + + public static void validateNotEmpty(String paramVal, String paramName) { + if (StringUtils.isBlank(paramVal)) { + throw new FalconCLIException("Missing argument : " + paramName); + } + } + + public static void validateSortOrder(String sortOrder) { + if (!StringUtils.isBlank(sortOrder)) { + if (!sortOrder.equalsIgnoreCase("asc") && !sortOrder.equalsIgnoreCase("desc")) { + throw new FalconCLIException("Value for param sortOrder should be \"asc\" or \"desc\". It is : " + + sortOrder); + } + } + } + +} http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/client/src/main/java/org/apache/falcon/client/AbstractFalconClient.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/falcon/client/AbstractFalconClient.java b/client/src/main/java/org/apache/falcon/client/AbstractFalconClient.java index b3fd3ae..5d6eff5 100644 --- a/client/src/main/java/org/apache/falcon/client/AbstractFalconClient.java +++ b/client/src/main/java/org/apache/falcon/client/AbstractFalconClient.java @@ -28,7 +28,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 java.io.ByteArrayInputStream; import java.io.IOException; @@ -460,4 +462,34 @@ public abstract class AbstractFalconClient { public abstract FeedLookupResult reverseLookUp(String entityType, String path, String doAs); public abstract EntityList getDependency(String entityType, String entityName, String doAs); + + public abstract TriageResult triage(String name, String entityName, String start, String colo); + // SUSPEND CHECKSTYLE CHECK ParameterNumberCheck + public abstract InstancesResult getRunningInstances(String type, String entity, String colo, + List<LifeCycle> lifeCycles, + String filterBy, String orderBy, String sortOrder, + Integer offset, Integer numResults, String doAsUser); + // RESUME CHECKSTYLE CHECK ParameterNumberCheck + public abstract FeedInstanceResult getFeedInstanceListing(String type, String entity, String start, String end, + String colo, String doAsUser); + public abstract int getStatus(String doAsUser); + + public abstract String getThreadDump(String doAs); + + public abstract LineageGraphResult getEntityLineageGraph(String pipeline, String doAs); + + public abstract String getDimensionList(String dimensionType, String cluster, String doAs); + + public abstract String getReplicationMetricsDimensionList(String schedEntityType, String schedEntityName, + Integer numResults, String doAs); + + public abstract String getDimensionRelations(String dimensionType, String dimensionName, String doAs); + + public abstract String getVertex(String id, String doAs); + + public abstract String getVertices(String key, String value, String doAs); + + public abstract String getVertexEdges(String id, String direction, String doAs); + + public abstract String getEdge(String id, String doAs); } http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/client/src/main/java/org/apache/falcon/client/FalconCLIConstants.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/falcon/client/FalconCLIConstants.java b/client/src/main/java/org/apache/falcon/client/FalconCLIConstants.java new file mode 100644 index 0000000..04f1599 --- /dev/null +++ b/client/src/main/java/org/apache/falcon/client/FalconCLIConstants.java @@ -0,0 +1,220 @@ +/** + * 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.client; + +/** +* FalconCLI Constants. +*/ +public final class FalconCLIConstants { + private FalconCLIConstants(){ + + } + public static final String ENV_FALCON_DEBUG = "FALCON_DEBUG"; + public static final String DEFINITION_OPT = "definition"; + public static final String LOOKUP_OPT = "lookup"; + public static final String SLA_MISS_ALERT_OPT = "slaAlert"; + public static final String TOUCH_OPT = "touch"; + public static final String ADMIN_CMD = "admin"; + public static final String HELP_CMD = "help"; + public static final String METADATA_CMD = "metadata"; + public static final String ENTITY_CMD = "entity"; + public static final String INSTANCE_CMD = "instance"; + public static final String EXTENSION_CMD = "extension"; + public static final String SAFE_MODE_OPT = "setsafemode"; + public static final String VERSION_OPT = "version"; + public static final String SUBMIT_OPT = "submit"; + public static final String SUBMIT_ONLY_OPT = "submitOnly"; + public static final String UPDATE_OPT = "update"; + public static final String UPDATE_CLUSTER_DEPENDENTS_OPT = "updateClusterDependents"; + public static final String DELETE_OPT = "delete"; + public static final String SCHEDULE_OPT = "schedule"; + public static final String CURRENT_COLO = "current.colo"; + public static final String CLIENT_PROPERTIES = "/client.properties"; + public static final String RELATIONS_OPT = "relations"; + public static final String PIPELINE_OPT = "pipeline"; + public static final String NAME_OPT = "name"; + public static final String VERSION_OPT_DESCRIPTION = "show Falcon server build version"; + public static final String STACK_OPTION_DESCRIPTION = "show the thread stack dump"; + public static final String FALCON_URL = "FALCON_URL"; + public static final String STACK_OPTION = "stack"; + public static final String SUBMIT_OPT_DESCRIPTION = "Submits an entity xml to Falcon"; + public static final String UPDATE_OPT_DESCRIPTION = "Updates an existing entity"; + public static final String DELETE_OPT_DESCRIPTION = "Deletes an entity in Falcon, and kills its instance from " + + "workflow engine"; + public static final String SUBMIT_AND_SCHEDULE_OPT = "submitAndSchedule"; + public static final String SUBMIT_AND_SCHEDULE_OPT_DESCRIPTION = "Submits an entity to Falcon and " + + "schedules it immediately"; + public static final String VALIDATE_OPT = "validate"; + public static final String VALIDATE_OPT_DESCRIPTION = "Validates an entity based on the entity type"; + public static final String DEFINITION_OPT_DESCRIPTION = "Gets the Definition of entity"; + public static final String SLA_MISS_ALERT_OPT_DESCRIPTION = "Get missing feed instances which missed SLA"; + + + public static final String LOOKUP_OPT_DESCRIPTION = "Lookup a feed given its instance's path"; + public static final String PATH_OPT = "path"; + public static final String PATH_OPT_DESCRIPTION = "Path for a feed's instance"; + public static final String TOUCH_OPT_DESCRIPTION = "Force update the entity in workflow engine" + + "(even without any changes to entity)"; + public static final String PROPS_OPT = "properties"; + public static final String PROPS_OPT_DESCRIPTION = "User supplied comma separated key value properties"; + public static final String FIELDS_OPT = "fields"; + public static final String FIELDS_OPT_DESCRIPTION = "Entity fields to show for a request"; + public static final String TAGS_OPT = "tags"; + public static final String TAGS_OPT_DESCRIPTION = "Filter returned entities by the specified tags"; + public static final String NUM_INSTANCES_OPT = "numInstances"; + public static final String NUM_INSTANCES_OPT_DESCRIPTION = "Number of instances to return per entity " + + "summary request"; + public static final String NAMESEQ_OPT = "nameseq"; + public static final String NAMESEQ_OPT_DESCRIPTION = "Subsequence of entity name"; + public static final String TAGKEYS_OPT = "tagkeys"; + public static final String TAGKEYS_OPT_DESCRIPTION = "Keywords in tags"; + public static final String SHOWSCHEDULER_OPT = "showScheduler"; + public static final String SHOWSCHEDULER_OPT_DESCRIPTION = "To return the scheduler " + + "on which the entity is scheduled."; + + public static final String DEBUG_OPTION = "debug"; + public static final String URL_OPTION = "url"; + public static final String TYPE_OPT = "type"; + public static final String COLO_OPT = "colo"; + public static final String CLUSTER_OPT = "cluster"; + public static final String FEED_OPT = "feed"; + public static final String PROCESS_OPT = "process"; + public static final String ENTITY_NAME_OPT = "name"; + public static final String FILE_PATH_OPT = "file"; + public static final String SUSPEND_OPT = "suspend"; + public static final String RESUME_OPT = "resume"; + public static final String STATUS_OPT = "status"; + public static final String SUMMARY_OPT = "summary"; + public static final String DEPENDENCY_OPT = "dependency"; + public static final String SKIPDRYRUN_OPT = "skipDryRun"; + public static final String FILTER_BY_OPT = "filterBy"; + public static final String ORDER_BY_OPT = "orderBy"; + public static final String SORT_ORDER_OPT = "sortOrder"; + public static final String OFFSET_OPT = "offset"; + public static final String NUM_RESULTS_OPT = "numResults"; + public static final String START_OPT = "start"; + public static final String END_OPT = "end"; + public static final String DO_AS_OPT = "doAs"; + public static final String RUNNING_OPT_DESCRIPTION = "Gets running process instances for a given process"; + public static final String LIST_OPT_DESCRIPTION = "Gets all instances for a given entity in the range start " + + "time and optional end time"; + public static final String STATUS_OPT_DESCRIPTION = "Gets status of process instances for a given process in" + + " the range start time and optional end time"; + public static final String SUMMARY_OPT_DESCRIPTION = "Gets summary of instances for a given process in the" + + " range start time and optional end time"; + public static final String KILL_OPT_DESCRIPTION = "Kills active process instances for a given process in the" + + " range start time and optional end time"; + public static final String SUSPEND_OPT_DESCRIPTION = "Suspends active process instances for a given process in" + + " the range start time and optional end time"; + public static final String RESUME_OPT_DESCRIPTION = "Resumes suspended process instances for a given" + + " process in the range start time and optional end time"; + public static final String RERUN_OPT_DESCRIPTION = "Reruns process instances for a given process in the" + + " range start time and optional end time and overrides properties present in job.properties file"; + public static final String LOG_OPT_DESCRIPTION = "Logs print the logs for process instances for a given" + + " process in the range start time and optional end time"; + public static final String PARARMS_OPT_DESCRIPTION = "Displays the workflow parameters for a given instance" + + " of specified nominal time start time represents nominal time and end time is not considered"; + public static final String LISTING_OPT_DESCRIPTION = "Displays feed listing and their status between a" + + " start and end time range."; + public static final String DEPENDENCY_OPT_DESCRIPTION = "Displays dependent instances for a specified" + + " instance."; + public static final String TRIAGE_OPT_DESCRIPTION = "Triage a feed or process instance and find the failures" + + " in it's lineage."; + public static final String URL_OPTION_DESCRIPTION = "Falcon URL"; + public static final String START_OPT_DESCRIPTION = "Start time is required for commands, status, kill, " + + "suspend, resume and re-runand it is nominal time while displaying workflow params"; + public static final String END_OPT_DESCRIPTION = "End time is optional for commands, status, kill, suspend, " + + "resume and re-run; if not specified then current time is considered as end time"; + public static final String RUNID_OPT_DESCRIPTION = "Instance runid is optional and user can specify the " + + "runid, defaults to 0"; + public static final String CLUSTERS_OPT_DESCRIPTION = "clusters is optional for commands kill, suspend and " + + "resume, should not be specified for other commands"; + public static final String SOURCECLUSTER_OPT_DESCRIPTION = " source cluster is optional for commands kill, " + + "suspend and resume, should not be specified for other commands (required for only feed)"; + public static final String FILE_PATH_OPT_DESCRIPTION = "Path to job.properties file is required for rerun " + + "command, it should contain name=value pair for properties to override for rerun"; + public static final String TYPE_OPT_DESCRIPTION = "Entity type, can be feed or process xml"; + public static final String ENTITY_NAME_OPT_DESCRIPTION = "Entity name, can be feed or process name"; + public static final String COLO_OPT_DESCRIPTION = "Colo on which the cmd has to be executed"; + public static final String LIFECYCLE_OPT_DESCRIPTION = "describes life cycle of entity , for feed it can be " + + "replication/retention and for process it can be execution"; + public static final String FILTER_BY_OPT_DESCRIPTION = "Filter returned instances by the specified fields"; + public static final String ORDER_BY_OPT_DESCRIPTION = "Order returned instances by this field"; + public static final String SORT_ORDER_OPT_DESCRIPTION = "asc or desc order for results"; + public static final String OFFSET_OPT_DESCRIPTION = "Start returning instances from this offset"; + public static final String FORCE_RERUN_FLAG_DESCRIPTION = "Flag to forcefully rerun entire workflow " + + "of an instance"; + public static final String DO_AS_OPT_DESCRIPTION = "doAs user"; + public static final String INSTANCE_TIME_OPT_DESCRIPTION = "Time for an instance"; + public static final String ALL_ATTEMPTS_DESCRIPTION = "To get all attempts of corresponding instances"; + public static final String FORCE_RERUN_FLAG = "force"; + public static final String INSTANCE_TIME_OPT = "instanceTime"; + public static final String RUNNING_OPT = "running"; + public static final String KILL_OPT = "kill"; + public static final String RERUN_OPT = "rerun"; + public static final String LOG_OPT = "logs"; + public static final String CLUSTERS_OPT = "clusters"; + public static final String SOURCECLUSTER_OPT = "sourceClusters"; + public static final String LIFECYCLE_OPT = "lifecycle"; + public static final String PARARMS_OPT = "params"; + public static final String LISTING_OPT = "listing"; + public static final String TRIAGE_OPT = "triage"; + public static final String SKIPDRYRUN_OPT_DESCRIPTION = "skip dry run in workflow engine"; + public static final String SCHEDULE_OPT_DESCRIPTION = "Schedules a submited entity in Falcon"; + public static final String ALL_ATTEMPTS = "allAttempts"; + public static final String RUNID_OPT = "runid"; + public static final String INSTANCE_STATUS_OPT = "instanceStatus"; + public static final String SEARCH_OPT = "search"; + + + // Discovery Commands + public static final String DISCOVERY_OPT = "discovery"; + public static final String LIST_OPT = "list"; + + // Lineage Commands + public static final String LINEAGE_OPT = "lineage"; + public static final String VERTEX_CMD = "vertex"; + public static final String VERTICES_CMD = "vertices"; + public static final String VERTEX_EDGES_CMD = "edges"; + public static final String EDGE_CMD = "edge"; + public static final String ID_OPT = "id"; + public static final String KEY_OPT = "key"; + public static final String VALUE_OPT = "value"; + public static final String DIRECTION_OPT = "direction"; + + public static final String DISCOVERY_OPT_DESCRIPTION = "Discover falcon metadata relations"; + public static final String LINEAGE_OPT_DESCRIPTION = "Get falcon metadata lineage information"; + public static final String PIPELINE_OPT_DESCRIPTION = "Get lineage graph for the entities in a pipeline"; + public static final String RELATIONS_OPT_DESCRIPTION = "List all relations for a dimension"; + public static final String NAME_OPT_DESCRIPTION = "Dimension name"; + public static final String CLUSTER_OPT_DESCRIPTION = "Cluster name"; + public static final String FEED_OPT_DESCRIPTION = "Feed Entity name"; + public static final String PROCESS_OPT_DESCRIPTION = "Process Entity name"; + public static final String NUM_RESULTS_OPT_DESCRIPTION = "Number of results to return per request"; + public static final String VERTEX_CMD_DESCRIPTION = "show the vertices"; + public static final String VERTICES_CMD_DESCRIPTION = "show the vertices"; + public static final String VERTEX_EDGES_CMD_DESCRIPTION = "show the edges for a given vertex"; + public static final String EDGE_CMD_DESCRIPTION = "show the edges"; + public static final String ID_OPT_DESCRIPTION = "vertex or edge id"; + public static final String KEY_OPT_DESCRIPTION = "key property"; + public static final String VALUE_OPT_DESCRIPTION = "value property"; + public static final String DIRECTION_OPT_DESCRIPTION = "edge direction property"; + public static final String DEBUG_OPTION_DESCRIPTION = "Use debug mode to see debugging statements on stdout"; + public static final String DO_AS_DESCRIPTION = "doAs user"; +} http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/client/src/main/java/org/apache/falcon/client/FalconClient.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/falcon/client/FalconClient.java b/client/src/main/java/org/apache/falcon/client/FalconClient.java index 4716019..8f77fad 100644 --- a/client/src/main/java/org/apache/falcon/client/FalconClient.java +++ b/client/src/main/java/org/apache/falcon/client/FalconClient.java @@ -26,7 +26,6 @@ import com.sun.jersey.client.urlconnection.HTTPSProperties; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.net.util.TrustManagerUtils; -import org.apache.falcon.FalconCLIConstants; import org.apache.falcon.LifeCycle; import org.apache.falcon.entity.v0.DateValidator; import org.apache.falcon.entity.v0.Entity; @@ -540,7 +539,6 @@ public class FalconClient extends AbstractFalconClient { .addQueryParam(DO_AS_OPT, doAsUser).call(operation); return getResponse(APIResult.class, clientResponse); } - public InstancesResult getRunningInstances(String type, String entity, String colo, List<LifeCycle> lifeCycles, String filterBy, String orderBy, String sortOrder, Integer offset, Integer numResults, String doAsUser) { @@ -551,7 +549,6 @@ public class FalconClient extends AbstractFalconClient { .addQueryParam(LIFECYCLE, lifeCycles, type).addQueryParam(USER, doAsUser).call(Instances.RUNNING); return getResponse(InstancesResult.class, clientResponse); } - @Override public InstancesResult getStatusOfInstances(String type, String entity, String start, String end, String colo, List<LifeCycle> lifeCycles, String filterBy, String orderBy, @@ -759,8 +756,7 @@ public class FalconClient extends AbstractFalconClient { return stream; } - private <T> T getResponse(Class<T> clazz, - ClientResponse clientResponse) { + private <T> T getResponse(Class<T> clazz, ClientResponse clientResponse) { printClientResponse(clientResponse); checkIfSuccessful(clientResponse); return clientResponse.getEntity(clazz); http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/common/pom.xml ---------------------------------------------------------------------- diff --git a/common/pom.xml b/common/pom.xml index 5b0188f..96cb7f5 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -211,12 +211,6 @@ </dependency> <dependency> - <groupId>javax.validation</groupId> - <artifactId>validation-api</artifactId> - <version>${javax-validation.version}</version> - </dependency> - - <dependency> <groupId>org.apache.spark</groupId> <artifactId>spark-core_2.10</artifactId> <exclusions> @@ -241,6 +235,11 @@ <version>0.9.3</version> <scope>test</scope> </dependency> + <dependency> + <groupId>javax.validation</groupId> + <artifactId>validation-api</artifactId> + <version>${javax-validation.version}</version> + </dependency> </dependencies> <build> http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 7284277..fe94261 100644 --- a/pom.xml +++ b/pom.xml @@ -370,6 +370,7 @@ <module>falcon-ui</module> <module>build-tools</module> <module>client</module> + <module>shell</module> <module>cli</module> <module>metrics</module> <module>titan</module> http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/shell/pom.xml ---------------------------------------------------------------------- diff --git a/shell/pom.xml b/shell/pom.xml new file mode 100644 index 0000000..fea6b54 --- /dev/null +++ b/shell/pom.xml @@ -0,0 +1,196 @@ +<?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. + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.falcon</groupId> + <artifactId>falcon-main</artifactId> + <version>0.11-SNAPSHOT</version> + </parent> + <artifactId>falcon-shell</artifactId> + <name>Apache Falcon Shell</name> + + <dependencies> + + <dependency> + <groupId>org.apache.falcon</groupId> + <artifactId>falcon-client</artifactId> + </dependency> + + <dependency> + <groupId>commons-net</groupId> + <artifactId>commons-net</artifactId> + </dependency> + + <dependency> + <groupId>commons-codec</groupId> + <artifactId>commons-codec</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + </dependency> + + <dependency> + <groupId>com.sun.jersey</groupId> + <artifactId>jersey-client</artifactId> + </dependency> + + <dependency> + <groupId>com.sun.jersey</groupId> + <artifactId>jersey-core</artifactId> + </dependency> + + <dependency> + <groupId>com.sun.jersey</groupId> + <artifactId>jersey-json</artifactId> + </dependency> + + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </dependency> + + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </dependency> + + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.4</version> + </dependency> + + <dependency> + <groupId>jline</groupId> + <artifactId>jline</artifactId> + </dependency> + + <dependency> + <groupId>com.github.stephenc.findbugs</groupId> + <artifactId>findbugs-annotations</artifactId> + </dependency> + + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + </dependency> + + <dependency> + <groupId>org.springframework.shell</groupId> + <artifactId>spring-shell</artifactId> + </dependency> + + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + <version>4.0.3.RELEASE</version> + </dependency> + + <dependency> + <groupId>com.google.code.findbugs</groupId> + <artifactId>jsr305</artifactId> + <version>3.0.0</version> + </dependency> + + </dependencies> + + <build> + <plugins> + <!-- make the jar executable by adding a Main-Class and Class-Path to the manifest --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>2.4.1</version> + <configuration> + <shadedArtifactAttached>false</shadedArtifactAttached> + <createDependencyReducedPom>false</createDependencyReducedPom> + <artifactSet> + <includes> + <include>org.apache.hadoop:hadoop-auth</include> + <include>org.apache.hadoop.security.authentication.client.Authenticator</include>> + <include>org.apache.falcon:*</include> + <include>org.apache.commons:*</include> + <include>commons-logging:*</include> + <include>commons-net:*</include> + <include>commons-codec:*</include> + <include>commons-io:*</include> + <include>jline:*</include> + <include>org.slf4j:*</include> + <include>log4j:*</include> + <include>com.sun.jersey:*</include> + <include>org.springframework:*</include> + <include>org.springframework.shell:*</include> + </includes> + </artifactSet> + <filters> + <filter> + <artifact>*:*</artifact> + <excludes> + <exclude>META-INF/*.SF</exclude> + <exclude>META-INF/*.DSA</exclude> + <exclude>META-INF/*.RSA</exclude> + </excludes> + </filter> + </filters> + </configuration> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <transformers> + <transformer + implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> + <transformer + implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> + </transformer> + <transformer + implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer"/> + <transformer + implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer"/> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.rat</groupId> + <artifactId>apache-rat-plugin</artifactId> + <configuration> + <excludes> + <exclude>falcon-cli-hist.log</exclude> + </excludes> + </configuration> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/shell/src/main/java/org/apache/falcon/shell/commands/BaseFalconCommands.java ---------------------------------------------------------------------- diff --git a/shell/src/main/java/org/apache/falcon/shell/commands/BaseFalconCommands.java b/shell/src/main/java/org/apache/falcon/shell/commands/BaseFalconCommands.java new file mode 100644 index 0000000..5d6467b --- /dev/null +++ b/shell/src/main/java/org/apache/falcon/shell/commands/BaseFalconCommands.java @@ -0,0 +1,155 @@ +/** + * 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.commons.lang3.StringUtils; +import org.apache.falcon.client.AbstractFalconClient; +import org.apache.falcon.client.FalconCLIException; +import org.apache.falcon.client.FalconClient; +import org.springframework.shell.core.ExecutionProcessor; +import org.springframework.shell.event.ParseResult; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import static org.apache.falcon.client.FalconCLIConstants.CURRENT_COLO; +import static org.apache.falcon.client.FalconCLIConstants.FALCON_URL; + +/** + * Common code for all falcon command classes. + */ +public class BaseFalconCommands implements ExecutionProcessor { + protected static final String FALCON_URL_PROPERTY = "falcon.url"; + private static final String DO_AS = "DO_AS"; + private static final String DO_AS_PROPERTY = "do.as"; + private static final String SHELL_PROPERTIES = "/shell.properties"; + protected static final String FALCON_URL_ABSENT = "Failed to get falcon url from environment or client properties"; + private static Properties clientProperties; + private static Properties backupProperties = new Properties(); + private static AbstractFalconClient client; + + static { + clientProperties = getShellProperties(); + } + + + public static Properties getShellProperties() { + if (clientProperties == null) { + InputStream inputStream = null; + Properties prop = new Properties(System.getProperties()); + prop.putAll(backupProperties); + 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); + } + String urlOverride = System.getenv(FALCON_URL); + if (urlOverride != null) { + prop.setProperty(FALCON_URL_PROPERTY, urlOverride); + } + if (prop.getProperty(FALCON_URL_PROPERTY) == null) { + throw new FalconCLIException(FALCON_URL_ABSENT); + } + String doAsOverride = System.getenv(DO_AS); + if (doAsOverride != null) { + prop.setProperty(DO_AS_PROPERTY, doAsOverride); + } + clientProperties = prop; + backupProperties.clear(); + } + return clientProperties; + } + + static void setClientProperty(String key, String value) { + Properties props; + try { + props = getShellProperties(); + } catch (FalconCLIException e) { + props = backupProperties; + } + if (StringUtils.isBlank(value)) { + props.remove(key); + } else { + props.setProperty(key, value); + } + // Re-load client in the next call + client = null; + } + + public static AbstractFalconClient getFalconClient() { + if (client == null) { + client = new FalconClient(getShellProperties().getProperty(FALCON_URL_PROPERTY), getShellProperties()); + } + return client; + } + + public static void setFalconClient(AbstractFalconClient abstractFalconClient) { + client = abstractFalconClient; + } + + protected String getColo(String colo) { + if (colo == null) { + Properties prop = getShellProperties(); + colo = prop.getProperty(CURRENT_COLO, "*"); + } + return colo; + } + + protected String getDoAs() { + return getShellProperties().getProperty(DO_AS_PROPERTY); + } + + @Override + public ParseResult beforeInvocation(ParseResult parseResult) { + Object[] args = parseResult.getArguments(); + if (args != null) { + boolean allEqual = true; + for (int i = 1; i < args.length; i++) { + allEqual &= args[0].equals(args[i]); + } + if (allEqual) { + if (args[0] instanceof String) { + String[] split = ((String) args[0]).split("\\s+"); + Object[] newArgs = new String[args.length]; + System.arraycopy(split, 0, newArgs, 0, split.length); + parseResult = new ParseResult(parseResult.getMethod(), parseResult.getInstance(), newArgs); + } + } + } + return parseResult; + } + + @Override + public void afterReturningInvocation(ParseResult parseResult, Object o) { + + } + + @Override + public void afterThrowingInvocation(ParseResult parseResult, Throwable throwable) { + } +} http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/shell/src/main/java/org/apache/falcon/shell/commands/FalconAdminCommands.java ---------------------------------------------------------------------- diff --git a/shell/src/main/java/org/apache/falcon/shell/commands/FalconAdminCommands.java b/shell/src/main/java/org/apache/falcon/shell/commands/FalconAdminCommands.java new file mode 100644 index 0000000..e560248 --- /dev/null +++ b/shell/src/main/java/org/apache/falcon/shell/commands/FalconAdminCommands.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.commands; + +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.stereotype.Component; + +import static org.apache.falcon.client.FalconCLIConstants.STACK_OPTION; +import static org.apache.falcon.client.FalconCLIConstants.STACK_OPTION_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.VERSION_OPT; +import static org.apache.falcon.client.FalconCLIConstants.VERSION_OPT_DESCRIPTION; + +/** + * Admin commands. + */ +@Component +public class FalconAdminCommands extends BaseFalconCommands { + public static final String ADMIN_PREFIX = "admin"; + public static final String ADMIN_COMMAND_PREFIX = ADMIN_PREFIX + " "; + + @CliCommand(value = {STATUS_OPT, ADMIN_COMMAND_PREFIX + STATUS_OPT}, help = STATUS_OPT_DESCRIPTION) + public String status( + ) { + int status = getFalconClient().getStatus(getDoAs()); + String url = getShellProperties().getProperty(BaseFalconCommands.FALCON_URL_PROPERTY); + if (status != 200) { + throw new RuntimeException("Falcon server is not fully operational (on " + + url + "). " + + "Please check log files."); + } else { + return ("Falcon server is running (on " + url + ")"); + } + } + + @CliCommand(value = {ADMIN_COMMAND_PREFIX + STACK_OPTION}, help = STACK_OPTION_DESCRIPTION) + public String stack( + ) { + return getFalconClient().getThreadDump(getDoAs()); + } + + @CliCommand(value = {ADMIN_COMMAND_PREFIX + VERSION_OPT}, help = VERSION_OPT_DESCRIPTION) + public String version( + ) { + return getFalconClient().getVersion(getDoAs()); + } +} http://git-wip-us.apache.org/repos/asf/falcon/blob/da767c2f/shell/src/main/java/org/apache/falcon/shell/commands/FalconConnectionCommands.java ---------------------------------------------------------------------- diff --git a/shell/src/main/java/org/apache/falcon/shell/commands/FalconConnectionCommands.java b/shell/src/main/java/org/apache/falcon/shell/commands/FalconConnectionCommands.java new file mode 100644 index 0000000..d14e916 --- /dev/null +++ b/shell/src/main/java/org/apache/falcon/shell/commands/FalconConnectionCommands.java @@ -0,0 +1,58 @@ +/** + * 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.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; +import org.springframework.stereotype.Component; + +import javax.annotation.Nonnull; + +/** + * Connection Commands. + */ +@Component +public class FalconConnectionCommands extends BaseFalconCommands { + + @CliCommand(value = "get", help = "get properties") + public String getParameter(@CliOption(key = {"", "key"}, mandatory = false, help = "<key>") final String key) { + if (StringUtils.isBlank(key)) { + return BaseFalconCommands.getShellProperties().toString(); + } + return getShellProperties().getProperty(key); + } + + @CliCommand(value = "set", help = "set properties") + public void setParameter(@CliOption(key = {"", "keyval"}, mandatory = true, help = "<key-val>") + @Nonnull final String keyVal) { + String[] kvArray = keyVal.split("="); + String key = ""; + String value = ""; + if (kvArray.length > 0) { + key = kvArray[0]; + } + if (kvArray.length > 1) { + value = kvArray[1]; + } + setClientProperty(key, value); + } +}
