You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by is...@apache.org on 2013/07/10 18:52:12 UTC
[37/45] fixing component version issues and adding currently
refactored components to the parent pom
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.activation/src/main/java/org/apache/stratos/activation/activation/utils/Util.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.activation/src/main/java/org/apache/stratos/activation/activation/utils/Util.java b/components/org.apache.stratos.activation/src/main/java/org/apache/stratos/activation/activation/utils/Util.java
new file mode 100644
index 0000000..98bb716
--- /dev/null
+++ b/components/org.apache.stratos.activation/src/main/java/org/apache/stratos/activation/activation/utils/Util.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2005-2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. 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.stratos.activation.activation.utils;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.base.ServerConfiguration;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.registry.core.service.RegistryService;
+import org.wso2.carbon.registry.core.session.UserRegistry;
+import org.wso2.carbon.user.core.service.RealmService;
+
+/**
+ * Utilities for the Service Activation Module for Tenants.
+ */
+public class Util {
+
+ private static RegistryService registryService = null;
+ private static RealmService realmService = null;
+ private static String serviceName = null;
+ private static final Log log = LogFactory.getLog(Util.class);
+
+ private static boolean cloudServiceInfoPathSanityChecked = false;
+
+ /**
+ * Stores an instance of the Registry Service that can be used to access the registry.
+ *
+ * @param service the Registry Service instance.
+ */
+ public static synchronized void setRegistryService(RegistryService service) {
+ if (registryService == null) {
+ registryService = service;
+ }
+ }
+
+ /**
+ * Method to retrieve the Registry Service instance.
+ *
+ * @return the Registry Service instance if it has been stored or null if not.
+ */
+ @SuppressWarnings("unused")
+ public static RegistryService getRegistryService() {
+ return registryService;
+ }
+
+ /**
+ * Stores an instance of the Realm Service that can be used to access the user realm.
+ *
+ * @param service the Realm Service instance.
+ */
+ public static synchronized void setRealmService(RealmService service) {
+ if (realmService == null) {
+ realmService = service;
+ }
+ }
+
+ /**
+ * Method to retrieve the Realm Service instance.
+ *
+ * @return the Realm Service instance if it has been stored or null if not.
+ */
+ public static RealmService getRealmService() {
+ return realmService;
+ }
+
+ private static UserRegistry getSuperTenantGovernanceSystemRegistry() throws RegistryException {
+ return registryService.getGovernanceSystemRegistry();
+ }
+
+// /**
+// * Method to determine whether the given cloud service is active.
+// *
+// * @param cloudServiceName the name of the cloud service.
+// * @param tenantId the tenant identifier.
+// * @param systemRegistry the super tenant's governance system registry
+// *
+// * @return true if the service is active or false if not.
+// * @throws Exception if the operation failed.
+// */
+// public static boolean isCloudServiceActive(String cloudServiceName,
+// int tenantId, UserRegistry systemRegistry)
+// throws Exception {
+// // The cloud manager is always active
+// if (StratosConstants.CLOUD_MANAGER_SERVICE.equals(cloudServiceName)) {
+// return true;
+// }
+//
+// if(!cloudServiceInfoPathSanityChecked) {
+// if(!systemRegistry.resourceExists(StratosConstants.CLOUD_SERVICE_INFO_STORE_PATH)) {
+// throw new RuntimeException("Cloud services list resource " +
+// StratosConstants.CLOUD_SERVICE_INFO_STORE_PATH + " does not exist");
+// }
+// cloudServiceInfoPathSanityChecked = true;
+// }
+//
+// String cloudServiceInfoPath = StratosConstants.CLOUD_SERVICE_INFO_STORE_PATH +
+// RegistryConstants.PATH_SEPARATOR + tenantId +
+// RegistryConstants.PATH_SEPARATOR + cloudServiceName;
+// Resource cloudServiceInfoResource;
+// if (systemRegistry.resourceExists(cloudServiceInfoPath)) {
+// cloudServiceInfoResource = systemRegistry.get(cloudServiceInfoPath);
+// String isActiveStr =
+// cloudServiceInfoResource.getProperty(StratosConstants.CLOUD_SERVICE_IS_ACTIVE_PROP_KEY);
+// return Boolean.toString(true).equals(isActiveStr);
+// }
+// return false;
+// }
+//
+
+ /**
+ * Method to obtain the name of the cloud service in which this module is running.
+ *
+ * @return the name of the service as defined in the server configuration.
+ */
+ public static String getServiceName() {
+ if (serviceName == null) {
+ serviceName = ServerConfiguration.getInstance().getFirstProperty("Name");
+ }
+ return serviceName;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.activation/src/main/resources/META-INF/module.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.activation/src/main/resources/META-INF/module.xml b/components/org.apache.stratos.activation/src/main/resources/META-INF/module.xml
new file mode 100644
index 0000000..220e0e5
--- /dev/null
+++ b/components/org.apache.stratos.activation/src/main/resources/META-INF/module.xml
@@ -0,0 +1,33 @@
+<!--
+ ~ Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ ~
+ ~ WSO2 Inc. 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.
+ -->
+<module name="activation" class="org.apache.stratos.activation.activation.module.ActivationModule">
+ <InFlow>
+ <handler name="InFlowActivationHandler"
+ class="org.apache.stratos.activation.activation.module.ActivationHandler">
+ <order phase="Validation" phaseFirst="true"/>
+ </handler>
+ </InFlow>
+
+ <InFaultFlow>
+ <handler name="FaultInFlowActivationHandler"
+ class="org.apache.stratos.activation.activation.module.ActivationHandler">
+ <order phase="Validation" phaseFirst="true"/>
+ </handler>
+ </InFaultFlow>
+ <parameter name="adminModule" locked="true">true</parameter>
+</module>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.activation/src/main/resources/META-INF/services.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.activation/src/main/resources/META-INF/services.xml b/components/org.apache.stratos.activation/src/main/resources/META-INF/services.xml
new file mode 100644
index 0000000..01c4d91
--- /dev/null
+++ b/components/org.apache.stratos.activation/src/main/resources/META-INF/services.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ !
+ ! Copyright (c) 2005-2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ !
+ ! WSO2 Inc. 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.
+ !-->
+<serviceGroup>
+ <service name="ActivationService" scope="transportsession">
+ <transports>
+ <transport>https</transport>
+ </transports>
+ <parameter name="ServiceClass" locked="false">
+ org.apache.stratos.activation.activation.service.ActivationService
+ </parameter>
+ </service>
+ <parameter name="hiddenService" locked="true">true</parameter>
+</serviceGroup>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.mgt.cli/2.1.3/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.cli/2.1.3/pom.xml b/components/org.apache.stratos.adc.mgt.cli/2.1.3/pom.xml
deleted file mode 100644
index e82ce78..0000000
--- a/components/org.apache.stratos.adc.mgt.cli/2.1.3/pom.xml
+++ /dev/null
@@ -1,125 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- ~ Copyright (c) 2009-2010, WSO2 Inc. (http://www.wso2.org) All Rights
- Reserved. ~ ~ 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. -->
-<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/maven-v4_0_0.xsd">
-
- <parent>
- <groupId>org.apache.stratos</groupId>
- <artifactId>stratos-components-parent</artifactId>
- <version>3.0.0-SNAPSHOT</version>
- <relativePath>../../pom.xml</relativePath>
- </parent>
-
- <modelVersion>4.0.0</modelVersion>
- <artifactId>org.apache.stratos.adc.mgt.cli</artifactId>
- <version>2.1.3</version>
- <packaging>jar</packaging>
- <name>Apache Stratos - ADC Management CLI</name>
- <description>ADC management CLI bundle</description>
- <url>http://apache.org</url>
-
- <properties>
- <slf4j.version>1.7.5</slf4j.version>
- </properties>
-
- <dependencies>
- <!-- <dependency>
- <groupId>org.wso2.carbon</groupId>
- <artifactId>org.wso2.carbon.ui</artifactId>
- </dependency> -->
- <!-- Adding HttpClient dependencies. Those were resolved with above one -->
- <dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>${commons-httpclient.version}</version>
- </dependency>
- <dependency>
- <groupId>org.wso2.securevault</groupId>
- <artifactId>org.wso2.securevault</artifactId>
- <version>1.0.0-wso2v2</version>
- </dependency>
- <dependency>
- <groupId>org.apache.httpcomponents.wso2</groupId>
- <artifactId>httpcore</artifactId>
- <version>4.1.0-wso2v1</version>
- </dependency>
- <dependency>
- <groupId>org.apache.stratos</groupId>
- <artifactId>org.apache.stratos.adc.mgt.stub</artifactId>
- <version>4.1.3</version>
- </dependency>
- <dependency>
- <groupId>commons-cli</groupId>
- <artifactId>commons-cli</artifactId>
- <version>1.2</version>
- </dependency>
- <dependency>
- <groupId>jline</groupId>
- <artifactId>jline</artifactId>
- <version>2.11</version>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <version>3.1</version>
- </dependency>
- <dependency>
- <groupId>commons-validator</groupId>
- <artifactId>commons-validator</artifactId>
- <version>1.4.0</version>
- </dependency>
- <!-- Logging -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>${slf4j.version}</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>${slf4j.version}</version>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
- <version>2.1</version>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-assembly-plugin</artifactId>
- <configuration>
- <archive>
- <manifest>
- <mainClass>org.apache.stratos.adc.mgt.cli.CliTool</mainClass>
- </manifest>
- </archive>
- <descriptors>
- <descriptor>src/main/assembly/src.xml</descriptor>
- </descriptors>
- </configuration>
- <executions>
- <execution>
- <id>make-assembly</id> <!-- this is used for inheritance merges -->
- <phase>package</phase> <!-- bind to the packaging phase -->
- <goals>
- <goal>single</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/assembly/src.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/assembly/src.xml b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/assembly/src.xml
deleted file mode 100644
index ec41ef1..0000000
--- a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/assembly/src.xml
+++ /dev/null
@@ -1,36 +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.
- -->
-<assembly
- xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
- <id>Tool</id>
- <formats>
- <format>jar</format>
- </formats>
- <includeBaseDirectory>false</includeBaseDirectory>
- <dependencySets>
- <dependencySet>
- <outputDirectory>/</outputDirectory>
- <useProjectArtifact>true</useProjectArtifact>
- <unpack>true</unpack>
- <scope>runtime</scope>
- </dependencySet>
- </dependencySets>
-</assembly>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/Main.iml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/Main.iml b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/Main.iml
deleted file mode 100644
index 9a9b340..0000000
--- a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/Main.iml
+++ /dev/null
@@ -1,204 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module type="JAVA_MODULE" version="4">
- <component name="NewModuleRootManager" inherit-compiler-output="true">
- <exclude-output />
- <content url="file://$MODULE_DIR$">
- <sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
- </content>
- <orderEntry type="inheritedJdk" />
- <orderEntry type="sourceFolder" forTests="false" />
- </component>
- <component name="org.twodividedbyzero.idea.findbugs">
- <option name="_basePreferences">
- <map>
- <entry key="property.analysisEffortLevel" value="default" />
- <entry key="property.analyzeAfterCompile" value="false" />
- <entry key="property.annotationGutterIconEnabled" value="true" />
- <entry key="property.annotationSuppressWarningsClass" value="edu.umd.cs.findbugs.annotations.SuppressWarnings" />
- <entry key="property.annotationTextRangeMarkupEnabled" value="true" />
- <entry key="property.exportAsHtml" value="true" />
- <entry key="property.exportAsXml" value="true" />
- <entry key="property.exportBaseDir" value="" />
- <entry key="property.exportCreateArchiveDir" value="false" />
- <entry key="property.exportOpenBrowser" value="true" />
- <entry key="property.minPriorityToReport" value="Medium" />
- <entry key="property.runAnalysisInBackground" value="false" />
- <entry key="property.showHiddenDetectors" value="false" />
- <entry key="property.toolWindowToFront" value="true" />
- </map>
- </option>
- <option name="_detectors">
- <map>
- <entry key="AppendingToAnObjectOutputStream" value="true" />
- <entry key="AtomicityProblem" value="true" />
- <entry key="BadAppletConstructor" value="false" />
- <entry key="BadResultSetAccess" value="true" />
- <entry key="BadSyntaxForRegularExpression" value="true" />
- <entry key="BadUseOfReturnValue" value="true" />
- <entry key="BadlyOverriddenAdapter" value="true" />
- <entry key="BooleanReturnNull" value="true" />
- <entry key="BuildInterproceduralCallGraph" value="false" />
- <entry key="BuildObligationPolicyDatabase" value="true" />
- <entry key="CallToUnsupportedMethod" value="false" />
- <entry key="CalledMethods" value="true" />
- <entry key="CheckCalls" value="false" />
- <entry key="CheckExpectedWarnings" value="false" />
- <entry key="CheckImmutableAnnotation" value="true" />
- <entry key="CheckTypeQualifiers" value="true" />
- <entry key="CloneIdiom" value="true" />
- <entry key="ComparatorIdiom" value="true" />
- <entry key="ConfusedInheritance" value="true" />
- <entry key="ConfusionBetweenInheritedAndOuterMethod" value="true" />
- <entry key="CrossSiteScripting" value="true" />
- <entry key="DefaultEncodingDetector" value="true" />
- <entry key="DoInsideDoPrivileged" value="true" />
- <entry key="DontCatchIllegalMonitorStateException" value="true" />
- <entry key="DontIgnoreResultOfPutIfAbsent" value="true" />
- <entry key="DontUseEnum" value="true" />
- <entry key="DroppedException" value="true" />
- <entry key="DumbMethodInvocations" value="true" />
- <entry key="DumbMethods" value="true" />
- <entry key="DuplicateBranches" value="true" />
- <entry key="EmptyZipFileEntry" value="true" />
- <entry key="EqualsOperandShouldHaveClassCompatibleWithThis" value="true" />
- <entry key="ExplicitSerialization" value="true" />
- <entry key="FieldItemSummary" value="true" />
- <entry key="FinalizerNullsFields" value="true" />
- <entry key="FindBadCast2" value="true" />
- <entry key="FindBadForLoop" value="true" />
- <entry key="FindBugsSummaryStats" value="true" />
- <entry key="FindCircularDependencies" value="false" />
- <entry key="FindDeadLocalStores" value="true" />
- <entry key="FindDoubleCheck" value="true" />
- <entry key="FindEmptySynchronizedBlock" value="true" />
- <entry key="FindFieldSelfAssignment" value="true" />
- <entry key="FindFinalizeInvocations" value="true" />
- <entry key="FindFloatEquality" value="true" />
- <entry key="FindFloatMath" value="false" />
- <entry key="FindHEmismatch" value="true" />
- <entry key="FindInconsistentSync2" value="true" />
- <entry key="FindJSR166LockMonitorenter" value="true" />
- <entry key="FindLocalSelfAssignment2" value="true" />
- <entry key="FindMaskedFields" value="true" />
- <entry key="FindMismatchedWaitOrNotify" value="true" />
- <entry key="FindNakedNotify" value="true" />
- <entry key="FindNonSerializableStoreIntoSession" value="false" />
- <entry key="FindNonSerializableValuePassedToWriteObject" value="false" />
- <entry key="FindNonShortCircuit" value="true" />
- <entry key="FindNullDeref" value="true" />
- <entry key="FindNullDerefsInvolvingNonShortCircuitEvaluation" value="true" />
- <entry key="FindOpenStream" value="true" />
- <entry key="FindPuzzlers" value="true" />
- <entry key="FindRefComparison" value="true" />
- <entry key="FindReturnRef" value="true" />
- <entry key="FindRunInvocations" value="true" />
- <entry key="FindSelfComparison" value="true" />
- <entry key="FindSelfComparison2" value="true" />
- <entry key="FindSleepWithLockHeld" value="true" />
- <entry key="FindSpinLoop" value="true" />
- <entry key="FindSqlInjection" value="true" />
- <entry key="FindTwoLockWait" value="true" />
- <entry key="FindUncalledPrivateMethods" value="true" />
- <entry key="FindUnconditionalWait" value="true" />
- <entry key="FindUninitializedGet" value="true" />
- <entry key="FindUnrelatedTypesInGenericContainer" value="true" />
- <entry key="FindUnreleasedLock" value="true" />
- <entry key="FindUnsatisfiedObligation" value="true" />
- <entry key="FindUnsyncGet" value="true" />
- <entry key="FindUseOfNonSerializableValue" value="true" />
- <entry key="FindUselessControlFlow" value="true" />
- <entry key="FormatStringChecker" value="true" />
- <entry key="FunctionsThatMightBeMistakenForProcedures" value="true" />
- <entry key="HugeSharedStringConstants" value="true" />
- <entry key="IDivResultCastToDouble" value="true" />
- <entry key="IncompatMask" value="true" />
- <entry key="InconsistentAnnotations" value="true" />
- <entry key="InefficientMemberAccess" value="false" />
- <entry key="InefficientToArray" value="true" />
- <entry key="InfiniteLoop" value="true" />
- <entry key="InfiniteRecursiveLoop" value="true" />
- <entry key="InheritanceUnsafeGetResource" value="true" />
- <entry key="InitializationChain" value="true" />
- <entry key="InitializeNonnullFieldsInConstructor" value="true" />
- <entry key="InstantiateStaticClass" value="true" />
- <entry key="IntCast2LongAsInstant" value="true" />
- <entry key="InvalidJUnitTest" value="true" />
- <entry key="IteratorIdioms" value="true" />
- <entry key="LazyInit" value="true" />
- <entry key="LoadOfKnownNullValue" value="true" />
- <entry key="LostLoggerDueToWeakReference" value="true" />
- <entry key="MethodReturnCheck" value="true" />
- <entry key="Methods" value="true" />
- <entry key="MultithreadedInstanceAccess" value="true" />
- <entry key="MutableLock" value="true" />
- <entry key="MutableStaticFields" value="true" />
- <entry key="Naming" value="true" />
- <entry key="Noise" value="false" />
- <entry key="NoiseNullDeref" value="false" />
- <entry key="NoteAnnotationRetention" value="true" />
- <entry key="NoteCheckReturnValueAnnotations" value="true" />
- <entry key="NoteDirectlyRelevantTypeQualifiers" value="true" />
- <entry key="NoteJCIPAnnotation" value="true" />
- <entry key="NoteNonNullAnnotations" value="true" />
- <entry key="NoteNonnullReturnValues" value="true" />
- <entry key="NoteSuppressedWarnings" value="true" />
- <entry key="NoteUnconditionalParamDerefs" value="true" />
- <entry key="NumberConstructor" value="true" />
- <entry key="OverridingEqualsNotSymmetrical" value="true" />
- <entry key="PreferZeroLengthArrays" value="true" />
- <entry key="PublicSemaphores" value="false" />
- <entry key="QuestionableBooleanAssignment" value="true" />
- <entry key="ReadOfInstanceFieldInMethodInvokedByConstructorInSuperclass" value="true" />
- <entry key="ReadReturnShouldBeChecked" value="true" />
- <entry key="RedundantInterfaces" value="true" />
- <entry key="ReflectiveClasses" value="true" />
- <entry key="RepeatedConditionals" value="true" />
- <entry key="ResolveAllReferences" value="false" />
- <entry key="RuntimeExceptionCapture" value="true" />
- <entry key="SerializableIdiom" value="true" />
- <entry key="StartInConstructor" value="true" />
- <entry key="StaticCalendarDetector" value="true" />
- <entry key="StringConcatenation" value="true" />
- <entry key="SuperfluousInstanceOf" value="true" />
- <entry key="SuspiciousThreadInterrupted" value="true" />
- <entry key="SwitchFallthrough" value="true" />
- <entry key="SynchronizationOnSharedBuiltinConstant" value="true" />
- <entry key="SynchronizeAndNullCheckField" value="true" />
- <entry key="SynchronizeOnClassLiteralNotGetClass" value="true" />
- <entry key="SynchronizingOnContentsOfFieldToProtectField" value="true" />
- <entry key="TestASM" value="false" />
- <entry key="TestDataflowAnalysis" value="false" />
- <entry key="TestingGround" value="false" />
- <entry key="TestingGround2" value="false" />
- <entry key="TrainFieldStoreTypes" value="true" />
- <entry key="TrainLongInstantfParams" value="true" />
- <entry key="TrainNonNullAnnotations" value="true" />
- <entry key="TrainUnconditionalDerefParams" value="true" />
- <entry key="URLProblems" value="true" />
- <entry key="UncallableMethodOfAnonymousClass" value="true" />
- <entry key="UnnecessaryMath" value="true" />
- <entry key="UnreadFields" value="true" />
- <entry key="UselessSubclassMethod" value="false" />
- <entry key="VarArgsProblems" value="true" />
- <entry key="VolatileUsage" value="true" />
- <entry key="WaitInLoop" value="true" />
- <entry key="WrongMapIterator" value="true" />
- <entry key="XMLFactoryBypass" value="true" />
- </map>
- </option>
- <option name="_reportCategories">
- <map>
- <entry key="BAD_PRACTICE" value="true" />
- <entry key="CORRECTNESS" value="true" />
- <entry key="EXPERIMENTAL" value="true" />
- <entry key="I18N" value="true" />
- <entry key="MALICIOUS_CODE" value="true" />
- <entry key="MT_CORRECTNESS" value="true" />
- <entry key="PERFORMANCE" value="true" />
- <entry key="SECURITY" value="true" />
- <entry key="STYLE" value="true" />
- </map>
- </option>
- </component>
-</module>
-
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/CliTool.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/CliTool.java b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/CliTool.java
deleted file mode 100644
index 4a824a4..0000000
--- a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/CliTool.java
+++ /dev/null
@@ -1,76 +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.stratos.adc.mgt.cli;
-
-import static org.apache.stratos.adc.mgt.cli.utils.CliConstants.STRATOS_DIR;
-
-import java.io.File;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class is used for input the commands through CLITool, command prompt.
- */
-public class CliTool {
-
- private static final Logger logger = LoggerFactory.getLogger(CliTool.class);
-
- /**
- * Main executable method used to call from CLI.
- *
- */
- public static void main(final String[] args) {
- CliTool cliTool = new CliTool();
- cliTool.createConfigDirectory();
- cliTool.handleConsoleInputs(args);
- }
-
- /**
- * Here is the place all the command line inputs get processed
- *
- * @param arguments
- * passed to CLI tool.
- */
- private void handleConsoleInputs(String[] arguments) {
- if (logger.isInfoEnabled()) {
- logger.info("Stratos CLI Started...");
- }
- StratosApplication application = new StratosApplication();
- application.start(arguments);
- }
-
- private void createConfigDirectory() {
- File stratosFile = new File(System.getProperty("user.home"), STRATOS_DIR);
- if (stratosFile.exists()) {
- if (logger.isInfoEnabled()) {
- logger.info("Using directory: {}", stratosFile.getPath());
- }
- } else {
- if (stratosFile.mkdir()) {
- if (logger.isInfoEnabled()) {
- logger.info("Created directory: {}", stratosFile.getPath());
- }
- } else if (logger.isWarnEnabled()) {
- logger.warn("Failed to created directory: {}", stratosFile.getPath());
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/Command.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/Command.java b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/Command.java
deleted file mode 100644
index caebaa4..0000000
--- a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/Command.java
+++ /dev/null
@@ -1,67 +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.stratos.adc.mgt.cli;
-
-import org.apache.stratos.adc.mgt.cli.exception.CommandException;
-import org.apache.commons.cli.Options;
-
-public interface Command<T extends CommandContext> {
-
- /**
- * @return The name of the command
- */
- String getName();
-
- /**
- * Information about the command
- *
- * @return The description of the command
- */
- String getDescription();
-
- /**
- * This should return the syntax required for the command.
- *
- * Used to display help.
- *
- * @return The syntax for this command
- */
- String getArgumentSyntax();
-
- /**
- * The options accepted by the command
- *
- * @return The Options for the commands
- */
- Options getOptions();
-
- /**
- * Executing the commands. Returns a code
- *
- * @param context
- * The context assoicated with the Command Line Application
- * @param args
- * The arguments for the command
- * @return The status code
- * @throws org.apache.stratos.adc.mgt.cli.exception.CommandException
- * if any errors occur when executing the command
- */
- int execute(T context, String[] args) throws CommandException;
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/CommandContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/CommandContext.java b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/CommandContext.java
deleted file mode 100644
index 745b2f4..0000000
--- a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/CommandContext.java
+++ /dev/null
@@ -1,88 +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.stratos.adc.mgt.cli;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Observable;
-
-public class CommandContext extends Observable {
-
- /**
- * Properties for the context.
- */
- private Map<String, Object> properties;
-
- /**
- * The application
- */
- private final CommandLineApplication<? extends CommandContext> application;
-
- public CommandContext(CommandLineApplication<? extends CommandContext> application) {
- properties = new HashMap<String, Object>();
- this.application = application;
- }
-
- public final CommandLineApplication<? extends CommandContext> getApplication() {
- return application;
- }
-
- /**
- * Set property in the context
- *
- * @param key
- * The key
- * @param o
- * The value for the key
- * @return The previous value or null
- */
- public Object put(String key, Object o) {
- Object previous = properties.put(key, o);
- setChanged();
- notifyObservers();
- return previous;
- }
-
- /**
- * Get property value from the context
- *
- * @param key
- * The key
- * @return The value
- */
- public Object getObject(String key) {
- return properties.get(key);
- }
-
- /**
- * Get the string value, or null
- *
- * @param key
- * The key
- * @return The string value, or null.
- */
- public String getString(String key) {
- Object o = getObject(key);
- if (o instanceof String) {
- return (String) o;
- }
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/CommandLineApplication.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/CommandLineApplication.java b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/CommandLineApplication.java
deleted file mode 100644
index 010948f..0000000
--- a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/CommandLineApplication.java
+++ /dev/null
@@ -1,190 +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.stratos.adc.mgt.cli;
-
-import java.io.File;
-import java.io.IOException;
-
-import jline.console.ConsoleReader;
-import jline.console.history.FileHistory;
-
-import org.apache.stratos.adc.mgt.cli.utils.CliConstants;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public abstract class CommandLineApplication<T extends CommandContext> {
-
- private static final Logger logger = LoggerFactory.getLogger(CommandLineApplication.class);
-
- protected final ConsoleReader reader;
- protected FileHistory history;
-
- public CommandLineApplication() {
- reader = createConsoleReader();
- }
-
- /**
- * Creates new jline ConsoleReader.
- *
- * @return a jline ConsoleReader instance
- */
- protected ConsoleReader createConsoleReader() {
- ConsoleReader consoleReader = null;
- try {
- consoleReader = new ConsoleReader();
- consoleReader.setPrompt(getPrompt());
- history = new FileHistory(getHistoryFile());
- consoleReader.setHistory(history);
- } catch (IOException e) {
- throw new IllegalStateException("Cannot create jline console reader", e);
- }
- return consoleReader;
- }
-
- public ConsoleReader getConsoleReader() {
- return reader;
- }
-
- protected abstract String getPrompt();
-
- /**
- * Get the history file for the Console Reader.
- *
- * @return File for storing history
- */
- protected abstract File getHistoryFile();
-
- public final void start(String[] args) {
- Thread shutdownHookThread = new Thread("CLI Shutdown Hook") {
- @Override
- public void run() {
- performDestroy();
- }
- };
- Runtime.getRuntime().addShutdownHook(shutdownHookThread);
- int returnCode = run(args);
- if (logger.isDebugEnabled()) {
- logger.debug("Exiting with error code {}", returnCode);
- }
- System.exit(returnCode);
- }
-
- protected abstract int run(String[] args);
-
- protected void promptLoop() {
- String line = null;
- boolean exit = false;
-
- try {
- while (!exit && (reader != null && ((line = reader.readLine()) != null))) {
- if ("".equals(line)) {
- continue;
- }
- if (StringUtils.isNotBlank(line)) {
- execute(line);
- exit = CliConstants.EXIT_ACTION.equals(line.trim());
- }
- }
- } catch (IOException e) {
- throw new IllegalStateException("Error in reading line", e);
- }
- }
-
- private int execute(String line) {
- try {
- if (logger.isDebugEnabled()) {
- logger.debug("Executing command line: \"{}\"", line);
- }
- int returnCode = executeCommand(line);
- if (logger.isDebugEnabled()) {
- logger.debug("Command line executed \"{}\". Return code: {}", line, returnCode);
- }
- return returnCode;
- } catch (RuntimeException e) {
- if (logger.isErrorEnabled()) {
- logger.error("Error executing command line: " + line, e);
- }
- return 1;
- }
- }
-
- protected abstract int executeCommand(String line);
-
- private void performDestroy() {
- if (logger.isDebugEnabled()) {
- logger.debug("Shutting down application... Invoking destroy methods");
- }
- if (history != null) {
- try {
- history.flush();
- } catch (IOException e) {
- if (logger.isErrorEnabled()) {
- logger.error("Error flushing history.", e);
- }
- }
- }
- destroy();
- }
-
- /**
- * May override to perform action before destroying
- */
- protected void destroy() {
- };
-
- public String getInput(String prompt) {
- return getInput(prompt, null);
- }
-
- public String getInput(String prompt, Character mask) {
- String line = null;
- try {
- reader.setPrompt(prompt + ": ");
- while ((line = reader.readLine(mask)) != null) {
- if ("".equals(line)) {
- continue;
- }
- return line;
- }
- } catch (IOException e) {
- throw new IllegalStateException("Error in reading line", e);
- } finally {
- reader.setPrompt(CliConstants.STRATOS_SHELL_PROMPT);
- }
- return line;
- }
-
- /**
- * @return {@code true if user confirmed}
- */
- public boolean getConfirmation(String prompt) {
- prompt = prompt + " [yes/no]";
-
- String input = "";
- int tries = 0;
- do {
- tries++;
- input = getInput(prompt);
- } while (!"y".equals(input) && !"yes".equals(input) && !"n".equals(input) && !"no".equals(input) && tries < 3);
-
- return "y".equals(input) || "yes".equals(input);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/CommandLineService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/CommandLineService.java b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/CommandLineService.java
deleted file mode 100644
index 2aa9f2b..0000000
--- a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/CommandLineService.java
+++ /dev/null
@@ -1,556 +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.stratos.adc.mgt.cli;
-
-import java.rmi.RemoteException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
-
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.client.Options;
-import org.apache.axis2.client.ServiceClient;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.ConfigurationContextFactory;
-import org.apache.axis2.description.TransportOutDescription;
-import org.apache.axis2.transport.http.HttpTransportProperties;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.stratos.adc.mgt.cli.exception.CommandException;
-import org.apache.stratos.adc.mgt.cli.utils.CommandLineUtils;
-import org.apache.stratos.adc.mgt.cli.utils.RowMapper;
-import org.apache.stratos.adc.mgt.dto.xsd.Cartridge;
-import org.apache.stratos.adc.mgt.dto.xsd.PolicyDefinition;
-import org.apache.stratos.adc.mgt.dto.xsd.SubscriptionInfo;
-import org.apache.stratos.adc.mgt.stub.ApplicationManagementServiceADCExceptionException;
-import org.apache.stratos.adc.mgt.stub.ApplicationManagementServiceAlreadySubscribedExceptionException;
-import org.apache.stratos.adc.mgt.stub.ApplicationManagementServiceDomainMappingExistsExceptionException;
-import org.apache.stratos.adc.mgt.stub.ApplicationManagementServiceDuplicateCartridgeAliasExceptionException;
-import org.apache.stratos.adc.mgt.stub.ApplicationManagementServiceInvalidCartridgeAliasExceptionException;
-import org.apache.stratos.adc.mgt.stub.ApplicationManagementServiceInvalidRepositoryExceptionException;
-import org.apache.stratos.adc.mgt.stub.ApplicationManagementServiceNotSubscribedExceptionException;
-import org.apache.stratos.adc.mgt.stub.ApplicationManagementServicePolicyExceptionException;
-import org.apache.stratos.adc.mgt.stub.ApplicationManagementServiceRepositoryCredentialsRequiredExceptionException;
-import org.apache.stratos.adc.mgt.stub.ApplicationManagementServiceRepositoryRequiredExceptionException;
-import org.apache.stratos.adc.mgt.stub.ApplicationManagementServiceRepositoryTransportExceptionException;
-import org.apache.stratos.adc.mgt.stub.ApplicationManagementServiceStub;
-import org.apache.stratos.adc.mgt.stub.ApplicationManagementServiceUnregisteredCartridgeExceptionException;
-
-import com.google.gson.Gson;
-
-public class CommandLineService {
-
- private static final Logger logger = LoggerFactory.getLogger(CommandLineService.class);
-
- private ApplicationManagementServiceStub stub;
-
- private CommandLineService() {
- }
-
- private static class SingletonHolder {
- private final static CommandLineService INSTANCE = new CommandLineService();
- }
-
- public static CommandLineService getInstance() {
- return SingletonHolder.INSTANCE;
- }
-
- private void initializeApplicationManagementStub(String serverURL, String username, String password) throws AxisFault {
- HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator();
- authenticator.setUsername(username);
- authenticator.setPassword(password);
- authenticator.setPreemptiveAuthentication(true);
-
- ApplicationManagementServiceStub stub;
- ConfigurationContext configurationContext = null;
- try {
- configurationContext = ConfigurationContextFactory.createDefaultConfigurationContext();
- } catch (Exception e) {
- String msg = "Backend error occurred. Please contact the service admins!";
- throw new AxisFault(msg, e);
- }
- HashMap<String, TransportOutDescription> transportsOut = configurationContext
- .getAxisConfiguration().getTransportsOut();
- for (TransportOutDescription transportOutDescription : transportsOut.values()) {
- transportOutDescription.getSender().init(configurationContext, transportOutDescription);
- }
- stub = new ApplicationManagementServiceStub(configurationContext, serverURL + "/services/ApplicationManagementService");
- ServiceClient client = stub._getServiceClient();
- Options option = client.getOptions();
- option.setManageSession(true);
- option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, authenticator);
- option.setTimeOutInMilliSeconds(300000);
- this.stub = stub;
- }
-
- public boolean login(String serverURL, String username, String password, boolean validateLogin) throws CommandException {
- try {
- // Following code will avoid validating certificate
- SSLContext sc;
- // Get SSL context
- sc = SSLContext.getInstance("SSL");
- // Create empty HostnameVerifier
- HostnameVerifier hv = new HostnameVerifier() {
- public boolean verify(String urlHostName, SSLSession session) {
- return true;
- }
- };
- // Create a trust manager that does not validate certificate
- // chains
- TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
- public java.security.cert.X509Certificate[] getAcceptedIssuers() {
- return null;
- }
-
- public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
- }
-
- public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
- }
- } };
- sc.init(null, trustAllCerts, new java.security.SecureRandom());
- SSLContext.setDefault(sc);
- HttpsURLConnection.setDefaultHostnameVerifier(hv);
- } catch (Exception e) {
- throw new RuntimeException("Error while authentication process!", e);
- }
-
- // Initialize Service Stub
- try {
- initializeApplicationManagementStub(serverURL, username, password);
- } catch (AxisFault e) {
- System.out.println("Error connecting to the back-end");
- throw new CommandException(e);
- }
-
- try {
- if (validateLogin) {
- String tenantDomain = stub.getTenantDomain();
- if (logger.isDebugEnabled()) {
- logger.debug("Tenant Domain {}", tenantDomain);
- }
- return (tenantDomain != null);
- } else {
- // Just return true as we don't need to validate
- return true;
- }
- } catch (RemoteException e) {
- System.out.println("Authentication failed!");
- throw new CommandException(e);
- }
- }
-
- public void listSubscribedCartridges(final boolean full) throws CommandException {
- try {
- Cartridge[] cartridges = stub.getSubscribedCartridges();
-
- if (cartridges == null) {
- if (logger.isDebugEnabled()) {
- logger.debug("No subscribed cartridges found");
- }
- System.out.println("There are no subscribed cartridges");
- return;
- }
-
- RowMapper<Cartridge> cartridgeMapper = new RowMapper<Cartridge>() {
-
- @Override
- public String[] getData(Cartridge cartridge) {
- String[] data = full ? new String[9] : new String[7];
- data[0] = cartridge.getCartridgeType();
- data[1] = cartridge.getDisplayName();
- data[2] = cartridge.getVersion();
- data[3] = cartridge.getMultiTenant() ? "Multi-Tenant" : "Single-Tenant";
- data[4] = cartridge.getCartridgeAlias();
- data[5] = cartridge.getStatus();
- data[6] = cartridge.getMultiTenant() ? "N/A" : String.valueOf(cartridge.getActiveInstances());
- if (full) {
- data[7] = getAccessURLs(cartridge);
- data[8] = cartridge.getRepoURL() != null ? cartridge.getRepoURL() : "";
- }
- return data;
- }
- };
-
- List<String> headers = new ArrayList<String>();
- headers.add("Type");
- headers.add("Name");
- headers.add("Version");
- headers.add("Tenancy Model");
- headers.add("Alias");
- headers.add("Status");
- headers.add("Running Instances");
- if (full) {
- headers.add("Access URL(s)");
- headers.add("Repo URL");
- }
-
- System.out.println("Subscribed Cartridges:");
- CommandLineUtils.printTable(cartridges, cartridgeMapper, headers.toArray(new String[headers.size()]));
-
- System.out.println();
-
- } catch (ApplicationManagementServiceADCExceptionException e) {
- handleException("cannot.list.subscribed.cartridges", e);
- } catch (RemoteException e) {
- handleException(e);
- }
- }
-
- public void listAvailableCartridges() throws CommandException {
- try {
- Cartridge[] multiTenantCatridges = stub.getAvailableCartridges(true);
-
- if (multiTenantCatridges == null) {
- if (logger.isDebugEnabled()) {
- logger.debug("No multi-tenant cartridges available");
- }
- System.out.println("There are no multi-tenant cartridges available");
- }
-
- RowMapper<Cartridge> cartridgeMapper = new RowMapper<Cartridge>() {
-
- @Override
- public String[] getData(Cartridge cartridge) {
- String[] data = new String[3];
- data[0] = cartridge.getCartridgeType();
- data[1] = cartridge.getDisplayName();
- data[2] = cartridge.getVersion();
- return data;
- }
- };
-
- System.out.println("Available Multi-Tenant Cartridges:");
- CommandLineUtils.printTable(multiTenantCatridges, cartridgeMapper, "Type", "Name", "Version");
- System.out.println();
-
- Cartridge[] singleTenantCatridges = stub.getAvailableCartridges(false);
-
- if (multiTenantCatridges == null) {
- if (logger.isDebugEnabled()) {
- logger.debug("No single-tenant cartridges available");
- }
- System.out.println("There are no single-tenant cartridges available");
- }
-
- System.out.println("Available Single-Tenant Cartridges:");
- CommandLineUtils.printTable(singleTenantCatridges, cartridgeMapper, "Type", "Name", "Version");
- System.out.println();
- } catch (ApplicationManagementServiceADCExceptionException e) {
- handleException("cannot.list.available.cartridges", e);
- } catch (RemoteException e) {
- handleException(e);
- }
- }
-
- public void listAvailablePolicies() throws CommandException {
- try {
- PolicyDefinition[] policies = stub.getPolicyDefinitions();
-
- if (policies == null) {
- if (logger.isDebugEnabled()) {
- logger.debug("No policies available");
- }
- System.out.println("There are no policies available");
- }
-
- RowMapper<PolicyDefinition> policyMapper = new RowMapper<PolicyDefinition>() {
-
- @Override
- public String[] getData(PolicyDefinition policyDefinition) {
- String[] data = new String[3];
- data[0] = policyDefinition.getName();
- data[1] = policyDefinition.getDescription();
- data[2] = policyDefinition.getDefaultPolicy() ? "Yes" : "No";
- return data;
- }
- };
-
- CommandLineUtils.printTable(policies, policyMapper, "Policy Name", "Description", "Default");
- System.out.println();
- } catch (RemoteException e) {
- handleException(e);
- }
- }
-
- public void info(String alias) throws CommandException {
- try {
- Cartridge cartridge = null;
- try {
- cartridge = stub.getCartridgeInfo(alias);
- } catch (ApplicationManagementServiceADCExceptionException e) {
- handleException(e);
- return;
- } catch (ApplicationManagementServiceNotSubscribedExceptionException e) {
- handleException("notsubscribed.error", e, alias);
- }
- if (logger.isDebugEnabled()) {
- logger.debug("Cartridge Info: {}", new Gson().toJson(cartridge));
- }
- final String FORMAT = "%-20s: %s%n";
- System.out.println();
- System.out.println("Cartridge Information");
- System.out.println("---------------------");
- System.out.format(FORMAT, "Cartridge", cartridge.getCartridgeType());
- System.out.format(FORMAT, "Name", cartridge.getDisplayName());
- System.out.format(FORMAT, "Description", cartridge.getDescription());
- System.out.format(FORMAT, "Version", cartridge.getVersion());
- System.out.format(FORMAT, "Tenancy Model", cartridge.getMultiTenant() ? "Multi-Tenant" : "Single-Tenant");
- System.out.format(FORMAT, "Alias", cartridge.getCartridgeAlias());
- if (StringUtils.isNotBlank(cartridge.getPolicyDescription())) {
- System.out.format(FORMAT, "Policy", cartridge.getPolicyDescription());
- }
- System.out.format(FORMAT, "Access URL(s)", getAccessURLs(cartridge));
- if (StringUtils.isNotBlank(cartridge.getIp())) {
- System.out.format(FORMAT, "Host", cartridge.getIp());
- }
- if (StringUtils.isNotBlank(cartridge.getDbUserName())) {
- System.out.format(FORMAT, "Database Username", cartridge.getDbUserName());
- }
- if (StringUtils.isNotBlank(cartridge.getPassword())) {
- System.out.format(FORMAT, "Password", cartridge.getPassword());
- }
- if (StringUtils.isNotBlank(cartridge.getRepoURL())) {
- System.out.format(FORMAT, "Repository URL", cartridge.getRepoURL());
- }
- System.out.format(FORMAT, "Status", cartridge.getStatus());
- System.out.format(FORMAT, "Running Instances",
- cartridge.getMultiTenant() ? "N/A" : String.valueOf(cartridge.getActiveInstances()));
- System.out.println();
-
- } catch (RemoteException e) {
- handleException(e);
- }
- }
-
- public void unsubscribe(String alias) throws CommandException {
- try {
- stub.unsubscribe(alias);
- System.out.println("You have successfully unsubscribed " + alias);
- } catch (ApplicationManagementServiceADCExceptionException e) {
- handleException("cannot.unsubscribe", e);
- } catch (ApplicationManagementServiceNotSubscribedExceptionException e) {
- handleException("notsubscribed.error", e, alias);
- } catch (RemoteException e) {
- handleException(e);
- }
- }
-
- public void sync(String alias) throws CommandException {
- try {
- System.out.format("Synchronizing repository for alias: %s%n", alias);
- stub.synchronizeRepository(alias);
- } catch (ApplicationManagementServiceADCExceptionException e) {
- handleException("cannot.syncrepo", e);
- } catch (RemoteException e) {
- handleException(e);
- } catch (ApplicationManagementServiceNotSubscribedExceptionException e) {
- handleException("notsubscribed.error", e, alias);
- }
- }
-
- public String addDomainMapping(String domain, String alias) throws CommandException {
- try {
- return stub.addDomainMapping(domain, alias);
- } catch (ApplicationManagementServiceADCExceptionException e) {
- handleException("cannot.mapdomain", e);
- } catch (RemoteException e) {
- handleException(e);
- } catch (ApplicationManagementServiceNotSubscribedExceptionException e) {
- handleException("notsubscribed.error", e, alias);
- } catch (ApplicationManagementServiceDomainMappingExistsExceptionException e) {
- handleException("domainmapping.exists.error", e, domain, alias);
- }
- return null;
- }
-
- public void removeDomainMapping(String alias) throws CommandException {
- try {
- stub.removeDomainMapping(alias);
- System.out.format("Domain mapping removed for alias: %s.%n", alias);
- } catch (ApplicationManagementServiceADCExceptionException e) {
- handleException("cannot.removedomain", e);
- } catch (RemoteException e) {
- handleException(e);
- } catch (ApplicationManagementServiceNotSubscribedExceptionException e) {
- handleException("notsubscribed.error", e, alias);
- }
- }
-
- public void subscribe(String cartridgeType, String alias, String policy, String externalRepoURL,
- boolean privateRepo, String username, String password, String dataCartridgeType, String dataCartridgeAlias)
- throws CommandException {
-
- SubscriptionInfo subcriptionConnectInfo = null;
- if (StringUtils.isNotBlank(dataCartridgeType) && StringUtils.isNotBlank(dataCartridgeAlias)) {
- System.out.format("Subscribing to data cartridge %s with alias %s.%n", dataCartridgeType,
- dataCartridgeAlias);
- try {
- subcriptionConnectInfo = stub.subscribe(dataCartridgeType, dataCartridgeAlias, null, null, false, null,
- null, null, null);
- System.out.format("You have successfully subscribed to %s cartridge with alias %s.%n",
- dataCartridgeType, dataCartridgeAlias);
- System.out.format("%nSubscribing to %s cartridge and connecting with %s data cartridge.%n", alias,
- dataCartridgeAlias);
- } catch (RemoteException e) {
- handleException(e);
- } catch (ApplicationManagementServiceADCExceptionException e) {
- handleException("cannot.subscribe", e);
- } catch (ApplicationManagementServiceRepositoryRequiredExceptionException e) {
- handleException("repository.required", e);
- } catch (ApplicationManagementServiceUnregisteredCartridgeExceptionException e) {
- handleException("cartridge.notregistered", e, dataCartridgeType);
- } catch (ApplicationManagementServiceInvalidCartridgeAliasExceptionException e) {
- handleException("cartridge.invalid.alias", e);
- } catch (ApplicationManagementServiceAlreadySubscribedExceptionException e) {
- handleException("cartridge.already.subscribed", e, e.getFaultMessage().getAlreadySubscribedException()
- .getCartridgeType());
- } catch (ApplicationManagementServiceDuplicateCartridgeAliasExceptionException e) {
- handleException("cartridge.alias.duplicate", e, dataCartridgeAlias);
- } catch (ApplicationManagementServicePolicyExceptionException e) {
- handleException("policy.error", e);
- } catch (ApplicationManagementServiceRepositoryTransportExceptionException e) {
- handleException("repository.transport.error", e, externalRepoURL);
- } catch (ApplicationManagementServiceRepositoryCredentialsRequiredExceptionException e) {
- handleException("repository.credentials.required", e, externalRepoURL);
- } catch (ApplicationManagementServiceInvalidRepositoryExceptionException e) {
- handleException("repository.invalid.error", e, externalRepoURL);
- }
- }
-
-
- try {
- SubscriptionInfo subcriptionInfo = stub.subscribe(cartridgeType, alias, policy, externalRepoURL,
- privateRepo, username, password, dataCartridgeType, dataCartridgeAlias);
-
- System.out
- .format("You have successfully subscribed to %s cartridge with alias %s.%n", cartridgeType, alias);
-
- String repoURL = null;
- String hostnames = null;
- String hostnamesLabel = null;
- if (subcriptionInfo != null) {
- repoURL = subcriptionInfo.getRepositoryURL();
- hostnames = subcriptionInfo.getHostname();
- hostnamesLabel = "host name";
-
- if (repoURL != null) {
- System.out.println("GIT Repository URL: " + repoURL);
- }
-
- Cartridge cart = stub.getCartridgeInfo(alias);
- System.out.format("Your application is being published here. %s%n", getAccessURLs(cart));
- }
- if (subcriptionConnectInfo != null) {
- hostnames += ", " + subcriptionConnectInfo.getHostname();
- hostnamesLabel = "host names";
-
- Cartridge cart = stub.getCartridgeInfo(alias);
- System.out.format("Your data application is being published here. %s%n", getAccessURLs(cart));
- }
- if (externalRepoURL != null) {
- String takeTimeMsg = "(this might take few minutes... depending on repo size)\n";
- System.out.println(takeTimeMsg);
- }
-
- System.out.format("Please map the %s \"%s\" to ELB IP%n", hostnamesLabel, hostnames);
- } catch (RemoteException e) {
- handleException(e);
- } catch (ApplicationManagementServiceADCExceptionException e) {
- handleException("cannot.subscribe", e);
- } catch (ApplicationManagementServiceRepositoryRequiredExceptionException e) {
- handleException("repository.required", e);
- } catch (ApplicationManagementServiceUnregisteredCartridgeExceptionException e) {
- handleException("cartridge.notregistered", e, cartridgeType);
- } catch (ApplicationManagementServiceInvalidCartridgeAliasExceptionException e) {
- handleException("cartridge.invalid.alias", e);
- } catch (ApplicationManagementServiceAlreadySubscribedExceptionException e) {
- handleException("cartridge.already.subscribed", e, e.getFaultMessage().getAlreadySubscribedException()
- .getCartridgeType());
- } catch (ApplicationManagementServiceDuplicateCartridgeAliasExceptionException e) {
- handleException("cartridge.alias.duplicate", e, alias);
- } catch (ApplicationManagementServicePolicyExceptionException e) {
- handleException("policy.error", e);
- } catch (ApplicationManagementServiceRepositoryTransportExceptionException e) {
- handleException("repository.transport.error", e, externalRepoURL);
- } catch (ApplicationManagementServiceRepositoryCredentialsRequiredExceptionException e) {
- handleException("repository.credentials.required", e, externalRepoURL);
- } catch (ApplicationManagementServiceInvalidRepositoryExceptionException e) {
- handleException("repository.invalid.error", e, externalRepoURL);
- } catch (ApplicationManagementServiceNotSubscribedExceptionException e) {
- handleException("notsubscribed.error", e, alias);
- }
- }
-
- private String getAccessURLs(Cartridge cartridge) {
- String[] accessURLs = cartridge.getAccessURLs();
- StringBuilder urlBuilder = new StringBuilder();
- if (accessURLs != null) {
- for (int i = 0; i < accessURLs.length; i++) {
- String url = accessURLs[i];
- if (url != null) {
- if (i > 0) {
- urlBuilder.append(", ");
- }
- urlBuilder.append(url);
- }
- }
- }
- return urlBuilder.toString();
- }
-
- private void handleException(Exception e) throws CommandException {
- if (logger.isDebugEnabled()) {
- logger.debug("Displaying message from Exception {}\n{}", e.getClass(), e.getMessage());
- }
- // TODO: Fix handling error message.
- // Sometimes the Axis2 stub throws only the RemoteException (an
- // AxisFault)
- // So, other exceptions won't come here.
- String message = e.getMessage();
- if (message == null || (message != null && message.contains("Exception"))) {
- message = "Error executing command!";
- }
- if (logger.isErrorEnabled()) {
- logger.error(message);
- }
- System.out.println(message);
- throw new CommandException(message, e);
- }
-
- private void handleException(String key, Exception e, Object... args) throws CommandException {
- if (logger.isDebugEnabled()) {
- logger.debug("Displaying message for {}. Exception thrown is {}", key, e.getClass());
- }
- String message = CommandLineUtils.getMessage(key, args);
- if (logger.isErrorEnabled()) {
- logger.error(message);
- }
- System.out.println(message);
- throw new CommandException(message, e);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/StratosApplication.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/StratosApplication.java b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/StratosApplication.java
deleted file mode 100644
index 74caf39..0000000
--- a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/StratosApplication.java
+++ /dev/null
@@ -1,504 +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.stratos.adc.mgt.cli;
-
-import static org.apache.stratos.adc.mgt.cli.utils.CliConstants.STRATOS_DIR;
-import static org.apache.stratos.adc.mgt.cli.utils.CliConstants.STRATOS_HISTORY_DIR;
-
-import java.io.File;
-import java.io.PrintWriter;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.stratos.adc.mgt.cli.completer.CommandCompleter;
-import org.apache.stratos.adc.mgt.cli.exception.CommandException;
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.GnuParser;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.text.StrTokenizer;
-import org.apache.commons.validator.routines.UrlValidator;
-import org.apache.log4j.Level;
-import org.apache.log4j.LogManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.stratos.adc.mgt.cli.commands.AddDomainMappingCommand;
-import org.apache.stratos.adc.mgt.cli.commands.CartridgesCommand;
-import org.apache.stratos.adc.mgt.cli.commands.ExitCommand;
-import org.apache.stratos.adc.mgt.cli.commands.HelpCommand;
-import org.apache.stratos.adc.mgt.cli.commands.InfoCommand;
-import org.apache.stratos.adc.mgt.cli.commands.ListCommand;
-import org.apache.stratos.adc.mgt.cli.commands.PoliciesCommand;
-import org.apache.stratos.adc.mgt.cli.commands.RemoveDomainMappingCommand;
-import org.apache.stratos.adc.mgt.cli.commands.SubscribeCommand;
-import org.apache.stratos.adc.mgt.cli.commands.SyncCommand;
-import org.apache.stratos.adc.mgt.cli.commands.UnsubscribeCommand;
-import org.apache.stratos.adc.mgt.cli.utils.CliConstants;
-
-public class StratosApplication extends CommandLineApplication<StratosCommandContext> {
-
- private static final Logger logger = LoggerFactory.getLogger(StratosApplication.class);
-
- private final Map<String, Command<StratosCommandContext>> commands;
- private final StratosCommandContext context;
-
- private final Options options;
-
- public StratosApplication() {
- commands = new HashMap<String, Command<StratosCommandContext>>();
- context = new StratosCommandContext(this);
-
- options = constructOptions();
-
- createCommands();
- createAutocomplete();
- }
-
- /**
- * Construct Options.
- *
- * @return Options expected from command-line.
- */
- private Options constructOptions() {
- final Options options = new Options();
- Option usernameOption = new Option(CliConstants.USERNAME_OPTION, CliConstants.USERNAME_LONG_OPTION, true,
- "Username");
- usernameOption.setArgName("username");
- options.addOption(usernameOption);
-
- Option passwordOption = new Option(CliConstants.PASSWORD_OPTION, CliConstants.PASSWORD_LONG_OPTION, true,
- "Password");
- passwordOption.setArgName("password");
- passwordOption.setOptionalArg(true);
- options.addOption(passwordOption);
- options.addOption(CliConstants.HELP_OPTION, CliConstants.HELP_LONG_OPTION, false, "Display this help");
- options.addOption(CliConstants.TRACE_OPTION, false, "Enable trace logging");
- options.addOption(CliConstants.DEBUG_OPTION, false, "Enable debug logging");
- return options;
- }
-
- private void createCommands() {
- Command<StratosCommandContext> command = new HelpCommand();
- commands.put(command.getName(), command);
-
- command = new ExitCommand();
- commands.put(command.getName(), command);
-
- command = new SubscribeCommand();
- commands.put(command.getName(), command);
-
- command = new UnsubscribeCommand();
- commands.put(command.getName(), command);
-
- command = new CartridgesCommand();
- commands.put(command.getName(), command);
-
- command = new ListCommand();
- commands.put(command.getName(), command);
-
- command = new InfoCommand();
- commands.put(command.getName(), command);
-
- command = new AddDomainMappingCommand();
- commands.put(command.getName(), command);
-
- command = new RemoveDomainMappingCommand();
- commands.put(command.getName(), command);
-
- command = new SyncCommand();
- commands.put(command.getName(), command);
-
- command = new PoliciesCommand();
- commands.put(command.getName(), command);
-
- if (logger.isDebugEnabled()) {
- logger.debug("Created {} commands for the application. {}", commands.size(), commands.keySet());
- }
- }
-
- private void createAutocomplete() {
- reader.addCompleter(new CommandCompleter(commands));
- }
-
- @Override
- protected String getPrompt() {
- return CliConstants.STRATOS_SHELL_PROMPT;
- }
-
- @Override
- protected File getHistoryFile() {
- File stratosFile = new File(System.getProperty("user.home"), STRATOS_DIR);
- File historyFile = new File(stratosFile, STRATOS_HISTORY_DIR);
- return historyFile;
- }
-
- @Override
- public int run(String[] args) {
- boolean loaded = loadRequiredProperties();
- if (!loaded) {
- return CliConstants.ERROR_CODE;
- }
-
- // To get the command action from arguments
- String[] remainingArgs = null;
-
- // Command action
- String action = null;
-
- String usernameInput = null;
- String passwordInput = null;
-
- if (args != null && args.length > 0) {
- // Arguments are passed.
- if (logger.isDebugEnabled()) {
- logger.debug("Arguments:");
- for (String arg : args) {
- logger.debug(arg);
- }
- }
-
- final CommandLineParser parser = new GnuParser();
- CommandLine commandLine;
- try {
- // Must add all options. Otherwise actions cannot be performed directly by command line.
- Options allCommandOptions = new Options();
- for (Command<StratosCommandContext> command : commands.values()) {
- Options commandOptions = command.getOptions();
- if (commandOptions != null) {
- Collection<?> allOptions = commandOptions.getOptions();
- for (Object o : allOptions) {
- allCommandOptions.addOption((Option) o);
- }
- }
- }
- // Add options in this application
- Collection<?> allOptions = options.getOptions();
- for (Object o : allOptions) {
- allCommandOptions.addOption((Option) o);
- }
-
- commandLine = parser.parse(allCommandOptions, args);
- remainingArgs = commandLine.getArgs();
- if (remainingArgs != null && remainingArgs.length > 0) {
- // Get command action
- action = remainingArgs[0];
- }
-
- // Set logger levels from this point onwards
- setLoggerLevel(commandLine.hasOption(CliConstants.TRACE_OPTION),
- commandLine.hasOption(CliConstants.DEBUG_OPTION));
-
- if (commandLine.hasOption(CliConstants.USERNAME_OPTION)) {
- if (logger.isTraceEnabled()) {
- logger.trace("Username option is passed");
- }
- usernameInput = commandLine.getOptionValue(CliConstants.USERNAME_OPTION);
- }
- if (commandLine.hasOption(CliConstants.PASSWORD_OPTION)) {
- if (logger.isTraceEnabled()) {
- logger.trace("Password option is passed");
- }
- passwordInput = commandLine.getOptionValue(CliConstants.PASSWORD_OPTION);
- }
- if (commandLine.hasOption(CliConstants.HELP_ACTION)) {
- printHelp();
- return CliConstants.SUCCESSFUL_CODE;
- }
- } catch (ParseException e) {
- if (logger.isErrorEnabled()) {
- logger.error("Error parsing arguments when trying to login", e);
- }
- System.out.println(e.getMessage());
- return CliConstants.BAD_ARGS_CODE;
- }
-
- }
-
- if (StringUtils.isNotBlank(action)) {
- // User is executing an action
- if (logger.isDebugEnabled()) {
- logger.debug("Action: {}", action);
- }
- Command<StratosCommandContext> command = commands.get(action);
- if (command == null) {
- printHelp();
- return CliConstants.BAD_ARGS_CODE;
- }
-
- boolean loginRequired = !CliConstants.HELP_ACTION.equals(action);
-
- if (loginRequired && logger.isDebugEnabled()) {
- logger.debug("Trying to login...");
- }
-
- if (loginRequired && !login(usernameInput, passwordInput, false)) {
- if (logger.isDebugEnabled()) {
- logger.debug("Exiting from CLI. Login required but login might have failed: {}", action);
- }
- // Exit
- return CliConstants.ERROR_CODE;
- }
-
- try {
- String[] actionArgs = Arrays.copyOfRange(remainingArgs, 1, remainingArgs.length);
- if (logger.isDebugEnabled()) {
- logger.debug("Executing Action: {} {}", action, Arrays.asList(actionArgs));
- }
- int returnCode = command.execute(context, actionArgs);
- if (logger.isDebugEnabled()) {
- logger.debug("Exiting with error code {} after executing action {}", returnCode, action);
- }
- System.exit(returnCode);
- } catch (CommandException e) {
- if (logger.isErrorEnabled()) {
- logger.error("Error executing command: " + action, e);
- }
- return CliConstants.ERROR_CODE;
- }
- } else {
- if (login(usernameInput, passwordInput, true)) {
- System.out.println("Successfully Authenticated.");
- } else {
- // Exit
- return CliConstants.ERROR_CODE;
- }
-
- promptLoop();
- }
- return CliConstants.SUCCESSFUL_CODE;
- }
-
- private boolean login(String usernameInput, String passwordInput, boolean validateLogin) {
- // TODO Previous CLI version uses a keystore. Here we are not using it.
- // Check whether user has passed username and password
- if (StringUtils.isBlank(usernameInput) && StringUtils.isBlank(passwordInput)) {
- // User has not passed any arguments.
- // Try authenticating from the values found
- usernameInput = context.getString(CliConstants.STRATOS_USERNAME_ENV_PROPERTY);
- passwordInput = context.getString(CliConstants.STRATOS_PASSWORD_ENV_PROPERTY);
-
- if (logger.isDebugEnabled()) {
- if (StringUtils.isNotBlank(usernameInput) && StringUtils.isNotBlank(passwordInput)) {
- logger.debug("Found authentication details for {} from context", usernameInput);
- }
- }
-
- }
- // Get user input if not passed as args
- if (StringUtils.isBlank(usernameInput)) {
- usernameInput = getInput("Username");
- } else {
- System.out.format("Username: %s%n", usernameInput);
- }
- if (StringUtils.isBlank(passwordInput)) {
- passwordInput = getInput("Password", '*');
- }
-
- boolean success = false;
- String stratosURL = null;
- stratosURL = context.getString(CliConstants.STRATOS_URL_ENV_PROPERTY);
-
- try {
- success = CommandLineService.getInstance().login(stratosURL, usernameInput, passwordInput, validateLogin);
- } catch (Exception e) {
- if (logger.isErrorEnabled()) {
- logger.error("Error when trying to login", e);
- }
- }
- if (success) {
- if (logger.isDebugEnabled()) {
- logger.debug("Successfully Authenticated.");
- }
- } else {
- if (logger.isDebugEnabled()) {
- logger.debug("Authentication failed.");
- }
- }
- return success;
- }
-
- @Override
- protected int executeCommand(String line) {
- String[] tokens = new StrTokenizer(line).getTokenArray();
- String action = tokens[0];
- String[] actionArgs = Arrays.copyOfRange(tokens, 1, tokens.length);
- if (logger.isDebugEnabled()) {
- logger.debug("Executing command action: {}, Tokens: {}", action, tokens.length);
- }
- Command<StratosCommandContext> command = commands.get(action);
- if (command == null) {
- System.out.println(action + ": command not found.");
- return CliConstants.BAD_ARGS_CODE;
- }
- try {
- return command.execute(context, actionArgs);
- } catch (CommandException e) {
- if (logger.isErrorEnabled()) {
- logger.error("Error executing command: " + action, e);
- }
- return CliConstants.ERROR_CODE;
- }
- }
-
- /**
- * @return {@code true} if required properties are loaded
- */
- private boolean loadRequiredProperties() {
- if (logger.isDebugEnabled()) {
- logger.debug("Loading properties...");
- }
- // Load properties
- String stratosURL = null;
- String username = null;
- String password = null;
-
- stratosURL = System.getenv(CliConstants.STRATOS_URL_ENV_PROPERTY);
- username = System.getenv(CliConstants.STRATOS_USERNAME_ENV_PROPERTY);
- password = System.getenv(CliConstants.STRATOS_PASSWORD_ENV_PROPERTY);
-
- if (StringUtils.isBlank(stratosURL)) {
- if (logger.isDebugEnabled()) {
- logger.debug("Required configuration not found.");
- }
- // Stratos Controller details are not set.
- System.out.format("Could not find required \"%s\" variable in your environment.%n",
- CliConstants.STRATOS_URL_ENV_PROPERTY);
- return false;
- } else {
- if (logger.isDebugEnabled()) {
- logger.debug("Required configuration found. Validating {}", stratosURL);
- }
- UrlValidator urlValidator = new UrlValidator(new String[] { "https" });
- if (!urlValidator.isValid(stratosURL)) {
- if (logger.isDebugEnabled()) {
- logger.debug("Stratos Controller URL {} is not valid", stratosURL);
- }
- System.out.format(
- "The \"%s\" variable in your environment is not a valid URL. You have provided \"%s\".%n"
- + "Please provide the Stratos Controller URL as follows%nhttps://<host>:<port>%n",
- CliConstants.STRATOS_URL_ENV_PROPERTY, stratosURL);
- return false;
- }
- if (logger.isDebugEnabled()) {
- logger.debug("Stratos Controller URL {} is valid.", stratosURL);
- logger.debug("Adding the values to context.");
- }
- context.put(CliConstants.STRATOS_URL_ENV_PROPERTY, stratosURL);
- context.put(CliConstants.STRATOS_USERNAME_ENV_PROPERTY, username);
- context.put(CliConstants.STRATOS_PASSWORD_ENV_PROPERTY, password);
- return true;
- }
- }
-
- private void setLoggerLevel(boolean trace, boolean debug) {
- // We are using Log4j. So, get the logger and set log levels.
- org.apache.log4j.Logger logger = LogManager.getLogger(StratosApplication.class.getPackage().getName());
- if (logger != null && trace) {
- logger.setLevel(Level.TRACE);
- LogManager.getRootLogger().setLevel(Level.TRACE);
- } else if (logger != null && debug) {
- logger.setLevel(Level.DEBUG);
- LogManager.getRootLogger().setLevel(Level.DEBUG);
- }
- }
-
- public void printHelp(final String action) {
- Command<StratosCommandContext> command = commands.get(action);
- if (command == null) {
- System.out.println(action + ": command not found. Help not available.");
- return;
- }
- System.out.println(command.getDescription());
- Options options = command.getOptions();
- if (options != null) {
- if (StringUtils.isNotBlank(command.getArgumentSyntax())) {
- printHelp(command.getName() + " " + command.getArgumentSyntax(), options);
- } else {
- printHelp(command.getName(), options);
- }
- } else {
- // No options. Just print the usage.
- printUsage(command);
- }
- }
-
- public void printHelp() {
- printHelp(CliConstants.STRATOS_APPLICATION_NAME, options);
- System.out.println("\n\nAvailable Commands: ");
- for (String action : commands.keySet()) {
- Command<StratosCommandContext> command = commands.get(action);
- if (command != null) {
- System.out.format("%-25s %s%n", command.getName(), command.getDescription());
- }
- }
-
- System.out.println("\nFor help on a specific command type:\nhelp [command]");
- }
-
- /**
- * Print "help" with usage
- */
- private void printHelp(final String commandLineSyntax, final Options options) {
- final HelpFormatter helpFormatter = new HelpFormatter();
- helpFormatter.printHelp(commandLineSyntax, options, true);
- }
-
- public void printUsage(final String action) {
- Command<StratosCommandContext> command = commands.get(action);
- if (command == null) {
- return;
- }
- printUsage(command);
- }
-
- private void printUsage(Command<StratosCommandContext> command) {
- Options options = command.getOptions();
- if (options != null) {
- if (StringUtils.isNotBlank(command.getArgumentSyntax())) {
- printUsage(command.getName() + " " + command.getArgumentSyntax(), options);
- } else {
- printUsage(command.getName(), options);
- }
- } else {
- System.out.print("usage: ");
- if (StringUtils.isNotBlank(command.getArgumentSyntax())) {
- System.out.println(command.getName() + " " + command.getArgumentSyntax());
- } else {
- System.out.println(command.getName());
- }
- }
- }
-
- /**
- * Print "usage"
- */
- private void printUsage(final String commandLineSyntax, final Options options) {
- final PrintWriter writer = new PrintWriter(System.out);
- final HelpFormatter usageFormatter = new HelpFormatter();
- usageFormatter.printUsage(writer, 80, commandLineSyntax, options);
- writer.flush();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/StratosCommandContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/StratosCommandContext.java b/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/StratosCommandContext.java
deleted file mode 100644
index e4f7652..0000000
--- a/components/org.apache.stratos.adc.mgt.cli/2.1.3/src/main/java/org/apache/stratos/adc/mgt/cli/StratosCommandContext.java
+++ /dev/null
@@ -1,31 +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.stratos.adc.mgt.cli;
-
-public class StratosCommandContext extends CommandContext {
-
- public StratosCommandContext(StratosApplication application) {
- super(application);
- }
-
- public StratosApplication getStratosApplication() {
- return (StratosApplication) getApplication();
- }
-
-}