diff --git a/components/org.apache.stratos.autoscaler/pom.xml b/components/org.apache.stratos.autoscaler/pom.xml index 8a727015fd..5faa872575 100644 --- a/components/org.apache.stratos.autoscaler/pom.xml +++ b/components/org.apache.stratos.autoscaler/pom.xml @@ -17,31 +17,27 @@ specific language governing permissions and limitations under the License. --> - - + 4.0.0 org.apache.stratos stratos-components-parent - 4.1.1 + 4.1.2-SNAPSHOT - 4.0.0 org.apache.stratos.autoscaler bundle Apache Stratos - Autoscaler Autoscaler components - http://apache.org org.wso2.carbon org.wso2.carbon.registry.core - ${carbon.platform.version} + ${carbon.kernel.version} provided - org.drools drools-core @@ -102,16 +98,6 @@ mvel2 2.1.3.Final - org.drools drools-verifier @@ -162,7 +148,7 @@ org.wso2.carbon org.wso2.carbon.utils - ${wso2carbon.version} + ${carbon.kernel.version} provided @@ -175,7 +161,7 @@ org.wso2.carbon org.wso2.carbon.ntask.core provided - ${wso2carbon.version} + ${carbon.kernel.version} org.apache.stratos @@ -195,7 +181,7 @@ org.wso2.carbon org.wso2.carbon.identity.application.mgt.stub - ${wso2carbon.version} + ${carbon.kernel.version} com.nimbusds.wso2 @@ -213,7 +199,6 @@ org.apache.felix maven-bundle-plugin - true @@ -223,7 +208,6 @@ !org.apache.stratos.autoscaler.internal.*,org.apache.stratos.autoscaler.* - org.osgi.framework.*;resolution:=optional, org.apache.stratos.common.services.*; version="${project.version}", *;resolution:=optional @@ -260,7 +244,4 @@ - - 5.5.0.Final - - + \ No newline at end of file diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithms/partition/RoundRobin.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithms/partition/RoundRobin.java index 1ced90359f..2544e158a5 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithms/partition/RoundRobin.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithms/partition/RoundRobin.java @@ -93,7 +93,7 @@ public PartitionContext getNextScaleDownPartitionContext(PartitionContext[] part } } - if (partitionContexts[selectedIndex].getNonTerminatedMemberCount() < partitionContexts[selectedIndex].getMax()) { + if (partitionContexts[selectedIndex].getNonTerminatedMemberCount() <= partitionContexts[selectedIndex].getMax()) { if (log.isDebugEnabled()) { log.debug(String.format("[round-robin algorithm] [scale-down] [partition] %s has has members that" + diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/ApplicationHolder.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/ApplicationHolder.java index 47c3a8bfe3..2176bbcb35 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/ApplicationHolder.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/ApplicationHolder.java @@ -71,17 +71,16 @@ public static Applications getApplications() { if (applications == null) { synchronized (ApplicationHolder.class) { if (applications == null) { + // create a new Applications object for autoscaler + applications = new Applications(); + // retrieve from registry if (log.isDebugEnabled()) { - log.debug("Trying to retrieve applications from registry..."); + log.debug("Loading applications persisted in registry..."); } - applications = AutoscalerUtil.getApplications(); - if (applications == null) { - if (log.isDebugEnabled()) { - log.debug("No applications found in registry"); - } - // create a new Applications object - applications = new Applications(); + applications = AutoscalerUtil.loadApplicationsFromRegistry(applications); + if (applications.getApplications().isEmpty()) { + log.info("No applications found in registry."); } } } diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/ApplicationUtils.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/ApplicationUtils.java index 874666e925..d43f364fa7 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/ApplicationUtils.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/ApplicationUtils.java @@ -37,11 +37,11 @@ import java.util.regex.Pattern; public class ApplicationUtils { - private static final Log log = LogFactory.getLog(ApplicationUtils.class); - public static final String TOKEN_PAYLOAD_PARAM_NAME = "TOKEN"; public static final String DEPLOYMENT = "DEPLOYMENT"; + private static final String PORT_SEPARATOR="|"; public static final String PAYLOAD_PARAMETER = "payload_parameter."; + private static final Log log = LogFactory.getLog(ApplicationUtils.class); public static Pattern ALIAS_PATTERN = Pattern.compile("([a-z0-9]+([-][a-z0-9])*)+"); public static boolean isAliasValid(String alias) { @@ -76,7 +76,13 @@ public static Properties getGlobalPayloadData() { return globalProperties; } - private static String createPortMappingPayloadString(Cartridge cartridge) { + /** + * This method creates payload string with port numbers in + * 'PORTS': '9443|8280|8243' format + * @param cartridge + * @return String containing ports + */ + private static String createPortsToPayloadString(Cartridge cartridge) { // port mappings StringBuilder portMapBuilder = new StringBuilder(); @@ -88,8 +94,7 @@ private static String createPortMappingPayloadString(Cartridge cartridge) { } for (PortMapping portMapping : portMappings) { - int port = portMapping.getPort(); - portMapBuilder.append(port).append("|"); + portMapBuilder.append(portMapping.getPort()).append(PORT_SEPARATOR); } // remove last "|" character @@ -98,6 +103,39 @@ private static String createPortMappingPayloadString(Cartridge cartridge) { return portMappingString; } + /** + * This method creates payload string with port mappings in following format. + * PORT_MAPPINGS='NAME:mgt-console|PROTOCOL:https|PORT:30649|PROXY_PORT:0|TYPE:NodePort; + * NAME:pt-http|PROTOCOL:http|PORT:30650|PROXY_PORT:0|TYPE:NodePort; + * NAME:pt-https|PROTOCOL:https|PORT:30651|PROXY_PORT:0|TYPE:NodePort + * @param cartridge + * @return string containing port mapping + */ + private static String createPortMappingsToPayloadString(Cartridge cartridge) { + + // port mappings + StringBuilder portMapBuilder = new StringBuilder(); + PortMapping[] portMappings = cartridge.getPortMappings(); + + if (cartridge.getPortMappings()[0] == null) { + // first element is null, which means no port mappings. + return null; + } + + for (PortMapping portMapping : portMappings) { + int port = portMapping.getPort(); + //Format : NAME:mgt-console|PROTOCOL:https|PORT:30649|PROXY_PORT:0|TYPE:NodePort; + portMapBuilder.append(String.format("NAME:%s|PROTOCOL:%s|PORT:%d|PROXY_PORT:%d|TYPE:%s;", + portMapping.getName(), portMapping.getProtocol(), + portMapping.getPort(), portMapping.getProxyPort(), + portMapping.getKubernetesPortType())); + } + //remove last ";" character + String portMappingString = portMapBuilder.toString().replaceAll(";$", ""); + return portMappingString; + + } + public static StringBuilder getTextPayload(String appId, String groupName, String clusterId) { StringBuilder payloadBuilder = new StringBuilder(); @@ -139,12 +177,12 @@ public static StringBuilder getTextPayload(String appId, String groupName, Strin public static PayloadData createPayload(String appId, String groupName, Cartridge cartridge, String subscriptionKey, int tenantId, String clusterId, String hostName, String repoUrl, String alias, Map customPayloadEntries, String[] dependencyAliases, org.apache.stratos.common.Properties properties, String oauthToken, String[] dependencyClusterIDs, - String[] exportMetadata, String[] importMetadata,String lvsVirtualIP) + String[] exportMetadata, String[] importMetadata, String lvsVirtualIP) throws ApplicationDefinitionException { //Create the payload BasicPayloadData basicPayloadData = createBasicPayload(appId, groupName, cartridge, subscriptionKey, - clusterId, hostName, repoUrl, alias, tenantId, dependencyAliases, dependencyClusterIDs, exportMetadata, importMetadata,lvsVirtualIP); + clusterId, hostName, repoUrl, alias, tenantId, dependencyAliases, dependencyClusterIDs, exportMetadata, importMetadata, lvsVirtualIP); //Populate the basic payload details basicPayloadData.populatePayload(); @@ -212,7 +250,7 @@ private static BasicPayloadData createBasicPayload(String appId, String groupNam String subscriptionKey, String clusterId, String hostName, String repoUrl, String alias, int tenantId, String[] dependencyAliases, String[] dependencyCLusterIDs, - String[] exportMetadata, String[] importMetadata,String lvsVirtualIP) { + String[] exportMetadata, String[] importMetadata, String lvsVirtualIP) { BasicPayloadData basicPayloadData = new BasicPayloadData(); basicPayloadData.setAppId(appId); @@ -221,10 +259,11 @@ private static BasicPayloadData createBasicPayload(String appId, String groupNam basicPayloadData.setSubscriptionKey(subscriptionKey); //basicPayloadData.setDeployment("default");//currently hard coded to default basicPayloadData.setMultitenant(String.valueOf(cartridge.getMultiTenant())); - basicPayloadData.setPortMappings(createPortMappingPayloadString(cartridge)); + basicPayloadData.setPorts(createPortsToPayloadString(cartridge)); + basicPayloadData.setPortMappings(createPortMappingsToPayloadString(cartridge)); basicPayloadData.setServiceName(cartridge.getType()); basicPayloadData.setProvider(cartridge.getProvider()); - basicPayloadData.setLvsVirtualIP(lvsVirtualIP); + basicPayloadData.setLvsVirtualIP(lvsVirtualIP); if (repoUrl != null) { basicPayloadData.setGitRepositoryUrl(repoUrl); diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyBuilder.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyBuilder.java index 7d3b59e765..fe5ae12430 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyBuilder.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyBuilder.java @@ -39,14 +39,30 @@ private DependencyBuilder() { } - private static class Holder { - private static final DependencyBuilder INSTANCE = new DependencyBuilder(); - } - public static DependencyBuilder getInstance() { return Holder.INSTANCE; } + /** + * Utility method to get the group alias from the startup order Eg: group.mygroup + * + * @param startupOrder startup order + * @return group alias + */ + public static String getGroupFromStartupOrder(String startupOrder) { + return startupOrder.substring(AutoscalerConstants.GROUP.length() + 1); + } + + /** + * Utility method to get the cluster alias from startup order Eg: cartridge.myphp + * + * @param startupOrder startup order + * @return cluster alias + */ + public static String getClusterFromStartupOrder(String startupOrder) { + return startupOrder.substring(AutoscalerConstants.CARTRIDGE.length() + 1); + } + /** * This will build the dependency tree based on the given dependencies * @@ -236,23 +252,7 @@ public Set buildScalingDependencies(ParentComponent compon return scalingDependentLists; } - /** - * Utility method to get the group alias from the startup order Eg: group.mygroup - * - * @param startupOrder startup order - * @return group alias - */ - public static String getGroupFromStartupOrder(String startupOrder) { - return startupOrder.substring(AutoscalerConstants.GROUP.length() + 1); - } - - /** - * Utility method to get the cluster alias from startup order Eg: cartridge.myphp - * - * @param startupOrder startup order - * @return cluster alias - */ - public static String getClusterFromStartupOrder(String startupOrder) { - return startupOrder.substring(AutoscalerConstants.CARTRIDGE.length() + 1); + private static class Holder { + private static final DependencyBuilder INSTANCE = new DependencyBuilder(); } } diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyTree.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyTree.java index 04af9b1ec4..00e3fd5bb2 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyTree.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/DependencyTree.java @@ -230,10 +230,6 @@ public List findAllChildrenOfAppContext() { allChildrenOfAppContext); } - public void setTerminationBehavior(TerminationBehavior terminationBehavior) { - this.terminationBehavior = terminationBehavior; - } - public boolean isTerminateDependent() { return this.getTerminationBehavior() == TerminationBehavior.TERMINATE_DEPENDENT; } @@ -242,13 +238,12 @@ public boolean isTerminateAll() { return this.getTerminationBehavior() == TerminationBehavior.TERMINATE_ALL; } - public TerminationBehavior getTerminationBehavior() { return terminationBehavior; } - public enum TerminationBehavior { - TERMINATE_ALL, TERMINATE_NONE, TERMINATE_DEPENDENT + public void setTerminationBehavior(TerminationBehavior terminationBehavior) { + this.terminationBehavior = terminationBehavior; } public String getId() { @@ -281,4 +276,8 @@ private void buildTreeStructure(ApplicationChildContext applicationChildContext, } } } + + public enum TerminationBehavior { + TERMINATE_ALL, TERMINATE_NONE, TERMINATE_DEPENDENT + } } diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/context/ApplicationChildContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/context/ApplicationChildContext.java index 1e4f3fd31d..56e2840fa3 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/context/ApplicationChildContext.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/dependency/context/ApplicationChildContext.java @@ -29,17 +29,16 @@ */ public abstract class ApplicationChildContext { - private String id; protected boolean started; + protected boolean hasStartupDependents; + protected boolean isGroupScalingEnabled; + private String id; private boolean terminated; private ClusterStatus status; private Stack statusLifeCycle; private List applicationChildContextList; private ApplicationChildContext parent; - protected boolean hasStartupDependents; - protected boolean isGroupScalingEnabled; - public ApplicationChildContext(String id, boolean killDependent) { applicationChildContextList = new ArrayList(); statusLifeCycle = new Stack(); diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java index 7ac88ebb53..d9378ab376 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/DefaultApplicationParser.java @@ -57,10 +57,10 @@ */ public class DefaultApplicationParser implements ApplicationParser { - private static final String METADATA_APPENDER = "-"; public static final String ALIAS = "alias"; public static final String CARTRIDGE_TYPE = "type"; public static final String LOAD_BALANCER = "lb"; + private static final String METADATA_APPENDER = "-"; private static Log log = LogFactory.getLog(DefaultApplicationParser.class); private List applicationClusterContexts; @@ -73,6 +73,29 @@ public DefaultApplicationParser() { } + /** + * Validates terminationBehavior. The terminationBehavior should be one of the following: + * 1. terminate-none + * 2. terminate-dependents + * 3. terminate-all + * + * @throws ApplicationDefinitionException if terminationBehavior is different to what is + * listed above + */ + private static void validateTerminationBehavior(String terminationBehavior) throws ApplicationDefinitionException { + + if (!(terminationBehavior == null || + AutoscalerConstants.TERMINATE_NONE.equals(terminationBehavior) || + AutoscalerConstants.TERMINATE_DEPENDENTS.equals(terminationBehavior) || + AutoscalerConstants.TERMINATE_ALL.equals(terminationBehavior))) { + throw new ApplicationDefinitionException("Invalid termination behaviour found: [ " + + terminationBehavior + " ], should be one of '" + + AutoscalerConstants.TERMINATE_NONE + "', '" + + AutoscalerConstants.TERMINATE_DEPENDENTS + "', '" + + AutoscalerConstants.TERMINATE_ALL + "'"); + } + } + @Override public Application parse(ApplicationContext applicationContext) throws ApplicationDefinitionException, CartridgeGroupNotFoundException, @@ -153,7 +176,7 @@ private void addSubscribableInfo(String applicationId, String cartridgeType, if (!ApplicationUtils.isAliasValid(alias)) { handleError(String.format("Alias is not valid: [application-id] %s " + - "[cartridge-type] %s [alias] %s [valid-pattern] %s", applicationId, cartridgeType, alias, + "[cartridge-type] %s [alias] %s [valid-pattern] %s", applicationId, cartridgeType, alias, ApplicationUtils.ALIAS_PATTERN.pattern())); } @@ -235,7 +258,6 @@ private Map getSubscribableInformation(Applicat return subscribableInfoContextMap; } - /** * Builds the Application structure * @@ -334,7 +356,6 @@ private Application buildCompositeAppStructure(ApplicationContext applicationCon return application; } - /** * Parse Subscription Information * @@ -455,7 +476,7 @@ private Map> parseLeafLevelSubscriptions( subscribableInfoContext.getDeploymentPolicy(), isLB, tenantRange, subscribableInfoContext.getDependencyAliases(), subscribableInfoContext.getProperties(), arrDependencyClusterIDs, arrExportMetadata, - arrImportMetadata,subscribableInfoContext.getLvsVirtualIP()); + arrImportMetadata, subscribableInfoContext.getLvsVirtualIP()); appClusterCtxt.setAutoscalePolicyName(subscribableInfoContext.getAutoscalingPolicy()); appClusterCtxt.setProperties(subscribableInfoContext.getProperties()); @@ -528,29 +549,6 @@ private void createClusterDataMap(String applicationId, } } - /** - * Validates terminationBehavior. The terminationBehavior should be one of the following: - * 1. terminate-none - * 2. terminate-dependents - * 3. terminate-all - * - * @throws ApplicationDefinitionException if terminationBehavior is different to what is - * listed above - */ - private static void validateTerminationBehavior(String terminationBehavior) throws ApplicationDefinitionException { - - if (!(terminationBehavior == null || - AutoscalerConstants.TERMINATE_NONE.equals(terminationBehavior) || - AutoscalerConstants.TERMINATE_DEPENDENTS.equals(terminationBehavior) || - AutoscalerConstants.TERMINATE_ALL.equals(terminationBehavior))) { - throw new ApplicationDefinitionException("Invalid termination behaviour found: [ " + - terminationBehavior + " ], should be one of '" + - AutoscalerConstants.TERMINATE_NONE + "', '" + - AutoscalerConstants.TERMINATE_DEPENDENTS + "', '" + - AutoscalerConstants.TERMINATE_ALL + "'"); - } - } - /** * Parse Group information * @@ -942,12 +940,12 @@ private ApplicationClusterContext createApplicationClusterContext(String appId, String alias, String clusterId, String hostname, String deploymentPolicy, boolean isLB, String tenantRange, String[] dependencyAliases, Properties properties, String[] dependencyClustorIDs, - String[] exportMetadata, String[] importMetadata,String lvsVirtualIP) + String[] exportMetadata, String[] importMetadata, String lvsVirtualIP) throws ApplicationDefinitionException { // Create text payload PayloadData payloadData = ApplicationUtils.createPayload(appId, groupName, cartridge, subscriptionKey, tenantId, clusterId, - hostname, repoUrl, alias, null, dependencyAliases, properties, oauthToken, dependencyClustorIDs, exportMetadata, importMetadata,lvsVirtualIP); + hostname, repoUrl, alias, null, dependencyAliases, properties, oauthToken, dependencyClustorIDs, exportMetadata, importMetadata, lvsVirtualIP); String textPayload = payloadData.toString(); if (log.isDebugEnabled()) { diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/ParserUtils.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/ParserUtils.java index 904ab53a5b..aa42b7f870 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/ParserUtils.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/parser/ParserUtils.java @@ -72,13 +72,13 @@ public static Set convertStartupOrder(String[] startupOrderArr, Gr for (String commaSeparatedStartupOrder : startupOrderArr) { // convertStartupOrder all Startup Orders to aliases-based List components = Arrays.asList(commaSeparatedStartupOrder.split(",")); - for(String component : components) { + for (String component : components) { boolean aliasFound = false; - if(component.startsWith(AutoscalerConstants.GROUP)) { + if (component.startsWith(AutoscalerConstants.GROUP)) { String groupAlias = component.substring(AutoscalerConstants.GROUP.length() + 1); - if(groupContext.getGroupContexts() != null) { - for(GroupContext context : groupContext.getGroupContexts()) { - if(context.getAlias().equals(groupAlias)) { + if (groupContext.getGroupContexts() != null) { + for (GroupContext context : groupContext.getGroupContexts()) { + if (context.getAlias().equals(groupAlias)) { aliasFound = true; } } @@ -87,15 +87,15 @@ public static Set convertStartupOrder(String[] startupOrderArr, Gr } else { String cartridgeAlias = component.substring( AutoscalerConstants.CARTRIDGE.length() + 1); - if(groupContext.getCartridgeContexts() != null) { - for(CartridgeContext context : groupContext.getCartridgeContexts()) { - if(context.getSubscribableInfoContext().getAlias().equals(cartridgeAlias)) { + if (groupContext.getCartridgeContexts() != null) { + for (CartridgeContext context : groupContext.getCartridgeContexts()) { + if (context.getSubscribableInfoContext().getAlias().equals(cartridgeAlias)) { aliasFound = true; } } } } - if(!aliasFound) { + if (!aliasFound) { String msg = "The startup-order defined in the [group] " + groupContext.getName() + " is not correct. [startup-order-alias] " + component + " is not there in the application."; diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/BasicPayloadData.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/BasicPayloadData.java index ebe17aa931..67d88e4909 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/BasicPayloadData.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/BasicPayloadData.java @@ -32,7 +32,7 @@ public class BasicPayloadData implements Serializable { private static Log log = LogFactory.getLog(BasicPayloadData.class); - + protected StringBuilder payloadBuilder; private String appId; private String groupName; private String serviceName; @@ -48,6 +48,7 @@ public class BasicPayloadData implements Serializable { private String subscriptionKey; private String applicationPath; private String gitRepositoryUrl; + private String ports; private String portMappings; private String multitenant; private String provider; @@ -56,9 +57,7 @@ public class BasicPayloadData implements Serializable { private String[] dependencyClusterIDs; private String[] exportMetadataKeys; private String[] importMetadataKeys; - private String lvsVirtualIP; - - protected StringBuilder payloadBuilder; + private String lvsVirtualIP; public BasicPayloadData() { @@ -96,7 +95,9 @@ public void populatePayload() { payloadBuilder.append(","); payloadBuilder.append("REPO_URL=" + getGitRepositoryUrl()); payloadBuilder.append(","); - payloadBuilder.append("PORTS=" + getPortMappings()); + payloadBuilder.append("PORTS=" + getPorts()); + payloadBuilder.append(","); + payloadBuilder.append("PORT_MAPPINGS=" + getPortMappings()); payloadBuilder.append(","); payloadBuilder.append("PROVIDER=" + getProvider()); @@ -129,10 +130,10 @@ public void populatePayload() { if (getExportMetadataKeys() != null) { payloadBuilder.append("IMPORT_METADATA_KEYS=" + getImportMetadataKeys()); } - payloadBuilder.append(","); - if(getLvsVirtualIP()!=null && !getLvsVirtualIP().equals("")){ - payloadBuilder.append("LVS_VIRTUAL_IP=" +getLvsVirtualIP()); - } + payloadBuilder.append(","); + if (getLvsVirtualIP() != null && !getLvsVirtualIP().equals("")) { + payloadBuilder.append("LVS_VIRTUAL_IP=" + getLvsVirtualIP()); + } } public String getServiceName() { @@ -228,6 +229,14 @@ public void setGitRepositoryUrl(String gitRepositoryUrl) { this.gitRepositoryUrl = gitRepositoryUrl; } + public String getPorts() { + return ports; + } + + public void setPorts(String ports) { + this.ports = ports; + } + public String getPortMappings() { return portMappings; } @@ -236,6 +245,7 @@ public void setPortMappings(String portMappings) { this.portMappings = portMappings; } + public String getMultitenant() { return multitenant; } @@ -394,11 +404,11 @@ public void setImportMetadataKeys(String[] importMetadataKeys) { this.importMetadataKeys = importMetadataKeys; } - public String getLvsVirtualIP() { - return lvsVirtualIP; - } + public String getLvsVirtualIP() { + return lvsVirtualIP; + } - public void setLvsVirtualIP(String lvsVirtualIP) { - this.lvsVirtualIP = lvsVirtualIP; - } + public void setLvsVirtualIP(String lvsVirtualIP) { + this.lvsVirtualIP = lvsVirtualIP; + } } diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/PayloadFactory.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/PayloadFactory.java index e022f7b9cb..f4ad48b649 100755 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/PayloadFactory.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/payload/PayloadFactory.java @@ -26,8 +26,8 @@ public class PayloadFactory { - private static final String LB_IDENTIFIER = "lb"; public static final String DATA_IDENTIFIER = "data"; + private static final String LB_IDENTIFIER = "lb"; private static Log log = LogFactory.getLog(PayloadFactory.class); /** diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ApplicationClusterContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ApplicationClusterContext.java index 721a948807..cd48cd4ffa 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ApplicationClusterContext.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ApplicationClusterContext.java @@ -45,15 +45,6 @@ public class ApplicationClusterContext implements Serializable { private Properties properties; private String[] dependencyClusterIds; - - public PersistenceContext getPersistenceContext() { - return persistenceContext; - } - - public void setPersistenceContext(PersistenceContext persistenceContext) { - this.persistenceContext = persistenceContext; - } - private PersistenceContext persistenceContext; public ApplicationClusterContext(String cartridgeType, String clusterId, String hostName, @@ -69,6 +60,14 @@ public ApplicationClusterContext(String cartridgeType, String clusterId, String this.dependencyClusterIds = dependencyClusterIds; } + public PersistenceContext getPersistenceContext() { + return persistenceContext; + } + + public void setPersistenceContext(PersistenceContext persistenceContext) { + this.persistenceContext = persistenceContext; + } + public String getClusterId() { return clusterId; } diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ApplicationContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ApplicationContext.java index ec79fcf0eb..5c2b1f25bd 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ApplicationContext.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ApplicationContext.java @@ -25,12 +25,10 @@ public class ApplicationContext implements Serializable { - private static final long serialVersionUID = 6704036501869668646L; - public static final String STATUS_CREATED = "Created"; public static final String STATUS_DEPLOYED = "Deployed"; public static final String STATUS_UNDEPLOYING = "Undeploying"; - + private static final long serialVersionUID = 6704036501869668646L; private String applicationId; private String alias; private boolean multiTenant; diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ComponentContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ComponentContext.java index 98a0d5d676..d3fc2e6f1e 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ComponentContext.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/ComponentContext.java @@ -54,11 +54,11 @@ public void setDependencyContext(DependencyContext dependencyContext) { this.dependencyContext = dependencyContext; } - public void setApplicationClusterContexts(ApplicationClusterContext[] applicationClusterContexts) { - this.applicationClusterContexts = applicationClusterContexts; - } - public ApplicationClusterContext[] getApplicationClusterContexts() { return applicationClusterContexts; } + + public void setApplicationClusterContexts(ApplicationClusterContext[] applicationClusterContexts) { + this.applicationClusterContexts = applicationClusterContexts; + } } diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/SubscribableInfoContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/SubscribableInfoContext.java index 4ecb4fa817..c4b57f0176 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/SubscribableInfoContext.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/pojo/SubscribableInfoContext.java @@ -36,8 +36,8 @@ public class SubscribableInfoContext implements Serializable { private ArtifactRepositoryContext artifactRepositoryContext; private Properties properties; private PersistenceContext persistenceContext; - //This is the virtual IP that we need to pass for use LVS as Load Balancer - private String lvsVirtualIP; + //This is the virtual IP that we need to pass for use LVS as Load Balancer + private String lvsVirtualIP; public String getAlias() { return alias; @@ -111,11 +111,11 @@ public void setPersistenceContext(PersistenceContext persistenceContext) { this.persistenceContext = persistenceContext; } - public String getLvsVirtualIP() { - return lvsVirtualIP; - } + public String getLvsVirtualIP() { + return lvsVirtualIP; + } - public void setLvsVirtualIP(String lvsVirtualIP) { - this.lvsVirtualIP = lvsVirtualIP; - } + public void setLvsVirtualIP(String lvsVirtualIP) { + this.lvsVirtualIP = lvsVirtualIP; + } } diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java index 686e158c7f..912a2f6b03 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java @@ -74,10 +74,10 @@ public static synchronized void handleApplicationDeployment(Application applicat log.debug("Handling application creation event: [application-id] " + application.getUniqueIdentifier()); } - AutoscalerCloudControllerClient.getInstance().createApplicationClusters(application.getUniqueIdentifier(), - appClusterContexts); ApplicationHolder.persistApplication(application); ApplicationsEventPublisher.sendApplicationCreatedEvent(application); + AutoscalerCloudControllerClient.getInstance().createApplicationClusters(application.getUniqueIdentifier(), + appClusterContexts); } public static ApplicationInstance handleApplicationInstanceCreatedEvent(String appId, diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/AutoscalerCloudControllerClient.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/AutoscalerCloudControllerClient.java index 9504d53027..012420694b 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/AutoscalerCloudControllerClient.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/AutoscalerCloudControllerClient.java @@ -52,18 +52,6 @@ public class AutoscalerCloudControllerClient { private static CloudControllerServiceStub stub; - /* An instance of a CloudControllerClient is created when the class is loaded. - * Since the class is loaded only once, it is guaranteed that an object of - * CloudControllerClient is created only once. Hence it is singleton. - */ - private static class InstanceHolder { - private static final AutoscalerCloudControllerClient INSTANCE = new AutoscalerCloudControllerClient(); - } - - public static AutoscalerCloudControllerClient getInstance() { - return InstanceHolder.INSTANCE; - } - private AutoscalerCloudControllerClient() { try { XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration(); @@ -81,6 +69,10 @@ private AutoscalerCloudControllerClient() { } } + public static AutoscalerCloudControllerClient getInstance() { + return InstanceHolder.INSTANCE; + } + public synchronized MemberContext startInstance(PartitionRef partition, String clusterId, String clusterInstanceId, String networkPartitionId, @@ -182,7 +174,6 @@ public synchronized void createApplicationClusters(String appId, } } - private Volume[] convertVolumesToStubVolumes(VolumeContext[] volumeContexts) { ArrayList volumes = new ArrayList(); @@ -233,4 +224,12 @@ public void terminateAllInstances(String clusterId) throws RemoteException, log.debug(String.format("Service call terminateInstances() returned in %dms", (endTime - startTime))); } } + + /* An instance of a CloudControllerClient is created when the class is loaded. + * Since the class is loaded only once, it is guaranteed that an object of + * CloudControllerClient is created only once. Hence it is singleton. + */ + private static class InstanceHolder { + private static final AutoscalerCloudControllerClient INSTANCE = new AutoscalerCloudControllerClient(); + } } diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/AutoscalerContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/AutoscalerContext.java index 3a988e6061..0af9b56f74 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/AutoscalerContext.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/AutoscalerContext.java @@ -49,12 +49,10 @@ public class AutoscalerContext { private static final String AS_APPLICATION_ID_TO_APPLICATION_MONITOR_MAP = "AS_APPLICATION_ID_TO_APPLICATION_MONITOR_MAP"; private static final String AS_PENDING_APPLICATION_MONITOR_LIST = "AS_PENDING_APPLICATION_MONITOR_LIST"; private static final String AS_APPLICATIOIN_ID_TO_NETWORK_PARTITION_ALGO_CTX_MAP = "AS_APPLICATIOIN_ID_TO_NETWORK_PARTITION_ALGO_CTX_MAP"; - private boolean clustered; - private boolean coordinator; - private static volatile AutoscalerContext instance; private final transient DistributedObjectProvider distributedObjectProvider; - + private boolean clustered; + private boolean coordinator; // Map private Map applicationContextMap; // Map diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/application/ParentInstanceContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/application/ParentInstanceContext.java index 5d7b626323..53adbcc465 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/application/ParentInstanceContext.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/application/ParentInstanceContext.java @@ -33,14 +33,14 @@ * This will hold the application instance related info. */ public class ParentInstanceContext extends InstanceContext { + //partitions of this network partition + private final List partitionCtxts; //key=id of the child, value=ScalingEvent private Map idToScalingEvent; //key=id of the child, value=ScalingUpBeyondMaxEvent private Map idToScalingOverMaxEvent; //key=id of the child, value=ScalingDownBeyondMinEvent private Map idToScalingDownBeyondMinEvent; - //partitions of this network partition - private final List partitionCtxts; public ParentInstanceContext(String id) { super(id); diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/AbstractClusterContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/AbstractClusterContext.java index ae12c7e95c..43608f582f 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/AbstractClusterContext.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/AbstractClusterContext.java @@ -36,8 +36,8 @@ public class AbstractClusterContext implements Serializable { // cluster id protected String clusterId; - private String serviceId; protected Map clusterInstanceMap; + private String serviceId; public AbstractClusterContext(String clusterId, String serviceId) { diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/ClusterInstanceContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/ClusterInstanceContext.java index 3c87e3e923..019954a10f 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/ClusterInstanceContext.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/cluster/ClusterInstanceContext.java @@ -507,15 +507,15 @@ public StatefulKnowledgeSession getMinCheckKnowledgeSession() { return minCheckKnowledgeSession; } - public StatefulKnowledgeSession getMaxCheckKnowledgeSession() { - return maxCheckKnowledgeSession; - } - public void setMinCheckKnowledgeSession( StatefulKnowledgeSession minCheckKnowledgeSession) { this.minCheckKnowledgeSession = minCheckKnowledgeSession; } + public StatefulKnowledgeSession getMaxCheckKnowledgeSession() { + return maxCheckKnowledgeSession; + } + public StatefulKnowledgeSession getObsoleteCheckKnowledgeSession() { return obsoleteCheckKnowledgeSession; } @@ -581,4 +581,22 @@ public FactHandle getDependentScaleCheckFactHandle() { public void setDependentScaleCheckFactHandle(FactHandle dependentScaleCheckFactHandle) { this.dependentScaleCheckFactHandle = dependentScaleCheckFactHandle; } + + public void setCurveFinderCoefficientsOfMemoryConsumption(double a, double b, double c){ + memoryConsumption.setA(a); + memoryConsumption.setB(b); + memoryConsumption.setC(c); + } + + public void setCurveFinderCoefficientsOfLoadAverage(double a, double b, double c){ + loadAverage.setA(a); + loadAverage.setB(b); + loadAverage.setC(c); + } + + public void setCurveFinderCoeffcientsOfRequestsInFlight(double a, double b, double c){ + requestsInFlight.setA(a); + requestsInFlight.setB(b); + requestsInFlight.setC(c); + } } diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/member/MemberStatsContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/member/MemberStatsContext.java index 69810959fd..4f89f79bcd 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/member/MemberStatsContext.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/member/MemberStatsContext.java @@ -54,54 +54,54 @@ public MemoryConsumption getMemoryConsumption() { return memoryConsumption; } - public void setAverageLoadAverage(float value) { - loadAverage.setAverage(value); - } - - public void setAverageMemoryConsumption(float value) { - memoryConsumption.setAverage(value); - } - - public void setGradientOfLoadAverage(float value) { - loadAverage.setGradient(value); - } - - public void setGradientOfMemoryConsumption(float value) { - memoryConsumption.setGradient(value); - } - - public void setSecondDerivativeOfLoadAverage(float value) { - loadAverage.setSecondDerivative(value); - } - - public void setSecondDerivativeOfMemoryConsumption(float value) { - memoryConsumption.setSecondDerivative(value); - } - public float getAverageLoadAverage() { return loadAverage.getAverage(); } + public void setAverageLoadAverage(float value) { + loadAverage.setAverage(value); + } + public float getAverageMemoryConsumption() { return memoryConsumption.getAverage(); } + public void setAverageMemoryConsumption(float value) { + memoryConsumption.setAverage(value); + } + public float getGradientOfLoadAverage() { return loadAverage.getGradient(); } + public void setGradientOfLoadAverage(float value) { + loadAverage.setGradient(value); + } + public float getGradientOfMemoryConsumption() { return memoryConsumption.getGradient(); } + public void setGradientOfMemoryConsumption(float value) { + memoryConsumption.setGradient(value); + } + public float getSecondDerivativeOfLoadAverage() { return loadAverage.getSecondDerivative(); } + public void setSecondDerivativeOfLoadAverage(float value) { + loadAverage.setSecondDerivative(value); + } + public float getSecondDerivativeOfMemoryConsumption() { return memoryConsumption.getSecondDerivative(); } + public void setSecondDerivativeOfMemoryConsumption(float value) { + memoryConsumption.setSecondDerivative(value); + } + public String getInstanceId() { return instanceId; } diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/ClusterLevelPartitionContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/ClusterLevelPartitionContext.java index 3ef2e45d89..69dba49d04 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/ClusterLevelPartitionContext.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/ClusterLevelPartitionContext.java @@ -93,6 +93,36 @@ public ClusterLevelPartitionContext(long memberExpiryTime) { this.pendingMembers = new ArrayList(); } + public ClusterLevelPartitionContext(PartitionRef partition, String networkPartitionId, String deploymentPolicyId) { + + super(partition, networkPartitionId, deploymentPolicyId); + this.pendingMembers = new ArrayList(); + this.activeMembers = new ArrayList(); + this.terminationPendingMembers = new ArrayList(); + this.obsoletedMembers = new ConcurrentHashMap(); + memberStatsContexts = new ConcurrentHashMap(); + + terminationPendingStartedTime = new HashMap(); + // check if a different value has been set for expiryTime + XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration(); + pendingMemberExpiryTime = conf.getLong(StratosConstants.PENDING_MEMBER_EXPIRY_TIMEOUT, 900000); + obsoltedMemberExpiryTime = conf.getLong(StratosConstants.OBSOLETED_MEMBER_EXPIRY_TIMEOUT, 86400000); + spinTerminateParallel = conf.getBoolean(StratosConstants.SPIN_TERMINATE_PARALLEL, false); + terminationPendingMemberExpiryTime = conf.getLong(StratosConstants.PENDING_TERMINATION_MEMBER_EXPIRY_TIMEOUT, 1800000); + if (log.isDebugEnabled()) { + log.debug("Member expiry time is set to: " + pendingMemberExpiryTime); + log.debug("Member obsoleted expiry time is set to: " + obsoltedMemberExpiryTime); + log.debug("Member pending termination expiry time is set to: " + terminationPendingMemberExpiryTime); + } + + Thread th = new Thread(new PendingMemberWatcher(this)); + th.start(); + Thread th2 = new Thread(new ObsoletedMemberWatcher(this)); + th2.start(); + Thread th3 = new Thread(new TerminationPendingMemberWatcher(this)); + th3.start(); + } + public void terminateAllRemainingInstances() { // Forcefully deleting remaining active members @@ -137,36 +167,6 @@ private void terminateForcefully(String memberId) { } } - public ClusterLevelPartitionContext(PartitionRef partition, String networkPartitionId, String deploymentPolicyId) { - - super(partition, networkPartitionId, deploymentPolicyId); - this.pendingMembers = new ArrayList(); - this.activeMembers = new ArrayList(); - this.terminationPendingMembers = new ArrayList(); - this.obsoletedMembers = new ConcurrentHashMap(); - memberStatsContexts = new ConcurrentHashMap(); - - terminationPendingStartedTime = new HashMap(); - // check if a different value has been set for expiryTime - XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration(); - pendingMemberExpiryTime = conf.getLong(StratosConstants.PENDING_MEMBER_EXPIRY_TIMEOUT, 900000); - obsoltedMemberExpiryTime = conf.getLong(StratosConstants.OBSOLETED_MEMBER_EXPIRY_TIMEOUT, 86400000); - spinTerminateParallel = conf.getBoolean(StratosConstants.SPIN_TERMINATE_PARALLEL, false); - terminationPendingMemberExpiryTime = conf.getLong(StratosConstants.PENDING_TERMINATION_MEMBER_EXPIRY_TIMEOUT, 1800000); - if (log.isDebugEnabled()) { - log.debug("Member expiry time is set to: " + pendingMemberExpiryTime); - log.debug("Member obsoleted expiry time is set to: " + obsoltedMemberExpiryTime); - log.debug("Member pending termination expiry time is set to: " + terminationPendingMemberExpiryTime); - } - - Thread th = new Thread(new PendingMemberWatcher(this)); - th.start(); - Thread th2 = new Thread(new ObsoletedMemberWatcher(this)); - th2.start(); - Thread th3 = new Thread(new TerminationPendingMemberWatcher(this)); - th3.start(); - } - public long getTerminationPendingStartedTimeOfMember(String memberId) { return terminationPendingStartedTime.get(memberId); } @@ -488,7 +488,7 @@ public int getTotalMemberCount() { public int getNonTerminatedMemberCount() { int nonTerminatedMemberCount = 0; - if(spinTerminateParallel) { + if (spinTerminateParallel) { // Returning all the pending members as there shouldn't be a spawning // before complete termination. // Will be applicable only when having min1*max1 situation @@ -653,8 +653,8 @@ public void movePendingMemberToObsoleteMembers(String memberId) { } private class PendingMemberWatcher implements Runnable { - private ClusterLevelPartitionContext ctxt; private final Log log = LogFactory.getLog(PendingMemberWatcher.class); + private ClusterLevelPartitionContext ctxt; public PendingMemberWatcher(ClusterLevelPartitionContext ctxt) { this.ctxt = ctxt; @@ -675,16 +675,16 @@ public void run() { String clusterInstanceId = pendingMember.getClusterInstanceId(); String clusterId = pendingMember.getClusterId(); String serviceName = pendingMember.getCartridgeType(); - Service service = TopologyManager.getTopology(). + Service service = TopologyManager.getTopology(). getService(serviceName); ClusterStatus status = ClusterStatus.Terminated; - if(service != null) { + if (service != null) { Cluster cluster = service.getCluster(clusterId); - if(cluster != null) { + if (cluster != null) { ClusterInstance instance = cluster. getInstanceContexts(clusterInstanceId); - if(instance!= null) { + if (instance != null) { status = instance.getStatus(); } } @@ -725,8 +725,8 @@ public void run() { } private class ObsoletedMemberWatcher implements Runnable { - private ClusterLevelPartitionContext ctxt; private final Log log = LogFactory.getLog(ObsoletedMemberWatcher.class); + private ClusterLevelPartitionContext ctxt; public ObsoletedMemberWatcher(ClusterLevelPartitionContext ctxt) { this.ctxt = ctxt; @@ -792,8 +792,8 @@ public void run() { * This thread is responsible for moving member to obsolete list if pending termination timeout happens */ private class TerminationPendingMemberWatcher implements Runnable { - private ClusterLevelPartitionContext ctxt; private final Log log = LogFactory.getLog(TerminationPendingMemberWatcher.class); + private ClusterLevelPartitionContext ctxt; public TerminationPendingMemberWatcher(ClusterLevelPartitionContext ctxt) { this.ctxt = ctxt; diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/NetworkPartitionContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/NetworkPartitionContext.java index 678e898a94..0e79647035 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/NetworkPartitionContext.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/context/partition/network/NetworkPartitionContext.java @@ -121,8 +121,8 @@ public String getPartitionAlgorithm() { public List getInstanceIdToInstanceContextMap(String parentInstanceId) { List instanceContexts = new ArrayList(); - for(InstanceContext instanceContext : instanceIdToInstanceContextMap.values()) { - if(instanceContext.getParentInstanceId().equals(parentInstanceId)) { + for (InstanceContext instanceContext : instanceIdToInstanceContextMap.values()) { + if (instanceContext.getParentInstanceId().equals(parentInstanceId)) { instanceContexts.add(instanceContext); } } @@ -160,8 +160,8 @@ public ParentLevelPartitionContext getPartitionContextById(String partitionId) { public List getActiveInstances(String parentInstanceId) { List instanceContexts = new ArrayList(); - for(InstanceContext instanceContext : activeInstances) { - if(instanceContext.getParentInstanceId().equals(parentInstanceId)) { + for (InstanceContext instanceContext : activeInstances) { + if (instanceContext.getParentInstanceId().equals(parentInstanceId)) { instanceContexts.add(instanceContext); } } @@ -170,8 +170,8 @@ public List getActiveInstances(String parentInstanceId) { public List getPendingInstances(String parentInstanceId) { List instanceContexts = new ArrayList(); - for(InstanceContext instanceContext : pendingInstances) { - if(instanceContext.getParentInstanceId().equals(parentInstanceId)) { + for (InstanceContext instanceContext : pendingInstances) { + if (instanceContext.getParentInstanceId().equals(parentInstanceId)) { instanceContexts.add(instanceContext); } } @@ -188,8 +188,8 @@ public int getPendingInstancesCount() { public int getPendingInstancesCount(String parentInstanceId) { List instanceContexts = new ArrayList(); - for(InstanceContext instanceContext : pendingInstances) { - if(instanceContext.getParentInstanceId().equals(parentInstanceId)) { + for (InstanceContext instanceContext : pendingInstances) { + if (instanceContext.getParentInstanceId().equals(parentInstanceId)) { instanceContexts.add(instanceContext); } } @@ -203,8 +203,8 @@ public int getActiveInstancesCount() { public int getActiveInstancesCount(String parentInstanceId) { List instanceContexts = new ArrayList(); - for(InstanceContext instanceContext : activeInstances) { - if(instanceContext.getParentInstanceId().equals(parentInstanceId)) { + for (InstanceContext instanceContext : activeInstances) { + if (instanceContext.getParentInstanceId().equals(parentInstanceId)) { instanceContexts.add(instanceContext); } } @@ -321,14 +321,14 @@ public int getNonTerminatedInstancesCount() { public int getNonTerminatedInstancesCount(String parentInstanceId) { List instanceContexts = new ArrayList(); - for(InstanceContext instanceContext : activeInstances) { - if(instanceContext.getParentInstanceId().equals(parentInstanceId)) { + for (InstanceContext instanceContext : activeInstances) { + if (instanceContext.getParentInstanceId().equals(parentInstanceId)) { instanceContexts.add(instanceContext); } } - for(InstanceContext instanceContext : pendingInstances) { - if(instanceContext.getParentInstanceId().equals(parentInstanceId)) { + for (InstanceContext instanceContext : pendingInstances) { + if (instanceContext.getParentInstanceId().equals(parentInstanceId)) { instanceContexts.add(instanceContext); } } diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/publisher/InstanceNotificationPublisher.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/publisher/InstanceNotificationPublisher.java index a33329a9ce..52d3af15d7 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/publisher/InstanceNotificationPublisher.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/publisher/InstanceNotificationPublisher.java @@ -31,14 +31,6 @@ public class InstanceNotificationPublisher { private static final Log log = LogFactory.getLog(InstanceNotificationPublisher.class); - /* An instance of InstanceNotificationPublisher is created when the class is loaded. - * Since the class is loaded only once, it is guaranteed that an object of - * InstanceNotificationPublisher is created only once. Hence it is singleton. - */ - private static class InstanceHolder { - private static final InstanceNotificationPublisher INSTANCE = new InstanceNotificationPublisher(); - } - public static InstanceNotificationPublisher getInstance() { return InstanceHolder.INSTANCE; } @@ -66,4 +58,12 @@ public synchronized void sendInstanceCleanupEventForMember(String memberId) { log.info(String.format("Publishing Instance Cleanup Event: [member] %s", memberId)); publish(new InstanceCleanupMemberEvent(memberId)); } + + /* An instance of InstanceNotificationPublisher is created when the class is loaded. + * Since the class is loaded only once, it is guaranteed that an object of + * InstanceNotificationPublisher is created only once. Hence it is singleton. + */ + private static class InstanceHolder { + private static final InstanceNotificationPublisher INSTANCE = new InstanceNotificationPublisher(); + } } diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/health/AutoscalerHealthStatEventReceiver.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/health/AutoscalerHealthStatEventReceiver.java index 826a325f51..bfd2f63e79 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/health/AutoscalerHealthStatEventReceiver.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/health/AutoscalerHealthStatEventReceiver.java @@ -296,6 +296,40 @@ protected void onEvent(org.apache.stratos.messaging.event.Event event) { } }); + healthStatEventReceiver.addEventListener(new MemberCurveFinderOfMemoryConsumptionEventListener(){ + @Override + protected void onEvent(org.apache.stratos.messaging.event.Event event) { + MemberCurveFinderOfMemoryConsumptionEvent memberCurveFinderOfMemoryConsumptionEvent = (MemberCurveFinderOfMemoryConsumptionEvent) event; + String memberId = memberCurveFinderOfMemoryConsumptionEvent.getMemberId(); + Member member = getMemberByMemberId(memberId); + if (null == member) { + if (log.isDebugEnabled()) { + log.debug(String.format("Member not found in the Topology: [member] %s", memberId)); + } + return; + } + if (!member.isActive()) { + if (log.isDebugEnabled()) { + log.debug(String.format("Member activated event has not received for the member %s. " + + "Therefore ignoring" + " the health stat", memberId)); + } + return; + } + AutoscalerContext asCtx = AutoscalerContext.getInstance(); + ClusterMonitor monitor; + String clusterId = member.getClusterId(); + monitor = asCtx.getClusterMonitor(clusterId); + if (null == monitor) { + if (log.isDebugEnabled()) { + log.debug(String.format("A cluster monitor is not found in autoscaler context " + + "[cluster] %s", clusterId)); + } + return; + } + monitor.handleMemberCurveFinderOfMemoryConsumptionEvent(memberCurveFinderOfMemoryConsumptionEvent); + } + }); + healthStatEventReceiver.addEventListener(new MemberGradientOfLoadAverageEventListener() { @Override protected void onEvent(org.apache.stratos.messaging.event.Event event) { @@ -365,6 +399,41 @@ protected void onEvent(org.apache.stratos.messaging.event.Event event) { } }); + healthStatEventReceiver.addEventListener(new MemberCurveFinderOfLoadAverageEventListener(){ + @Override + protected void onEvent(org.apache.stratos.messaging.event.Event event) { + MemberCurveFinderOfLoadAverageEvent memberCurveFinderOfLoadAverageEvent = (MemberCurveFinderOfLoadAverageEvent) event; + String memberId = memberCurveFinderOfLoadAverageEvent.getMemberId(); + Member member = getMemberByMemberId(memberId); + if (null == member) { + if (log.isDebugEnabled()) { + log.debug(String.format("Member not found in the Topology: [member] %s", memberId)); + } + return; + } + if (!member.isActive()) { + if (log.isDebugEnabled()) { + log.debug(String.format("Member activated event has not received for the member %s. " + + "Therefore ignoring" + " the health stat", memberId)); + } + return; + } + AutoscalerContext asCtx = AutoscalerContext.getInstance(); + ClusterMonitor monitor; + String clusterId = member.getClusterId(); + monitor = asCtx.getClusterMonitor(clusterId); + if (null == monitor) { + if (log.isDebugEnabled()) { + log.debug(String.format("A cluster monitor is not found in autoscaler context " + + "[cluster] %s", clusterId)); + } + return; + } + + monitor.handleMemberCurveFinderOfLoadAverageEvent(memberCurveFinderOfLoadAverageEvent); + } + }); + healthStatEventReceiver.addEventListener(new MemberSecondDerivativeOfLoadAverageEventListener() { @Override protected void onEvent(org.apache.stratos.messaging.event.Event event) { @@ -406,6 +475,27 @@ protected void onEvent(org.apache.stratos.messaging.event.Event event) { } }); + healthStatEventReceiver.addEventListener(new CurveFinderOfLoadAverageEventListener(){ + @Override + protected void onEvent(org.apache.stratos.messaging.event.Event event) { + CurveFinderOfLoadAverageEvent curveFinderOfLoadAverageEvent = (CurveFinderOfLoadAverageEvent)event; + String clusterId = curveFinderOfLoadAverageEvent.getClusterId(); + AutoscalerContext asCtx = AutoscalerContext.getInstance(); + ClusterMonitor monitor; + monitor = asCtx.getClusterMonitor(clusterId); + + if(null == monitor){ + if (log.isDebugEnabled()) { + log.debug(String.format("A cluster monitor is not found in autoscaler context " + + "[cluster] %s", clusterId)); + } + return; + } + + monitor.handleCurveFinderLoadAverageEvent(curveFinderOfLoadAverageEvent); + } + }); + healthStatEventReceiver.addEventListener(new SecondDerivativeOfLoadAverageEventListener() { @Override protected void onEvent(org.apache.stratos.messaging.event.Event event) { @@ -425,6 +515,27 @@ protected void onEvent(org.apache.stratos.messaging.event.Event event) { } }); + healthStatEventReceiver.addEventListener(new CurveFinderOfMemoryConsumptionEventListener(){ + @Override + protected void onEvent(org.apache.stratos.messaging.event.Event event) { + CurveFinderOfMemoryConsumptionEvent curveFinderOfMemoryConsumptionEvent = (CurveFinderOfMemoryConsumptionEvent)event; + String clusterId = curveFinderOfMemoryConsumptionEvent.getClusterId(); + AutoscalerContext asCtx = AutoscalerContext.getInstance(); + ClusterMonitor monitor; + monitor = asCtx.getClusterMonitor(clusterId); + + if(null == monitor){ + if(log.isDebugEnabled()){ + log.debug(String.format("A cluster monitor is not found in autoscaler context " + + "[cluster] %s", clusterId)); + } + return; + } + + monitor.handleCurveFinderOfMemoryConsumptionEvent(curveFinderOfMemoryConsumptionEvent); + } + }); + healthStatEventReceiver.addEventListener(new SecondDerivativeOfMemoryConsumptionEventListener() { @Override protected void onEvent(org.apache.stratos.messaging.event.Event event) { @@ -463,6 +574,26 @@ protected void onEvent(org.apache.stratos.messaging.event.Event event) { monitor.handleSecondDerivativeOfRequestsInFlightEvent(secondDerivativeOfRequestsInFlightEvent); } }); + + healthStatEventReceiver.addEventListener(new CurveFinderOfRequestsInfFlightEventListener(){ + @Override + protected void onEvent(org.apache.stratos.messaging.event.Event event) { + CurveFinderOfRequestsInFlightEvent curveFinderOfRequestsInFlightEvent + = (CurveFinderOfRequestsInFlightEvent) event; + String clusterId = curveFinderOfRequestsInFlightEvent.getClusterId(); + AutoscalerContext asCtx = AutoscalerContext.getInstance(); + ClusterMonitor monitor; + monitor = asCtx.getClusterMonitor(clusterId); + if (null == monitor) { + if (log.isDebugEnabled()) { + log.debug(String.format("A cluster monitor is not found in autoscaler context " + + "[cluster] %s", clusterId)); + } + return; + } + monitor.handleCurveFinderOfRequestsInFlightEvent(curveFinderOfRequestsInFlightEvent); + } + }); } private Member getMemberByMemberId(String memberId) { diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java index 119c9c6fd2..2573991ee7 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java @@ -93,7 +93,7 @@ protected void onEvent(Event event) { getApplications().values()) { ApplicationContext applicationContext = AutoscalerContext.getInstance(). - getApplicationContext(application.getUniqueIdentifier()); + getApplicationContext(application.getUniqueIdentifier()); if (applicationContext != null && applicationContext.getStatus(). equals(ApplicationContext.STATUS_DEPLOYED)) { if (AutoscalerUtil.allClustersInitialized(application)) { @@ -132,47 +132,38 @@ protected void onEvent(Event event) { ApplicationClustersCreatedEvent applicationClustersCreatedEvent = (ApplicationClustersCreatedEvent) event; String appId = applicationClustersCreatedEvent.getAppId(); - boolean appMonitorCreationTriggered = false; - int retries = 30; - while (!appMonitorCreationTriggered && retries > 0) { - try { - //acquire read lock - ApplicationHolder.acquireReadLock(); - //start the application monitor - ApplicationContext applicationContext = AutoscalerContext.getInstance(). - getApplicationContext(appId); - if (applicationContext != null && - applicationContext.getStatus(). - equals(ApplicationContext.STATUS_DEPLOYED)) { - if (!AutoscalerContext.getInstance(). - containsApplicationPendingMonitor(appId)) { - appMonitorCreationTriggered = true; - AutoscalerUtil.getInstance().startApplicationMonitor(appId); - break; - } + try { + //acquire read lock + ApplicationHolder.acquireReadLock(); + //start the application monitor + ApplicationContext applicationContext = AutoscalerContext.getInstance(). + getApplicationContext(appId); + if (applicationContext != null && + applicationContext.getStatus(). + equals(ApplicationContext.STATUS_DEPLOYED)) { + if (!AutoscalerContext.getInstance(). + containsApplicationPendingMonitor(appId)) { + AutoscalerUtil.getInstance().startApplicationMonitor(appId); } - } catch (Exception e) { - String msg = "Error processing event " + e.getLocalizedMessage(); - log.error(msg, e); - } finally { - //release read lock - ApplicationHolder.releaseReadLock(); - } - - try { - retries--; - Thread.sleep(1000); - } catch (InterruptedException e) { + } else { + String status; + if(applicationContext == null) { + status = null; + } else { + status = applicationContext.getStatus(); + } + log.error("Error while creating the application monitor due to " + + "in-consistent persistence of [application] " + + applicationClustersCreatedEvent.getAppId() + ", " + + "the [application-context] " + applicationContext + + " status of [application-context] " + status); } - } - - // Reason is to re-try 5 time is because application status might not become "deployed" yet, refer deployApplication API for more information. - // Reason why not throwing error after 5 times is because this not the only place we trigger app-monitor creation. - if (!appMonitorCreationTriggered) { - String msg = String.format("Application monitor creation is not triggered on application " - + "clusters created event even after 5 retries [application-id] %s. " - + "Possible cause is either application context is null or application status didn't become %s yet.", appId, ApplicationContext.STATUS_DEPLOYED); - log.warn(msg); + } catch (Exception e) { + String msg = "Error processing event " + e.getLocalizedMessage(); + log.error(msg, e); + } finally { + //release read lock + ApplicationHolder.releaseReadLock(); } } catch (ClassCastException e) { String msg = "Error while casting the event " + e.getLocalizedMessage(); diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServiceComponent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServiceComponent.java index 65d75b2500..48ee481065 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServiceComponent.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServiceComponent.java @@ -77,17 +77,17 @@ */ public class AutoscalerServiceComponent { - private static final Log log = LogFactory.getLog(AutoscalerServiceComponent.class); - private static final String AUTOSCALER_COORDINATOR_LOCK = "AUTOSCALER_COORDINATOR_LOCK"; - private AutoscalerTopologyEventReceiver asTopologyReceiver; private AutoscalerHealthStatEventReceiver autoscalerHealthStatEventReceiver; private ExecutorService executorService; private ScheduledExecutorService scheduler; protected void activate(ComponentContext componentContext) throws Exception { + if (log.isDebugEnabled()) { + log.debug("Activating AutoscalerServiceComponent..."); + } try { XMLConfiguration conf = ConfUtil.getInstance(AutoscalerConstants.COMPONENTS_CONFIG).getConfiguration(); int threadPoolSize = conf.getInt(AutoscalerConstants.THREAD_POOL_SIZE_KEY, @@ -136,8 +136,8 @@ public void run() { } else { executeCoordinatorTasks(); } - - componentStartUpSynchronizer.waitForWebServiceActivation("AutoscalerService"); + componentStartUpSynchronizer.waitForAxisServiceActivation(Component.Autoscaler, + "AutoscalerService"); componentStartUpSynchronizer.setComponentStatus(Component.Autoscaler, true); if (log.isInfoEnabled()) { log.info("Autoscaler service component activated"); diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java index a32e02415d..170d99f174 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java @@ -27,11 +27,6 @@ * Abstract class for the monitoring functionality in Autoscaler. */ public abstract class Monitor implements EventHandler, Runnable { - //Monitor types - public enum MonitorType { - Application, Group, Cluster - } - //Id of the monitor, cluster=clusterId, group=group-alias, application=app-alias protected String id; //The parent app which this monitor relates to @@ -42,7 +37,6 @@ public enum MonitorType { protected boolean hasStartupDependents; //monitors map, key=InstanceId and value=ClusterInstance/GroupInstance/ApplicationInstance protected Map instanceIdToInstanceMap; - public Monitor() { this.instanceIdToInstanceMap = new HashMap(); } @@ -74,13 +68,6 @@ public String getId() { return id; } - /** - * Return the type of the monitor. - * - * @return monitor type - */ - public abstract MonitorType getMonitorType(); - /** * Set the id of the monitor * @@ -90,6 +77,13 @@ public void setId(String id) { this.id = id; } + /** + * Return the type of the monitor. + * + * @return monitor type + */ + public abstract MonitorType getMonitorType(); + /** * To get the appId of the monitor * @@ -216,4 +210,9 @@ public List getInstancesByParentInstanceId(String parentInstanceId) { public boolean hasInstance() { return !instanceIdToInstanceMap.isEmpty(); } + + //Monitor types + public enum MonitorType { + Application, Group, Cluster + } } diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java index 0b265e6846..cf7e06e8a9 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java @@ -148,10 +148,10 @@ public static Monitor getGroupMonitor(ParentComponentMonitor parentMonitor, //Find whether any other instances exists in group // which has not been added to in-memory model in the restart ApplicationMonitor applicationMonitor = AutoscalerContext.getInstance().getAppMonitor(appId); - if(applicationMonitor != null && applicationMonitor.isRestarting()) { + if (applicationMonitor != null && applicationMonitor.isRestarting()) { Collection instances = parentMonitor.getInstances(); - for(Instance instance : instances) { - if(!instanceIds.contains(instance.getInstanceId())) { + for (Instance instance : instances) { + if (!instanceIds.contains(instance.getInstanceId())) { instanceIds.add(instance.getInstanceId()); } } @@ -241,8 +241,8 @@ public static ClusterMonitor getClusterMonitor(ParentComponentMonitor parentMoni //Find whether any other instances exists in group // which has not been added to in-memory model in the restart Collection instances = parentMonitor.getInstances(); - for(Instance instance : instances) { - if(!parentInstanceIds.contains(instance.getInstanceId())) { + for (Instance instance : instances) { + if (!parentInstanceIds.contains(instance.getInstanceId())) { parentInstanceIds.add(instance.getInstanceId()); } } diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java index d4a2746773..8474e85aa2 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitor.java @@ -45,12 +45,10 @@ import org.apache.stratos.autoscaler.status.processor.cluster.ClusterStatusInactiveProcessor; import org.apache.stratos.autoscaler.status.processor.cluster.ClusterStatusTerminatedProcessor; import org.apache.stratos.autoscaler.util.AutoscalerConstants; -import org.apache.stratos.autoscaler.util.AutoscalerObjectConverter; import org.apache.stratos.autoscaler.util.ConfUtil; import org.apache.stratos.autoscaler.util.ServiceReferenceHolder; import org.apache.stratos.cloud.controller.stub.domain.MemberContext; import org.apache.stratos.common.Properties; -import org.apache.stratos.common.Property; import org.apache.stratos.common.client.CloudControllerServiceClient; import org.apache.stratos.common.constants.StratosConstants; import org.apache.stratos.common.threading.StratosThreadPool; @@ -84,23 +82,21 @@ */ public class ClusterMonitor extends Monitor { + private static final Log log = LogFactory.getLog(ClusterMonitor.class); private final ScheduledExecutorService scheduler; private final ExecutorService executorService; - protected boolean hasFaultyMember = false; protected ClusterContext clusterContext; + protected String serviceType; + protected String clusterId; // future to cancel it when destroying monitors private ScheduledFuture schedulerFuture; - protected String serviceType; private AtomicBoolean monitoringStarted; - protected String clusterId; private Cluster cluster; private int monitoringIntervalMilliseconds; //has scaling dependents private boolean hasScalingDependents; private boolean groupScalingEnabledSubtree; - - private static final Log log = LogFactory.getLog(ClusterMonitor.class); private String deploymentPolicyId; @@ -121,6 +117,27 @@ public ClusterMonitor(Cluster cluster, boolean hasScalingDependents, boolean gro this.deploymentPolicyId = deploymentPolicyId; } + private static void createClusterInstance(String serviceType, + String clusterId, String alias, String instanceId, + String partitionId, String networkPartitionId) { + + try { + CloudControllerServiceClient.getInstance().createClusterInstance( + serviceType, clusterId, alias, instanceId, partitionId, + networkPartitionId); + } catch (RemoteException e) { + String msg = " Exception occurred in creating cluster instance with cluster-id [" + clusterId + + "] instance-id [" + instanceId + "] service-type [" + serviceType + "]" + + "] alias [" + alias + "] partition-id [" + partitionId + "]" + + "] network-parition-id [" + networkPartitionId + "]" + + " .Reason [" + e.getMessage() + "]"; + log.error(msg); + throw new RuntimeException(msg, e); + } + + + } + @Override public MonitorType getMonitorType() { return MonitorType.Cluster; @@ -246,27 +263,6 @@ public boolean groupScalingEnabledSubtree() { return groupScalingEnabledSubtree; } - private static void createClusterInstance(String serviceType, - String clusterId, String alias, String instanceId, - String partitionId, String networkPartitionId) { - - try { - CloudControllerServiceClient.getInstance().createClusterInstance( - serviceType, clusterId, alias, instanceId, partitionId, - networkPartitionId); - } catch (RemoteException e) { - String msg = " Exception occurred in creating cluster instance with cluster-id [" + clusterId - + "] instance-id [" + instanceId + "] service-type [" + serviceType + "]" - + "] alias [" + alias + "] partition-id [" + partitionId + "]" - + "] network-parition-id [" + networkPartitionId + "]" - + " .Reason [" + e.getMessage() + "]"; - log.error(msg); - throw new RuntimeException(msg, e); - } - - - } - public void handleAverageLoadAverageEvent( AverageLoadAverageEvent averageLoadAverageEvent) { @@ -598,6 +594,31 @@ public void handleGradientOfLoadAverageEvent( } } + public void handleCurveFinderLoadAverageEvent(CurveFinderOfLoadAverageEvent curveFinderOfLoadAverageEvent){ + String networkPartitionId = curveFinderOfLoadAverageEvent.getNetworkPartitionId(); + String clusterId = curveFinderOfLoadAverageEvent.getClusterId(); + String instanceId = curveFinderOfLoadAverageEvent.getClusterInstanceId(); + + double a = curveFinderOfLoadAverageEvent.getA(); + double b = curveFinderOfLoadAverageEvent.getB(); + double c = curveFinderOfLoadAverageEvent.getC(); + + if (log.isDebugEnabled()) { + log.debug(String.format("CurveFinder of load avg event: [cluster] %s [network-partition] %s [a] %s [b] %s [c] %s", + clusterId, networkPartitionId, a, b, c)); + } + ClusterInstanceContext clusterLevelNetworkPartitionContext = getClusterInstanceContext( + networkPartitionId, instanceId); + if (null != clusterLevelNetworkPartitionContext) { + clusterLevelNetworkPartitionContext.setCurveFinderCoefficientsOfLoadAverage(a, b, c); + } else { + if (log.isDebugEnabled()) { + log.debug(String.format("Network partition context is not available for :" + + " [network partition] %s", networkPartitionId)); + } + } + } + public void handleSecondDerivativeOfLoadAverageEvent( SecondDerivativeOfLoadAverageEvent secondDerivativeOfLoadAverageEvent) { @@ -691,6 +712,32 @@ public void handleSecondDerivativeOfMemoryConsumptionEvent( } } + + public void handleCurveFinderOfMemoryConsumptionEvent(CurveFinderOfMemoryConsumptionEvent curveFinderOfMemoryConsumptionEvent){ + String networkPartitionId = curveFinderOfMemoryConsumptionEvent.getNetworkPartitionId(); + String clusterId = curveFinderOfMemoryConsumptionEvent.getClusterId(); + String clusterInstanceId = curveFinderOfMemoryConsumptionEvent.getClusterInstanceId(); + double a = curveFinderOfMemoryConsumptionEvent.getA(); + double b = curveFinderOfMemoryConsumptionEvent.getB(); + double c = curveFinderOfMemoryConsumptionEvent.getC(); + + + if (log.isDebugEnabled()) { + log.debug(String.format("CurveFinder of Memory Consumption event: [cluster] %s " + + "[network-partition] %s [a] %s [b] %s [c] %s", clusterId, networkPartitionId, a, b, c)); + } + ClusterInstanceContext clusterLevelNetworkPartitionContext = getClusterInstanceContext( + networkPartitionId, clusterInstanceId); + if (null != clusterLevelNetworkPartitionContext) { + clusterLevelNetworkPartitionContext.setCurveFinderCoefficientsOfMemoryConsumption(a, b, c); + } else { + if (log.isDebugEnabled()) { + log.debug(String.format("Network partition context is not available for :" + + " [network partition] %s", networkPartitionId)); + } + } + } + public void handleAverageRequestsServingCapabilityEvent( AverageRequestsServingCapabilityEvent averageRequestsServingCapabilityEvent) { @@ -922,10 +969,38 @@ public void handleMemberGradientOfMemoryConsumptionEvent( } return; } + + log.info("Gradient : " + memberStatsContext.getMemberId()); float value = memberGradientOfMemoryConsumptionEvent.getValue(); memberStatsContext.setGradientOfMemoryConsumption(value); } + public void handleMemberCurveFinderOfLoadAverageEvent(MemberCurveFinderOfLoadAverageEvent memberCurveFinderOfLoadAverageEvent){ + String clusterInstanceId = memberCurveFinderOfLoadAverageEvent.getClusterInstanceId(); + String memberId = memberCurveFinderOfLoadAverageEvent.getMemberId(); + Member member = getMemberByMemberId(memberId); + String networkPartitionId = getNetworkPartitionIdByMemberId(memberId); + ClusterInstanceContext networkPartitionCtxt = getClusterInstanceContext(networkPartitionId, + clusterInstanceId); + ClusterLevelPartitionContext partitionCtxt = networkPartitionCtxt.getPartitionCtxt( + member.getPartitionId()); + MemberStatsContext memberStatsContext = partitionCtxt.getMemberStatsContext(memberId); + if (null == memberStatsContext) { + if (log.isDebugEnabled()) { + log.debug(String.format("Member context is not available for : [member] %s", memberId)); + } + return; + } + + double a = memberCurveFinderOfLoadAverageEvent.getA(); + double b = memberCurveFinderOfLoadAverageEvent.getB(); + double c = memberCurveFinderOfLoadAverageEvent.getC(); + + memberStatsContext.getLoadAverage().setA(a); + memberStatsContext.getLoadAverage().setB(b); + memberStatsContext.getLoadAverage().setC(c); + } + public void handleMemberAverageLoadAverageEvent( MemberAverageLoadAverageEvent memberAverageLoadAverageEvent) { @@ -948,6 +1023,60 @@ public void handleMemberAverageLoadAverageEvent( memberStatsContext.setAverageLoadAverage(value); } + public void handleMemberCurveFinderOfMemoryConsumptionEvent(MemberCurveFinderOfMemoryConsumptionEvent memberCurveFinderOfMemoryConsumptionEvent){ + String clusterInstanceId = memberCurveFinderOfMemoryConsumptionEvent.getClusterInstanceId(); + String memberId = memberCurveFinderOfMemoryConsumptionEvent.getMemberId(); + Member member = getMemberByMemberId(memberId); + String networkPartitionId = getNetworkPartitionIdByMemberId(memberId); + ClusterInstanceContext networkPartitionCtxt = getClusterInstanceContext(networkPartitionId, + clusterInstanceId); + ClusterLevelPartitionContext partitionCtxt = networkPartitionCtxt.getPartitionCtxt( + member.getPartitionId()); + MemberStatsContext memberStatsContext = partitionCtxt.getMemberStatsContext(memberId); + + if (null == memberStatsContext) { + if (log.isDebugEnabled()) { + log.debug(String.format("Member context is not available for : [member] %s", memberId)); + } + return; + } + + + double a = memberCurveFinderOfMemoryConsumptionEvent.getA(); + double b = memberCurveFinderOfMemoryConsumptionEvent.getB(); + double c = memberCurveFinderOfMemoryConsumptionEvent.getC(); + + memberStatsContext.getMemoryConsumption().setA(a); + memberStatsContext.getMemoryConsumption().setB(b); + memberStatsContext.getMemoryConsumption().setC(c); + } + + public void handleCurveFinderOfRequestsInFlightEvent(CurveFinderOfRequestsInFlightEvent curveFinderOfRequestsInFlightEvent){ + String networkPartitionId = curveFinderOfRequestsInFlightEvent.getNetworkPartitionId(); + String clusterId = curveFinderOfRequestsInFlightEvent.getClusterId(); + String clusterInstanceId = curveFinderOfRequestsInFlightEvent.getClusterInstanceId(); + double a = curveFinderOfRequestsInFlightEvent.getA(); + double b = curveFinderOfRequestsInFlightEvent.getB(); + double c = curveFinderOfRequestsInFlightEvent.getC(); + + + if (log.isDebugEnabled()) { + log.debug(String.format("CurveFinder of Memory Consumption event: [cluster] %s " + + "[network-partition] %s [a] %s [b] %s [c] %s", clusterId, networkPartitionId, a, b, c)); + } + ClusterInstanceContext clusterLevelNetworkPartitionContext = getClusterInstanceContext( + networkPartitionId, clusterInstanceId); + if (null != clusterLevelNetworkPartitionContext) { + clusterLevelNetworkPartitionContext.setCurveFinderCoefficientsOfMemoryConsumption(a, b, c); + } else { + if (log.isDebugEnabled()) { + log.debug(String.format("Network partition context is not available for :" + + " [network partition] %s", networkPartitionId)); + } + } + + } + public void handleMemberGradientOfLoadAverageEvent( MemberGradientOfLoadAverageEvent memberGradientOfLoadAverageEvent) { diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ApplicationMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ApplicationMonitor.java index c917f2d7a2..70ee9d4fe3 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ApplicationMonitor.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ApplicationMonitor.java @@ -120,7 +120,7 @@ public void run() { getInstanceIdToInstanceContextMap().values()) { ApplicationInstance instance = (ApplicationInstance) instanceIdToInstanceMap. get(instanceContext.getId()); - ParentInstanceContext parentInstanceContext = (ParentInstanceContext)instanceContext; + ParentInstanceContext parentInstanceContext = (ParentInstanceContext) instanceContext; //stopping the monitoring when the group is inactive/Terminating/Terminated if (instance.getStatus().getCode() <= ApplicationStatus.Active.getCode()) { //Gives priority to scaling max out rather than dependency scaling @@ -147,20 +147,21 @@ public void run() { new ConcurrentHashMap()); } } - - Application application = ApplicationHolder.getApplications().getApplication(appId); - if (application != null) { - List defaultNetworkPartitions = getDefaultNetworkPartitions(application); - //Checking for whether minimum application instances are there. - if(defaultNetworkPartitions != null) { - checkForMinimumApplicationInstances(application, defaultNetworkPartitions); - } + //When the application is getting un-deployed, need to avoid + // checking the minimum count sanctification + if (!isTerminating()) { + Application application = ApplicationHolder.getApplications().getApplication(appId); + if (application != null) { + List defaultNetworkPartitions = getDefaultNetworkPartitions(application); + //Checking for whether minimum application instances are there. + if (defaultNetworkPartitions != null) { + checkForMinimumApplicationInstances(application, defaultNetworkPartitions); + } /*//Checking for whether any application instances need to be terminated. checkForApplicationInstanceTermination(application, defaultNetworkPartitions);*/ + } } - - } }; executorService.execute(monitoringRunnable); @@ -328,7 +329,7 @@ private void checkForMinimumApplicationInstances(Application application, } } //Starting the dependencies - if(!instanceIds.isEmpty()) { + if (!instanceIds.isEmpty()) { startDependency(application, instanceIds); } @@ -339,10 +340,10 @@ private void checkForApplicationInstanceTermination(Application application, for (NetworkPartitionContext networkPartitionContext : networkPartitionContextsMap.values()) { String nPartitionId = networkPartitionContext.getId(); - if(!defaultNetworkPartitions.contains(nPartitionId)) { + if (!defaultNetworkPartitions.contains(nPartitionId)) { log.info("The [application] " + appId + " runtime cannot be in [network-partition] " + nPartitionId + " as it is removed from the [application-policy]...!"); - for(InstanceContext instanceContext: networkPartitionContext. + for (InstanceContext instanceContext : networkPartitionContext. getInstanceIdToInstanceContextMap().values()) { //Handling application instance termination ApplicationBuilder.handleApplicationInstanceTerminatingEvent(this.appId, @@ -554,7 +555,7 @@ public boolean createInstanceAndStartDependency(Application application) getInstanceByNetworkPartitionId(context.getId()); if (appInstance != null) { //use the existing instance in the Topology to create the data - if(!isRestarting) { + if (!isRestarting) { this.setRestarting(true); } instanceId = handleApplicationInstanceCreation(application, context, appInstance); @@ -588,7 +589,7 @@ public boolean createInstanceAndStartDependency(Application application) " [appInstanceId] " + instance.getInstanceId()); } } - if(!instanceIds.isEmpty()) { + if (!instanceIds.isEmpty()) { startDependency(application, instanceIds); } diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java index eee0a3ae80..bc3052a6f9 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java @@ -125,7 +125,7 @@ public void run() { for (InstanceContext instanceContext : networkPartitionContext. getInstanceIdToInstanceContextMap().values()) { - ParentInstanceContext parentInstanceContext = (ParentInstanceContext)instanceContext; + ParentInstanceContext parentInstanceContext = (ParentInstanceContext) instanceContext; GroupInstance instance = (GroupInstance) instanceIdToInstanceMap. get(instanceContext.getId()); //stopping the monitoring when the group is inactive/Terminating/Terminated @@ -155,65 +155,73 @@ public void run() { } } - Collection parentInstances = parent.getInstances(); - - for (Instance parentInstance : parentInstances) { - if(parentInstance.getNetworkPartitionId().equals(networkPartitionContext.getId())) { - int nonTerminatedInstancesCount = networkPartitionContext. - getNonTerminatedInstancesCount(parentInstance.getInstanceId()); - int minInstances = networkPartitionContext. - getMinInstanceCount(); - int maxInstances = networkPartitionContext. - getMaxInstanceCount(); - int activeInstances = networkPartitionContext. - getActiveInstancesCount(parentInstance.getInstanceId()); - - if (nonTerminatedInstancesCount < minInstances) { - int instancesToBeCreated = minInstances - nonTerminatedInstancesCount; - for (int i = 0; i < instancesToBeCreated; i++) { - for (InstanceContext parentInstanceContext : parent. - getNetworkPartitionContext(networkPartitionContext.getId()). - getInstanceIdToInstanceContextMap().values()) { - //keep on scale-up/scale-down only if the application is active - ApplicationMonitor appMonitor = AutoscalerContext.getInstance(). - getAppMonitor(appId); - int activeAppInstances = appMonitor. + ApplicationMonitor applicationMonitor = AutoscalerContext.getInstance(). + getAppMonitor(appId); + + //When the application is getting un-deployed, need to avoid + // checking the minimum count sanctification + if (!applicationMonitor.isTerminating()) { + Collection parentInstances = parent.getInstances(); + + for (Instance parentInstance : parentInstances) { + if (parentInstance.getNetworkPartitionId().equals(networkPartitionContext.getId())) { + int nonTerminatedInstancesCount = networkPartitionContext. + getNonTerminatedInstancesCount(parentInstance.getInstanceId()); + int minInstances = networkPartitionContext. + getMinInstanceCount(); + int maxInstances = networkPartitionContext. + getMaxInstanceCount(); + int activeInstances = networkPartitionContext. + getActiveInstancesCount(parentInstance.getInstanceId()); + + if (nonTerminatedInstancesCount < minInstances) { + int instancesToBeCreated = minInstances - nonTerminatedInstancesCount; + for (int i = 0; i < instancesToBeCreated; i++) { + for (InstanceContext parentInstanceContext : parent. getNetworkPartitionContext(networkPartitionContext.getId()). - getActiveInstancesCount(); - if (activeAppInstances > 0) { - //Creating new group instance based on the existing parent instances - log.info("Creating a group instance of [application] " + getInstanceIdToInstanceContextMap().values()) { + //keep on scale-up/scale-down only if the application is active + ApplicationMonitor appMonitor = AutoscalerContext.getInstance(). + getAppMonitor(appId); + int activeAppInstances = appMonitor. + getNetworkPartitionContext(networkPartitionContext.getId()). + getActiveInstancesCount(); + if (activeAppInstances > 0) { + //Creating new group instance based on the existing parent instances + log.info("Creating a group instance of [application] " + appId + " [group] " + id + " as the the minimum required instances are not met"); - createInstanceOnDemand(parentInstanceContext.getId()); + createInstanceOnDemand(parentInstanceContext.getId()); + } } - } + } } - } - //If the active instances are higher than the max instances, - // the group instance has to get terminated - if (activeInstances > maxInstances) { - int instancesToBeTerminated = activeInstances - maxInstances; - List contexts = - networkPartitionContext.getInstanceIdToInstanceContextMap( - parentInstance.getInstanceId()); - List contextList = new ArrayList(contexts); - for (int i = 0; i < instancesToBeTerminated; i++) { - InstanceContext instanceContext = contextList.get(i); - //scale down only when extra instances found - log.info("Terminating a group instance of [application] " + //If the active instances are higher than the max instances, + // the group instance has to get terminated + if (activeInstances > maxInstances) { + int instancesToBeTerminated = activeInstances - maxInstances; + List contexts = + networkPartitionContext.getInstanceIdToInstanceContextMap( + parentInstance.getInstanceId()); + List contextList = new ArrayList(contexts); + for (int i = 0; i < instancesToBeTerminated; i++) { + InstanceContext instanceContext = contextList.get(i); + //scale down only when extra instances found + log.info("Terminating a group instance of [application] " + appId + " [group] " + id + " as it exceeded the " + "maximum no of instances by " + instancesToBeTerminated); - handleScalingDownBeyondMin((ParentInstanceContext)instanceContext, - networkPartitionContext, true); + handleScalingDownBeyondMin((ParentInstanceContext) instanceContext, + networkPartitionContext, true); + } } } } } + } } }; @@ -282,7 +290,7 @@ private void handleScalingDownBeyondMin(ParentInstanceContext instanceContext, } else { if (groupScalingEnabled) { if (nwPartitionContext.getNonTerminatedInstancesCount() > - nwPartitionContext.getMinInstanceCount()) { + nwPartitionContext.getMinInstanceCount()) { //send terminating to the specific group instance in the scale down ApplicationBuilder.handleGroupTerminatingEvent(this.appId, this.id, instanceContext.getId()); @@ -505,7 +513,7 @@ private void onTerminationOfInstance(String childId, String instanceId) { getAppMonitor(appId); //In case if the group instance is not in terminating while application is // terminating, changing the status to terminating - if(applicationMonitor.isTerminating() && instance.getStatus().getCode() < 3) { + if (applicationMonitor.isTerminating() && instance.getStatus().getCode() < 3) { //Sending group instance terminating event ApplicationBuilder.handleGroupTerminatingEvent(appId, id, instanceId); } @@ -672,8 +680,8 @@ private Instance getParentInstanceContext(String parentInstanceId) { * @return the group level network partition context */ private NetworkPartitionContext getGroupLevelNetworkPartitionContext(String groupAlias, - String appId, - Instance parentInstanceContext) { + String appId, + Instance parentInstanceContext) { NetworkPartitionContext parentLevelNetworkPartitionContext; String deploymentPolicyId = AutoscalerUtil.getDeploymentPolicyIdByAlias(appId, groupAlias); DeploymentPolicy deploymentPolicy = PolicyManager.getInstance().getDeploymentPolicy(deploymentPolicyId); @@ -780,7 +788,7 @@ private void addPartitionContext(Instance parentInstanceContext, * Creates the group instance and adds the required context objects * * @param group the group - * @param parentInstance the parent instance context + * @param parentInstance the parent instance context * @param partitionContext partition-context used to create the group instance * @param parentLevelNetworkPartitionContext the group level network partition context */ diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java index 105d3aa5c1..98e97cff8f 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java @@ -70,8 +70,6 @@ public abstract class ParentComponentMonitor extends Monitor { //Scheduler executor service to execute this monitor in a thread private final ScheduledExecutorService scheduler = StratosThreadPool.getScheduledExecutorService( "autoscaler.monitor.scheduler.thread.pool", 100); - // future to cancel it when destroying monitors - private ScheduledFuture schedulerFuture; //The monitors dependency tree with all the start-able/kill-able dependencies protected DependencyTree startupDependencyTree; //The monitors dependency tree with all the scaling dependencies @@ -86,6 +84,8 @@ public abstract class ParentComponentMonitor extends Monitor { protected Map> terminatingInstancesMap; //network partition contexts protected Map networkPartitionContextsMap; + // future to cancel it when destroying monitors + private ScheduledFuture schedulerFuture; //Executor service to maintain the thread pool private ExecutorService executorService; @@ -207,7 +207,7 @@ public void startDependencyOnTermination(String instanceId) { //starting a new instance of the child Monitor monitor = aliasToActiveChildMonitorsMap.get(context.getId()); //Creating the new instance - if(monitor instanceof ParentComponentMonitor) { + if (monitor instanceof ParentComponentMonitor) { ((ParentComponentMonitor) monitor).createInstanceOnTermination(instanceId); } else { monitor.createInstanceOnDemand(instanceId); @@ -244,12 +244,12 @@ private boolean startDependency(List applicationContext Monitor monitor = aliasToActiveChildMonitorsMap.get(context.getId()); // Creating new instance for (String instanceId : parentInstanceIds) { - if(monitor.getInstancesByParentInstanceId(instanceId) == null || + if (monitor.getInstancesByParentInstanceId(instanceId) == null || monitor.getInstancesByParentInstanceId(instanceId).isEmpty()) { monitor.createInstanceOnDemand(instanceId); } else { log.info(String.format("Instance has already exists for [application] " + - "%s [component] %s [instance-id] %s", getAppId(), + "%s [component] %s [instance-id] %s", getAppId(), context.getId(), instanceId)); } } @@ -275,7 +275,7 @@ public void onChildScalingEvent(ScalingEvent scalingEvent) { if (networkPartitionContext != null) { InstanceContext instanceContext = networkPartitionContext. getInstanceContext(instanceId); - ParentInstanceContext parentInstanceContext = (ParentInstanceContext)instanceContext; + ParentInstanceContext parentInstanceContext = (ParentInstanceContext) instanceContext; if (instanceContext != null) { if (parentInstanceContext.containsScalingEvent(id)) { parentInstanceContext.removeScalingEvent(id); @@ -302,7 +302,7 @@ public void onChildScalingDownBeyondMinEvent(ScalingDownBeyondMinEvent scalingDo String instanceId = scalingDownBeyondMinEvent.getInstanceId(); InstanceContext instanceContext = getNetworkPartitionContext(networkPartitionId). getInstanceContext(instanceId); - ((ParentInstanceContext)instanceContext).addScalingDownBeyondMinEvent(scalingDownBeyondMinEvent); + ((ParentInstanceContext) instanceContext).addScalingDownBeyondMinEvent(scalingDownBeyondMinEvent); } @Override @@ -323,7 +323,7 @@ public void onChildScalingOverMaxEvent(ScalingUpBeyondMaxEvent scalingUpBeyondMa InstanceContext instanceContext = networkPartitionContext. getInstanceContext(instanceId); if (instanceContext != null) { - ParentInstanceContext parentInstanceContext = (ParentInstanceContext)instanceContext; + ParentInstanceContext parentInstanceContext = (ParentInstanceContext) instanceContext; if (parentInstanceContext.containsScalingEvent(id)) { parentInstanceContext.removeScalingOverMaxEvent(id); parentInstanceContext.addScalingOverMaxEvent(scalingUpBeyondMaxEvent); @@ -362,18 +362,18 @@ protected void onChildActivatedEvent(String childId, String instanceId) { // no need to invoke start dependencies. Monitor childMonitor = aliasToActiveChildMonitorsMap.get(childId); - if(childMonitor != null) { + if (childMonitor != null) { Instance instance = childMonitor.getInstance(instanceId); boolean firstIteration = false; - if(instance != null) { - if(instance instanceof GroupInstance) { - GroupInstance groupInstance = (GroupInstance)instance; + if (instance != null) { + if (instance instanceof GroupInstance) { + GroupInstance groupInstance = (GroupInstance) instance; firstIteration = groupInstance.getPreviousState() == GroupStatus.Created; - } else if(instance instanceof ClusterInstance) { - ClusterInstance clusterInstance = (ClusterInstance)instance; + } else if (instance instanceof ClusterInstance) { + ClusterInstance clusterInstance = (ClusterInstance) instance; firstIteration = clusterInstance.getPreviousState() == ClusterStatus.Created; } - if(firstIteration || childMonitor.hasStartupDependents()) { + if (firstIteration || childMonitor.hasStartupDependents()) { startDep = startDependency(childId, instanceId); } } else { @@ -666,9 +666,9 @@ public boolean verifyGroupStatus(String childId, String instanceId, GroupStatus } } - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug(String.format("Calculating the group instances status for [application] " + - "%s [group] %s [group-instance] %s [required-status] %s [no-of-instances] %s", + "%s [group] %s [group-instance] %s [required-status] %s [no-of-instances] %s", appId, childId, instanceId, requiredStatus.toString(), noOfInstancesOfRequiredStatus)); } @@ -681,14 +681,14 @@ public boolean verifyGroupStatus(String childId, String instanceId, GroupStatus //if terminated all the instances in this instances map should be in terminated state if (noOfInstancesOfRequiredStatus == this.inactiveInstancesMap.size() && requiredStatus == GroupStatus.Terminated) { - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug(String.format("Group instances in required status for [application] " + "%s [group] %s [group-instance] %s [required-status] %s", appId, childId, instanceId, GroupStatus.Terminated.toString())); } return true; } else if (noOfInstancesOfRequiredStatus >= minInstances) { - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug(String.format("Group instances in required status for [application] " + "%s [group] %s [group-instance] %s [required-status] %s", appId, childId, instanceId, requiredStatus.toString())); @@ -697,7 +697,7 @@ public boolean verifyGroupStatus(String childId, String instanceId, GroupStatus } else { //of only one is inActive implies that the whole group is Inactive if (requiredStatus == GroupStatus.Inactive && noOfInstancesOfRequiredStatus >= 1) { - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug(String.format("Group instances in required status for [application] " + "%s [group] %s [group-instance] %s [required-status] %s", appId, childId, instanceId, GroupStatus.Inactive.toString())); diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/PolicyManager.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/PolicyManager.java index e7fc57c624..3336776e7b 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/PolicyManager.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/PolicyManager.java @@ -55,8 +55,12 @@ public class PolicyManager { private static Map applicationPolicyListMap; - public Collection getDeploymentPolicies() { - return deploymentPolicyListMap.values(); + private PolicyManager() { + // Initialize distributed object provider + DistributedObjectProvider distributedObjectProvider = ServiceReferenceHolder.getInstance().getDistributedObjectProvider(); + autoscalePolicyListMap = distributedObjectProvider.getMap(AS_POLICY_ID_TO_AUTOSCALE_POLICY_MAP); + deploymentPolicyListMap = distributedObjectProvider.getMap(DEPLOYMENT_POLICY_ID_TO_DEPLOYMENT_POLICY_MAP); + applicationPolicyListMap = distributedObjectProvider.getMap(APPLICATION_ID_TO_APPLICATION_POLICY_MAP); } /* An instance of a PolicyManager is created when the class is loaded. @@ -64,20 +68,12 @@ public Collection getDeploymentPolicies() { * PolicyManager is created only once. Hence it is singleton. */ - private static class InstanceHolder { - private static final PolicyManager INSTANCE = new PolicyManager(); - } - public static PolicyManager getInstance() { return InstanceHolder.INSTANCE; } - private PolicyManager() { - // Initialize distributed object provider - DistributedObjectProvider distributedObjectProvider = ServiceReferenceHolder.getInstance().getDistributedObjectProvider(); - autoscalePolicyListMap = distributedObjectProvider.getMap(AS_POLICY_ID_TO_AUTOSCALE_POLICY_MAP); - deploymentPolicyListMap = distributedObjectProvider.getMap(DEPLOYMENT_POLICY_ID_TO_DEPLOYMENT_POLICY_MAP); - applicationPolicyListMap = distributedObjectProvider.getMap(APPLICATION_ID_TO_APPLICATION_POLICY_MAP); + public Collection getDeploymentPolicies() { + return deploymentPolicyListMap.values(); } // Add the policy to information model and persist. @@ -120,7 +116,6 @@ public boolean removeAutoscalePolicy(String policyID) { return true; } - /** * Add deployment policy to in memory map and persist. * @@ -276,7 +271,6 @@ public AutoscalePolicy getAutoscalePolicy(String id) { return autoscalePolicyListMap.get(id); } - private void addDeploymentPolicyToPolicyListMap(DeploymentPolicy policy) { if (StringUtils.isEmpty(policy.getDeploymentPolicyID())) { throw new RuntimeException("Application id is not found in the deployment policy"); @@ -347,7 +341,6 @@ public DeploymentPolicy getDeploymentPolicy(String id) { return deploymentPolicyListMap.get(id); } - public void addApplicationPolicy(ApplicationPolicy applicationPolicy) throws InvalidApplicationPolicyException { String applicationPolicyId = applicationPolicy.getId(); if (log.isInfoEnabled()) { @@ -426,4 +419,8 @@ public boolean updateApplicationPolicy(ApplicationPolicy applicationPolicy) { public ApplicationPolicy[] getApplicationPolicies() { return applicationPolicyListMap.values().toArray(new ApplicationPolicy[0]); } + + private static class InstanceHolder { + private static final PolicyManager INSTANCE = new PolicyManager(); + } } diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/autoscale/LoadAverage.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/autoscale/LoadAverage.java index 19d1fce23c..08eea48440 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/autoscale/LoadAverage.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/autoscale/LoadAverage.java @@ -30,6 +30,12 @@ public class LoadAverage implements Serializable { private float average = 0.0f; private float secondDerivative = 0.0f; private float gradient = 0.0f; + /** + * curve finder coefficients + */ + private double a; + private double b; + private double c; /** * Gets the value of the average property. @@ -73,6 +79,30 @@ public void setGradient(float value) { this.gradient = value; } + public double getA() { + return a; + } + + public double getB() { + return b; + } + + public double getC() { + return c; + } + + public void setA(double a) { + this.a = a; + } + + public void setB(double b) { + this.b = b; + } + + public void setC(double c) { + this.c = c; + } + @Override public String toString() { return String.format("[average] %f [second-derivative] %f [gradient] %f", diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/autoscale/MemoryConsumption.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/autoscale/MemoryConsumption.java index 9578126a6a..be5b164ece 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/autoscale/MemoryConsumption.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/autoscale/MemoryConsumption.java @@ -30,6 +30,12 @@ public class MemoryConsumption implements Serializable { private float average = 0.0f; private float secondDerivative = 0.0f; private float gradient = 0.0f; + /** + * curve finder co-efficients + */ + private double a; + private double b; + private double c; /** * Gets the value of the average property. @@ -73,6 +79,30 @@ public void setGradient(float value) { this.gradient = value; } + public double getA() { + return a; + } + + public double getB() { + return b; + } + + public double getC() { + return c; + } + + public void setA(double a) { + this.a = a; + } + + public void setB(double b) { + this.b = b; + } + + public void setC(double c) { + this.c = c; + } + @Override public String toString() { return String.format("[average] %f [second-derivative] %f [gradient] %f", diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/autoscale/RequestsInFlight.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/autoscale/RequestsInFlight.java index 1d67e96c23..a31f46abca 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/autoscale/RequestsInFlight.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/autoscale/RequestsInFlight.java @@ -32,6 +32,12 @@ public class RequestsInFlight implements Serializable { private float gradient; private float scaleDownMarginOfGradient; private float scaleDownMarginOfSecondDerivative; + /** + * curve finder coefficients + */ + private double a; + private double b; + private double c; /** * Gets the value of the average property. @@ -103,4 +109,27 @@ public void setScaleDownMarginOfSecondDerivative(float scaleDownMarginOfSecondDe this.scaleDownMarginOfSecondDerivative = scaleDownMarginOfSecondDerivative; } + public double getA() { + return a; + } + + public double getB() { + return b; + } + + public double getC() { + return c; + } + + public void setA(double a) { + this.a = a; + } + + public void setB(double b) { + this.b = b; + } + + public void setC(double c) { + this.c = c; + } } \ No newline at end of file diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/AutoscalerRuleEvaluator.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/AutoscalerRuleEvaluator.java index 3688c6bfdb..b871e97925 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/AutoscalerRuleEvaluator.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/AutoscalerRuleEvaluator.java @@ -41,9 +41,8 @@ public class AutoscalerRuleEvaluator { private static final Log log = LogFactory.getLog(AutoscalerRuleEvaluator.class); - - private Map knowledgeBases; private static volatile AutoscalerRuleEvaluator instance; + private Map knowledgeBases; private AutoscalerRuleEvaluator() { knowledgeBases = new HashMap(); @@ -67,6 +66,24 @@ public static AutoscalerRuleEvaluator getInstance() { return instance; } + private static KnowledgeBase readKnowledgeBase(String drlFileName) { + KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); + String configDir = CarbonUtils.getCarbonConfigDirPath(); + String droolsDir = configDir + File.separator + StratosConstants.DROOLS_DIR_NAME; + Resource resource = ResourceFactory.newFileResource(droolsDir + File.separator + drlFileName); + kbuilder.add(resource, ResourceType.DRL); + KnowledgeBuilderErrors errors = kbuilder.getErrors(); + if (errors.size() > 0) { + for (KnowledgeBuilderError error : errors) { + log.error(error.getMessage()); + } + throw new IllegalArgumentException("Could not parse knowledge"); + } + KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); + kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); + return kbase; + } + public void parseAndBuildKnowledgeBaseForDroolsFile(String drlFileName) { KnowledgeBase knowledgeBase = readKnowledgeBase(drlFileName); if (knowledgeBase == null) { @@ -87,22 +104,4 @@ public StatefulKnowledgeSession getStatefulSession(String drlFileName) { ksession.setGlobal("log", RuleLog.getInstance()); return ksession; } - - private static KnowledgeBase readKnowledgeBase(String drlFileName) { - KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); - String configDir = CarbonUtils.getCarbonConfigDirPath(); - String droolsDir = configDir + File.separator + StratosConstants.DROOLS_DIR_NAME; - Resource resource = ResourceFactory.newFileResource(droolsDir + File.separator + drlFileName); - kbuilder.add(resource, ResourceType.DRL); - KnowledgeBuilderErrors errors = kbuilder.getErrors(); - if (errors.size() > 0) { - for (KnowledgeBuilderError error : errors) { - log.error(error.getMessage()); - } - throw new IllegalArgumentException("Could not parse knowledge"); - } - KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); - kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); - return kbase; - } } diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java index 89633f7ae0..d0a923f748 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java @@ -43,19 +43,42 @@ */ public class RuleTasksDelegator { - private static boolean arspiIsSet = false; - private static final Log log = LogFactory.getLog(RuleTasksDelegator.class); + private static boolean arspiIsSet = false; - public double getPredictedValueForNextMinute(float average, float gradient, float secondDerivative, int timeInterval) { + public double getPredictedValueForNextMinute(float average, float gradient, float secondDerivative, double timeInterval) { double predictedValue; -// s = u * t + 0.5 * a * t * t + // s = u * t + 0.5 * a * t * t if (log.isDebugEnabled()) { log.debug(String.format("Predicting the value, [average]: %s , [gradient]: %s , [second derivative] " + ": %s , [time intervals]: %s ", average, gradient, secondDerivative, timeInterval)); } predictedValue = average + gradient * timeInterval + 0.5 * secondDerivative * timeInterval * timeInterval; + + return predictedValue; + } + + /** + * @param a coefficient of t^2 term + * @param b coefficient of t term + * @param c constant term + * @param timeInterval + * @return predicted value + */ + public double getCurvePredictedValueForNextMinute(double a, double b, double c, long timeInterval) { + double predictedValue; + + log.info(String.format("Predicting the value, [a]: %s , [b]: %s , [c]: " + + ": %s , [time intervals]: %s ", a, b, c, timeInterval)); + // f(t) = a * t * t + b * t + c + if (log.isDebugEnabled()) { + log.debug(String.format("Predicting the value, [a]: %s , [b]: %s , [c]: " + + ": %s , [time intervals]: %s ", a, b, c, timeInterval)); + } + + predictedValue = a * timeInterval * timeInterval + b * timeInterval + c; + return predictedValue; } @@ -353,18 +376,56 @@ public double getLoadAveragePredictedValue(ClusterInstanceContext clusterInstanc } } + public double getCurveLoadAveragePredictedValue(ClusterInstanceContext clusterInstanceContext) { + double loadAveragePredicted = 0.0d; + int totalMemberCount = 0; + for (ClusterLevelPartitionContext partitionContext : clusterInstanceContext.getPartitionCtxts()) { + for (MemberStatsContext memberStatsContext : partitionContext.getMemberStatsContexts().values()) { + + double a = memberStatsContext.getLoadAverage().getA(); + double b = memberStatsContext.getLoadAverage().getB(); + double c = memberStatsContext.getLoadAverage().getC(); + + double memberPredictedLoadAverage = getCurvePredictedValueForNextMinute(a, b, c, 1); + + if (log.isDebugEnabled()) { + log.debug(String.format("[cluster-instance-id] %s [member-id] %s " + + "[predicted load average] %s " + , clusterInstanceContext.getId(), memberStatsContext.getMemberId() + , memberPredictedLoadAverage)); + } + loadAveragePredicted += memberPredictedLoadAverage; + ++totalMemberCount; + } + } + + if (totalMemberCount > 0) { + log.debug("Curve Predicted load average : " + loadAveragePredicted / totalMemberCount); + return loadAveragePredicted / totalMemberCount; + } else { + return 0; + } + } + + public double getLoadAveragePredictedValue() { + double loadAveragePredicted = 0.0; + int totalMemberCount; + return 0; + } + public double getMemoryConsumptionPredictedValue(ClusterInstanceContext clusterInstanceContext) { double memoryConsumptionPredicted = 0.0d; int totalMemberCount = 0; for (ClusterLevelPartitionContext partitionContext : clusterInstanceContext.getPartitionCtxts()) { for (MemberStatsContext memberStatsContext : partitionContext.getMemberStatsContexts().values()) { + log.info("Member ID : " + memberStatsContext.getMemberId()); + float memberMemoryConsumptionAverage = memberStatsContext.getMemoryConsumption().getAverage(); - float memberMemoryConsumptionGredient = memberStatsContext.getMemoryConsumption().getGradient(); + float memberMemoryConsumptionGradient = memberStatsContext.getMemoryConsumption().getGradient(); float memberMemoryConsumptionSecondDerivative = memberStatsContext.getMemoryConsumption().getSecondDerivative(); - double memberPredictedMemoryConsumption = getPredictedValueForNextMinute(memberMemoryConsumptionAverage, - memberMemoryConsumptionGredient, memberMemoryConsumptionSecondDerivative, 1); + double memberPredictedMemoryConsumption = getPredictedValueForNextMinute(memberMemoryConsumptionAverage, memberMemoryConsumptionGradient, memberMemoryConsumptionSecondDerivative, 1); if (log.isDebugEnabled()) { log.debug(String.format("[member-id] %s [predicted memory consumption] %s ", @@ -383,4 +444,39 @@ public double getMemoryConsumptionPredictedValue(ClusterInstanceContext clusterI return 0; } } + + public double getCurveMemoryConsumptionPredictedValue(ClusterInstanceContext clusterInstanceContext) { + double memoryConsumptionPredicted = 0.0d; + int totalMemberCount = 0; + for (ClusterLevelPartitionContext partitionContext : clusterInstanceContext.getPartitionCtxts()) { + for (MemberStatsContext memberStatsContext : partitionContext.getMemberStatsContexts().values()) { + + + double a = memberStatsContext.getMemoryConsumption().getA(); + double b = memberStatsContext.getMemoryConsumption().getB(); + double c = memberStatsContext.getMemoryConsumption().getC(); + + double memberPredictedMemoryConsumption = getCurvePredictedValueForNextMinute(a, + b, c, 1); + + if (memberPredictedMemoryConsumption == 0.0) + memberPredictedMemoryConsumption = memberStatsContext.getMemoryConsumption().getAverage(); + + if (log.isDebugEnabled()) { + log.debug(String.format("[member-id] %s [predicted memory consumption] %s ", + memberStatsContext.getMemberId() + , memberPredictedMemoryConsumption)); + } + memoryConsumptionPredicted += memberPredictedMemoryConsumption; + ++totalMemberCount; + } + } + + if (totalMemberCount > 0) { + log.debug("Curve Predicted memory consumption : " + memoryConsumptionPredicted / totalMemberCount); + return memoryConsumptionPredicted / totalMemberCount; + } else { + return 0; + } + } } diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java index 52c8dbea14..f0e797f881 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java @@ -245,10 +245,6 @@ public boolean deployApplication(String applicationId, String applicationPolicyI // validating application policy against the application AutoscalerUtil.validateApplicationPolicyAgainstApplication(applicationId, applicationPolicyId); - // Create application clusters in cloud controller and send application created event - ApplicationBuilder.handleApplicationDeployment(application, - applicationContext.getComponents().getApplicationClusterContexts()); - // Setting application policy id in application object try { ApplicationHolder.acquireWriteLock(); @@ -272,7 +268,13 @@ public boolean deployApplication(String applicationId, String applicationPolicyI applicationContext.setStatus(ApplicationContext.STATUS_DEPLOYED); AutoscalerContext.getInstance().updateApplicationContext(applicationContext); - log.info("Waiting for application clusters to be created: [application-id] " + applicationId); + // Create application clusters in cloud controller and send application created event + ApplicationBuilder.handleApplicationDeployment(application, + applicationContext.getComponents().getApplicationClusterContexts()); + + log.info("Waiting for application clusters to be created: [application-id] " + + applicationId); + return true; } catch (Exception e) { ApplicationContext applicationContext = RegistryManager.getInstance(). @@ -491,7 +493,7 @@ public boolean undeployApplication(String applicationId, boolean force) { return false; } else { log.info(String.format("Previous graceful un-deployment is in progress for " + - "[application-id] %s , thus terminating instances directly", + "[application-id] %s , thus terminating instances directly", applicationId)); appMonitor.setForce(true); terminateAllMembersAndClustersForcefully(applicationId); @@ -926,15 +928,15 @@ private void terminateAllMembersAndClustersForcefully(String applicationId) { //Stopping the cluster monitor thread ClusterMonitor clusterMonitor = AutoscalerContext.getInstance(). getClusterMonitor(clusterId); - if(clusterMonitor != null) { + if (clusterMonitor != null) { clusterMonitor.destroy(); } else { - if(log.isDebugEnabled()) { + if (log.isDebugEnabled()) { log.debug(String.format("Cluster monitor cannot be found for [application] %s " + "[cluster] %s", applicationId, clusterId)); } } - if(cluster != null) { + if (cluster != null) { Collection allClusterInstances = cluster.getClusterInstances(); for (ClusterInstance clusterInstance : allClusterInstances) { ClusterStatusEventPublisher.sendClusterTerminatedEvent(applicationId, cluster.getServiceName(), @@ -1132,7 +1134,7 @@ private void updateClusterMonitors(DeploymentPolicy deploymentPolicy) throws Inv for (NetworkPartitionRef networkPartition : deploymentPolicy.getNetworkPartitionRefs()) { NetworkPartitionContext clusterLevelNetworkPartitionContext = clusterMonitor.getClusterContext().getNetworkPartitionCtxt(networkPartition.getId()); - if(clusterLevelNetworkPartitionContext != null) { + if (clusterLevelNetworkPartitionContext != null) { try { addNewPartitionsToClusterMonitor(clusterLevelNetworkPartitionContext, networkPartition, deploymentPolicy.getDeploymentPolicyID(), clusterMonitor.getClusterContext().getServiceId()); diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java index b76322c18f..18a6956d71 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java @@ -80,24 +80,17 @@ public static AutoscalerUtil getInstance() { return Holder.INSTANCE; } - private static class Holder { - private static final AutoscalerUtil INSTANCE = new AutoscalerUtil(); - } - - public static Applications getApplications() { - - Applications applications; + public static Applications loadApplicationsFromRegistry(Applications applications) { + if (applications == null){ + throw new RuntimeException("Applications instance is null"); + } String[] appResourcePaths = RegistryManager.getInstance().getApplicationResourcePaths(); if (appResourcePaths != null) { - applications = new Applications(); for (String appResourcePath : appResourcePaths) { applications.addApplication(getApplicationFromPath(appResourcePath)); } - - return applications; } - - return null; + return applications; } public static Application getApplication(String appId) { @@ -266,80 +259,6 @@ public static org.apache.stratos.common.Properties toCommonProperties( return toCommonProperties(properties); } - public synchronized void startApplicationMonitor(String applicationId) { - - AutoscalerContext autoscalerContext = AutoscalerContext.getInstance(); - if (autoscalerContext.getAppMonitor(applicationId) == null) { - autoscalerContext.addApplicationPendingMonitor(applicationId); - ServiceReferenceHolder.getInstance().getExecutorService().submit(new ApplicationMonitorAdder(applicationId)); - - log.info(String.format("Monitor scheduled: [application] %s ", applicationId)); - } else { - if (log.isDebugEnabled()) { - log.debug(String.format("Application monitor thread already exists: " + - "[application] %s ", applicationId)); - } - } - } - - private class ApplicationMonitorAdder implements Runnable { - private String applicationId; - - public ApplicationMonitorAdder(String applicationId) { - this.applicationId = applicationId; - } - - public void run() { - long startTime = System.currentTimeMillis(); - long endTime = startTime; - int retries = 5; - boolean success = false; - ApplicationMonitor applicationMonitor = null; - while (!success && retries != 0) { - - try { - startTime = System.currentTimeMillis(); - log.info("Starting monitor: [application] " + applicationId); - try { - applicationMonitor = MonitorFactory.getApplicationMonitor(applicationId); - } catch (PolicyValidationException e) { - String msg = "Monitor creation failed: [application] " + applicationId; - log.warn(msg, e); - retries--; - } - success = true; - endTime = System.currentTimeMillis(); - } catch (DependencyBuilderException e) { - String msg = "Monitor creation failed: [application] " + applicationId; - log.warn(msg, e); - retries--; - } catch (TopologyInConsistentException e) { - String msg = "Monitor creation failed: [application] " + applicationId; - log.warn(msg, e); - retries--; - } - } - - if (applicationMonitor == null) { - String msg = "Monitor creation failed, even after retrying for 5 times: " - + "[application] " + applicationId; - log.error(msg); - throw new RuntimeException(msg); - } - AutoscalerContext autoscalerContext = AutoscalerContext.getInstance(); - autoscalerContext.removeApplicationPendingMonitor(applicationId); - autoscalerContext.removeAppMonitor(applicationId); - autoscalerContext.addAppMonitor(applicationMonitor); - - long startupTime = ((endTime - startTime) / 1000); - if (log.isInfoEnabled()) { - log.info(String.format("Monitor started successfully: [application] %s [dependents] %s " + - "[startup-time] %d seconds", applicationMonitor.getId(), - applicationMonitor.getStartupDependencyTree(), startupTime)); - } - } - } - public static Monitor.MonitorType findMonitorType(ApplicationChildContext context) { if (context instanceof GroupChildContext) { return Monitor.MonitorType.Group; @@ -711,7 +630,6 @@ public static void validateApplicationPolicy(ApplicationPolicy applicationPolicy } } - /** * Validates an application policy against the application * @@ -787,6 +705,150 @@ private static boolean isAppUsingNetworkPartitionId(String applicationId, String return false; } + public static void validateStartupOrders(String groupName, String[] startupOrders) throws InvalidServiceGroupException { + + if (startupOrders == null || startupOrders.length == 0) { + if (log.isDebugEnabled()) { + log.debug("No Startup Order defined for group " + groupName); + } + return; + } + + for (String startupOrder : startupOrders) { + // split comma separated startup orders + String[] splittedStartupOrders = startupOrder.split(","); + for (String splittedStartupOrder : splittedStartupOrders) { + if (!splittedStartupOrder.trim().startsWith("cartridge.") && !splittedStartupOrder.trim().startsWith("group.")) { + // invalid startup order; should prefixed by either 'cartridge.' or 'group.' + throw new InvalidServiceGroupException("Invalid cartridge group: startup order [" + startupOrder + + "] for group " + groupName + + ", should prefixed by either 'cartridge.' or 'group.'"); + } + } + } + } + + public static void validateScalingDependencies(String groupName, String[] scalingDependents) throws InvalidServiceGroupException { + + if (scalingDependents == null || scalingDependents.length == 0) { + if (log.isDebugEnabled()) { + log.debug("No Scaling Dependents defined for group " + groupName); + } + return; + } + + for (String scalingDependent : scalingDependents) { + // split comma separated scaling dependents + String[] splittedDependents = scalingDependent.split(","); + for (String splittedDependent : splittedDependents) { + if (!splittedDependent.trim().startsWith("cartridge.") && !splittedDependent.trim().startsWith("group.")) { + // invalid startup order; should prefixed by either 'cartridge.' or 'group.' + throw new InvalidServiceGroupException("Invalid cartridge group: Scaling Dependency [" + + scalingDependent + "] for group " + groupName + + ", should prefixed by either 'cartridge.' or 'group.'"); + } + } + } + } + + /** + * Validate the Auto Scalar policy removal + * + * @param autoscalePolicyId Auto Scalar policy id boolean + * @return + */ + public static boolean removableAutoScalerPolicy(String autoscalePolicyId) { + Collection applicationContexts = AutoscalerContext.getInstance(). + getApplicationContexts(); + for (ApplicationContext applicationContext : applicationContexts) { + if (applicationContext.getComponents().getCartridgeContexts() != null) { + for (CartridgeContext cartridgeContext : applicationContext.getComponents(). + getCartridgeContexts()) { + if (autoscalePolicyId.equals(cartridgeContext.getSubscribableInfoContext(). + getAutoscalingPolicy())) { + return false; + } + } + } + + if (applicationContext.getComponents().getGroupContexts() != null) { + return findAutoscalingPolicyInGroup(applicationContext.getComponents().getGroupContexts(), + autoscalePolicyId); + } + } + return true; + } + + public static boolean findAutoscalingPolicyInGroup(GroupContext[] groupContexts, + String autoscalePolicyId) { + for (GroupContext groupContext : groupContexts) { + if (groupContext.getCartridgeContexts() != null) { + for (CartridgeContext cartridgeContext : groupContext.getCartridgeContexts()) { + if (autoscalePolicyId.equals(cartridgeContext.getSubscribableInfoContext(). + getAutoscalingPolicy())) { + return false; + } + } + + } + if (groupContext.getGroupContexts() != null) { + return findAutoscalingPolicyInGroup(groupContext.getGroupContexts(), + autoscalePolicyId); + } + } + return true; + } + + /** + * Validate the deployment policy removal + * + * @param deploymentPolicyId + * @return + */ + public static boolean removableDeploymentPolicy(String deploymentPolicyId) { + boolean canRemove = true; + Map applications = ApplicationHolder.getApplications().getApplications(); + for (Application application : applications.values()) { + List deploymentPolicyIdsReferredInApplication = AutoscalerUtil. + getDeploymentPolicyIdsReferredInApplication(application.getUniqueIdentifier()); + for (String deploymentPolicyIdInApp : deploymentPolicyIdsReferredInApplication) { + if (deploymentPolicyId.equals(deploymentPolicyIdInApp)) { + canRemove = false; + } + } + } + return canRemove; + } + + public static void readApplicationContextsFromRegistry() { + String[] resourcePaths = RegistryManager.getInstance().getApplicationContextResourcePaths(); + if ((resourcePaths == null) || (resourcePaths.length == 0)) { + return; + } + + for (String resourcePath : resourcePaths) { + ApplicationContext applicationContext = RegistryManager.getInstance(). + getApplicationContextByResourcePath(resourcePath); + AutoscalerContext.getInstance().addApplicationContext(applicationContext); + } + } + + public synchronized void startApplicationMonitor(String applicationId) { + + AutoscalerContext autoscalerContext = AutoscalerContext.getInstance(); + if (autoscalerContext.getAppMonitor(applicationId) == null) { + autoscalerContext.addApplicationPendingMonitor(applicationId); + ServiceReferenceHolder.getInstance().getExecutorService().submit(new ApplicationMonitorAdder(applicationId)); + + log.info(String.format("Monitor scheduled: [application] %s ", applicationId)); + } else { + if (log.isDebugEnabled()) { + log.debug(String.format("Application monitor thread already exists: " + + "[application] %s ", applicationId)); + } + } + } + public void updateApplicationsTopology(Application application) throws ApplicationDefinitionException { Application existingApplication = ApplicationHolder.getApplications(). @@ -889,133 +951,66 @@ public void updateClusterMonitor(Application application) throws ApplicationDefi } } - public static void validateStartupOrders(String groupName, String[] startupOrders) throws InvalidServiceGroupException { - - if (startupOrders == null || startupOrders.length == 0) { - if (log.isDebugEnabled()) { - log.debug("No Startup Order defined for group " + groupName); - } - return; - } - - for (String startupOrder : startupOrders) { - // split comma separated startup orders - String[] splittedStartupOrders = startupOrder.split(","); - for (String splittedStartupOrder : splittedStartupOrders) { - if (!splittedStartupOrder.trim().startsWith("cartridge.") && !splittedStartupOrder.trim().startsWith("group.")) { - // invalid startup order; should prefixed by either 'cartridge.' or 'group.' - throw new InvalidServiceGroupException("Invalid cartridge group: startup order [" + startupOrder + - "] for group " + groupName + - ", should prefixed by either 'cartridge.' or 'group.'"); - } - } - } + private static class Holder { + private static final AutoscalerUtil INSTANCE = new AutoscalerUtil(); } - public static void validateScalingDependencies(String groupName, String[] scalingDependents) throws InvalidServiceGroupException { + private class ApplicationMonitorAdder implements Runnable { + private String applicationId; - if (scalingDependents == null || scalingDependents.length == 0) { - if (log.isDebugEnabled()) { - log.debug("No Scaling Dependents defined for group " + groupName); - } - return; + public ApplicationMonitorAdder(String applicationId) { + this.applicationId = applicationId; } - for (String scalingDependent : scalingDependents) { - // split comma separated scaling dependents - String[] splittedDependents = scalingDependent.split(","); - for (String splittedDependent : splittedDependents) { - if (!splittedDependent.trim().startsWith("cartridge.") && !splittedDependent.trim().startsWith("group.")) { - // invalid startup order; should prefixed by either 'cartridge.' or 'group.' - throw new InvalidServiceGroupException("Invalid cartridge group: Scaling Dependency [" + - scalingDependent + "] for group " + groupName + - ", should prefixed by either 'cartridge.' or 'group.'"); - } - } - } - } + public void run() { + long startTime = System.currentTimeMillis(); + long endTime = startTime; + int retries = 5; + boolean success = false; + ApplicationMonitor applicationMonitor = null; + while (!success && retries != 0) { - /** - * Validate the Auto Scalar policy removal - * - * @param autoscalePolicyId Auto Scalar policy id boolean - * @return - */ - public static boolean removableAutoScalerPolicy(String autoscalePolicyId) { - Collection applicationContexts = AutoscalerContext.getInstance(). - getApplicationContexts(); - for (ApplicationContext applicationContext : applicationContexts) { - if(applicationContext.getComponents().getCartridgeContexts() != null) { - for(CartridgeContext cartridgeContext : applicationContext.getComponents(). - getCartridgeContexts()) { - if(autoscalePolicyId.equals(cartridgeContext.getSubscribableInfoContext(). - getAutoscalingPolicy())) { - return false; + try { + startTime = System.currentTimeMillis(); + log.info("Starting monitor: [application] " + applicationId); + try { + applicationMonitor = MonitorFactory.getApplicationMonitor(applicationId); + } catch (PolicyValidationException e) { + String msg = "Monitor creation failed: [application] " + applicationId; + log.warn(msg, e); + retries--; } + success = true; + endTime = System.currentTimeMillis(); + } catch (DependencyBuilderException e) { + String msg = "Monitor creation failed: [application] " + applicationId; + log.warn(msg, e); + retries--; + } catch (TopologyInConsistentException e) { + String msg = "Monitor creation failed: [application] " + applicationId; + log.warn(msg, e); + retries--; } } - if(applicationContext.getComponents().getGroupContexts() != null) { - return findAutoscalingPolicyInGroup(applicationContext.getComponents().getGroupContexts(), - autoscalePolicyId); - } - } - return true; - } - - public static boolean findAutoscalingPolicyInGroup(GroupContext[] groupContexts, - String autoscalePolicyId) { - for(GroupContext groupContext : groupContexts) { - if(groupContext.getCartridgeContexts() != null) { - for(CartridgeContext cartridgeContext : groupContext.getCartridgeContexts()) { - if(autoscalePolicyId.equals(cartridgeContext.getSubscribableInfoContext(). - getAutoscalingPolicy())) { - return false; - } - } - - } - if(groupContext.getGroupContexts() != null) { - return findAutoscalingPolicyInGroup(groupContext.getGroupContexts(), - autoscalePolicyId); + if (applicationMonitor == null) { + String msg = "Monitor creation failed, even after retrying for 5 times: " + + "[application] " + applicationId; + log.error(msg); + throw new RuntimeException(msg); } - } - return true; - } - + AutoscalerContext autoscalerContext = AutoscalerContext.getInstance(); + autoscalerContext.removeApplicationPendingMonitor(applicationId); + autoscalerContext.removeAppMonitor(applicationId); + autoscalerContext.addAppMonitor(applicationMonitor); - /** - * Validate the deployment policy removal - * - * @param deploymentPolicyId - * @return - */ - public static boolean removableDeploymentPolicy(String deploymentPolicyId) { - boolean canRemove = true; - Map applications = ApplicationHolder.getApplications().getApplications(); - for (Application application : applications.values()) { - List deploymentPolicyIdsReferredInApplication = AutoscalerUtil. - getDeploymentPolicyIdsReferredInApplication(application.getUniqueIdentifier()); - for (String deploymentPolicyIdInApp : deploymentPolicyIdsReferredInApplication) { - if (deploymentPolicyId.equals(deploymentPolicyIdInApp)) { - canRemove = false; - } + long startupTime = ((endTime - startTime) / 1000); + if (log.isInfoEnabled()) { + log.info(String.format("Monitor started successfully: [application] %s [dependents] %s " + + "[startup-time] %d seconds", applicationMonitor.getId(), + applicationMonitor.getStartupDependencyTree(), startupTime)); } } - return canRemove; - } - - public static void readApplicationContextsFromRegistry() { - String[] resourcePaths = RegistryManager.getInstance().getApplicationContextResourcePaths(); - if ((resourcePaths == null) || (resourcePaths.length == 0)) { - return; - } - - for (String resourcePath : resourcePaths) { - ApplicationContext applicationContext = RegistryManager.getInstance(). - getApplicationContextByResourcePath(resourcePath); - AutoscalerContext.getInstance().addApplicationContext( applicationContext); - } } } diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/ConfUtil.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/ConfUtil.java index 28c5f66af4..969490e587 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/ConfUtil.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/ConfUtil.java @@ -34,12 +34,10 @@ public class ConfUtil { private static Log log = LogFactory.getLog(ConfUtil.class); - - private XMLConfiguration config; - //To maintain the map of config files private static HashMap instanceMap = new HashMap(); private static Object mutex = new Object(); + private XMLConfiguration config; private ConfUtil(String configFilePath) { try { diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/ServiceReferenceHolder.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/ServiceReferenceHolder.java index 36b048ebe1..4cc175c07c 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/ServiceReferenceHolder.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/ServiceReferenceHolder.java @@ -60,38 +60,38 @@ public static ServiceReferenceHolder getInstance() { return instance; } - public void setAxisConfiguration(AxisConfiguration axisConfiguration) { - this.axisConfiguration = axisConfiguration; - } - public AxisConfiguration getAxisConfiguration() { return axisConfiguration; } - public void setDistributedObjectProvider(DistributedObjectProvider distributedObjectProvider) { - this.distributedObjectProvider = distributedObjectProvider; + public void setAxisConfiguration(AxisConfiguration axisConfiguration) { + this.axisConfiguration = axisConfiguration; } public DistributedObjectProvider getDistributedObjectProvider() { return distributedObjectProvider; } - public void setHazelcastInstance(HazelcastInstance hazelcastInstance) { - this.hazelcastInstance = hazelcastInstance; + public void setDistributedObjectProvider(DistributedObjectProvider distributedObjectProvider) { + this.distributedObjectProvider = distributedObjectProvider; } public HazelcastInstance getHazelcastInstance() { return hazelcastInstance; } - public void setRegistry(UserRegistry governanceSystemRegistry) { - registry = governanceSystemRegistry; + public void setHazelcastInstance(HazelcastInstance hazelcastInstance) { + this.hazelcastInstance = hazelcastInstance; } public Registry getRegistry() { return registry; } + public void setRegistry(UserRegistry governanceSystemRegistry) { + registry = governanceSystemRegistry; + } + public TaskService getTaskService() { return taskService; } @@ -116,19 +116,19 @@ public void setGroupStatusProcessorChain(GroupStatusProcessorChain groupStatusPr this.groupStatusProcessorChain = groupStatusProcessorChain; } - public void setExecutorService(ExecutorService executorService) { - this.executorService = executorService; - } - public ExecutorService getExecutorService() { return executorService; } - public void setComponentStartUpSynchronizer(ComponentStartUpSynchronizer componentStartUpSynchronizer) { - this.componentStartUpSynchronizer = componentStartUpSynchronizer; + public void setExecutorService(ExecutorService executorService) { + this.executorService = executorService; } public ComponentStartUpSynchronizer getComponentStartUpSynchronizer() { return componentStartUpSynchronizer; } + + public void setComponentStartUpSynchronizer(ComponentStartUpSynchronizer componentStartUpSynchronizer) { + this.componentStartUpSynchronizer = componentStartUpSynchronizer; + } } diff --git a/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/AutoscalerUtilTest.java b/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/AutoscalerUtilTest.java index 2f65281b31..c676ed1a54 100644 --- a/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/AutoscalerUtilTest.java +++ b/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/AutoscalerUtilTest.java @@ -79,7 +79,7 @@ public void testFindTenantIdRange() { @Test public void testRemovalOfAutoscalingPolicy() { List cartridgeContexts = new ArrayList(); - for(int i = 0; i < 12; i++) { + for (int i = 0; i < 12; i++) { CartridgeContext cartridgeContext = new CartridgeContext(); SubscribableInfoContext subscribableContext = new SubscribableInfoContext(); subscribableContext.setAlias("cart-" + i); @@ -89,12 +89,12 @@ public void testRemovalOfAutoscalingPolicy() { cartridgeContexts.add(cartridgeContext); } List groupContextList = new ArrayList(); - for(int i = 0; i < 5; i++) { + for (int i = 0; i < 5; i++) { GroupContext groupContext = new GroupContext(); groupContext.setAlias("group-" + i); CartridgeContext[] cartridgeContexts1 = new CartridgeContext[2]; cartridgeContexts1[0] = cartridgeContexts.get(i); - cartridgeContexts1[1] = cartridgeContexts.get(i+5); + cartridgeContexts1[1] = cartridgeContexts.get(i + 5); groupContext.setCartridgeContexts(cartridgeContexts1); groupContextList.add(groupContext); @@ -123,7 +123,7 @@ public void testRemovalOfAutoscalingPolicy() { canRemove = AutoscalerUtil.removableAutoScalerPolicy("test"); assertEquals(canRemove, true); - for(int i = 0; i < 12; i ++) { + for (int i = 0; i < 12; i++) { canRemove = AutoscalerUtil.removableAutoScalerPolicy("auto-" + i); assertEquals(canRemove, false); diff --git a/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/TestMinimumRule.java b/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/TestMinimumRule.java index 2928d2d247..e1402092c9 100644 --- a/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/TestMinimumRule.java +++ b/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/TestMinimumRule.java @@ -45,6 +45,10 @@ public class TestMinimumRule { private StatefulKnowledgeSession ksession; private XMLConfiguration conf; + public static String get() { + return "null"; + } + @Before public void setUp() { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); @@ -95,8 +99,4 @@ public void testMinimumRule() { assertEquals(true, TestDelegator.isMinRuleFired()); } - - public static String get() { - return "null"; - } } diff --git a/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/TestObsoletedMemberRule.java b/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/TestObsoletedMemberRule.java index 2654529035..bd75a630d9 100644 --- a/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/TestObsoletedMemberRule.java +++ b/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/TestObsoletedMemberRule.java @@ -46,6 +46,10 @@ public class TestObsoletedMemberRule { private StatefulKnowledgeSession ksession; private XMLConfiguration conf; + public static String get() { + return "null"; + } + @Before public void setUp() { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); @@ -171,8 +175,4 @@ public void testMoreThanOneObsoletedMemberCase() { } - - public static String get() { - return "null"; - } } diff --git a/components/org.apache.stratos.cartridge.agent/pom.xml b/components/org.apache.stratos.cartridge.agent/pom.xml index 7343bbd0ba..67c2ff73b7 100644 --- a/components/org.apache.stratos.cartridge.agent/pom.xml +++ b/components/org.apache.stratos.cartridge.agent/pom.xml @@ -19,14 +19,13 @@ --> - + 4.0.0 org.apache.stratos stratos-components-parent - 4.1.1 + 4.1.2-SNAPSHOT - 4.0.0 org.apache.stratos.cartridge.agent jar Apache Stratos - Cartridge Agent @@ -74,7 +73,6 @@ com.google.code.gson gson - 2.2.4 org.apache.stratos @@ -105,12 +103,12 @@ org.wso2.carbon org.wso2.carbon.utils - ${wso2carbon.version} + ${carbon.kernel.version} org.wso2.carbon org.wso2.carbon.databridge.agent.thrift - ${wso2carbon.version} + ${carbon.kernel.version} - + \ No newline at end of file diff --git a/components/org.apache.stratos.cartridge.agent/src/test/java/org/apache/stratos/cartridge/agent/test/JavaCartridgeAgentTest.java b/components/org.apache.stratos.cartridge.agent/src/test/java/org/apache/stratos/cartridge/agent/test/JavaCartridgeAgentTest.java index d92d8069f7..b286066385 100644 --- a/components/org.apache.stratos.cartridge.agent/src/test/java/org/apache/stratos/cartridge/agent/test/JavaCartridgeAgentTest.java +++ b/components/org.apache.stratos.cartridge.agent/src/test/java/org/apache/stratos/cartridge/agent/test/JavaCartridgeAgentTest.java @@ -77,7 +77,7 @@ public class JavaCartridgeAgentTest { private static final String PARTITION_ID = "partition-1"; private static final String TENANT_ID = "-1234"; private static final String SERVICE_NAME = "php"; - public static final String AGENT_NAME = "apache-stratos-cartridge-agent-4.1.1"; + public static final String AGENT_NAME = "apache-stratos-cartridge-agent-4.1.2-SNAPSHOT"; private static HashMap executorList; private static ArrayList serverSocketList; private final ArtifactUpdatedEvent artifactUpdatedEvent; @@ -249,7 +249,7 @@ private String setupJavaAgent() { } log.info("Copying agent jar"); - String agentJar = "org.apache.stratos.cartridge.agent-4.1.1.jar"; + String agentJar = "org.apache.stratos.cartridge.agent-4.1.2-SNAPSHOT.jar"; String agentJarSource = getResourcesFolderPath() + "/../" + agentJar; String agentJarDest = agentHome.getCanonicalPath() + "/lib/" + agentJar; FileUtils.copyFile(new File(agentJarSource), new File(agentJarDest)); diff --git a/components/org.apache.stratos.cli/pom.xml b/components/org.apache.stratos.cli/pom.xml index afd63d2cc3..13bdf18f6a 100644 --- a/components/org.apache.stratos.cli/pom.xml +++ b/components/org.apache.stratos.cli/pom.xml @@ -19,24 +19,17 @@ --> - + 4.0.0 org.apache.stratos stratos-components-parent - 4.1.1 + 4.1.2-SNAPSHOT - 4.0.0 org.apache.stratos.cli jar Apache Stratos - CLI Apache Stratos CLI - http://apache.org - - - 1.7.6 - 1.46 - @@ -100,7 +93,6 @@ com.google.code.gson gson - 2.2.4 org.apache.httpcomponents @@ -118,7 +110,6 @@ org.apache.maven.plugins maven-dependency-plugin - 2.7 copy @@ -161,8 +152,8 @@ + org.apache.maven.plugins maven-antrun-plugin - 1.7 pre-integration-test @@ -187,7 +178,6 @@ org.codehaus.mojo exec-maven-plugin - 1.3 @@ -276,4 +266,4 @@ - + \ No newline at end of file diff --git a/components/org.apache.stratos.cloud.controller/pom.xml b/components/org.apache.stratos.cloud.controller/pom.xml index 791ae4ca13..a8abc2ec33 100644 --- a/components/org.apache.stratos.cloud.controller/pom.xml +++ b/components/org.apache.stratos.cloud.controller/pom.xml @@ -19,18 +19,16 @@ --> - + 4.0.0 org.apache.stratos stratos-components-parent - 4.1.1 + 4.1.2-SNAPSHOT - 4.0.0 org.apache.stratos.cloud.controller bundle Apache Stratos - Cloud Controller - http://apache.org @@ -38,11 +36,9 @@ org.apache.felix maven-scr-plugin - org.apache.felix maven-bundle-plugin - 1.4.0 true @@ -50,20 +46,26 @@ ${project.artifactId} !org.apache.stratos.cloud.controller.internal.*, + !org.apache.stratos.cloud.controller.stub.*, org.apache.stratos.cloud.controller.*, org.apache.stratos.cloud.controller.internal.*, - !org.apache.commons.logging, - org.apache.commons.logging; version=0.0.0, + !org.apache.stratos.cloud.controller.*, + org.apache.commons.logging, org.apache.commons.io.*, org.wso2.carbon.utils.*, - org.apache.stratos.kubernetes.client, - org.apache.stratos.kubernetes.client.exceptions, - + org.apache.stratos.kubernetes.client; version="${project.version}", + org.apache.stratos.kubernetes.client.exceptions; version="${project.version}", + org.jclouds.aws.ec2.*; version=${jclouds.version}, + org.jclouds.ec2.*; version=${jclouds.version}, + org.jclouds.compute.*; version=${jclouds.version}, + org.jclouds.domain.*; version=${jclouds.version}, + org.jclouds.googlecomputeengine*; version=${jclouds.version}, + org.jclouds.googlecloud.*; version=${jclouds.version}, + org.jclouds*; version=${jclouds.version}, *; resolution:=optional * @@ -94,12 +96,12 @@ org.wso2.carbon org.wso2.carbon.core - ${wso2carbon.version} + ${carbon.kernel.version} org.wso2.carbon org.wso2.carbon.utils - ${wso2carbon.version} + ${carbon.kernel.version} org.apache.stratos @@ -117,96 +119,59 @@ ${project.version} - com.google.guava - guava - 17.0 - - - com.jcraft - jsch.agentproxy.jsch - 0.0.7 - - - com.jcraft - jsch.agentproxy.core - 0.0.7 - - - com.jcraft - jsch.agentproxy.connector-factory - 0.0.7 + org.wso2.carbon + org.wso2.carbon.securevault + ${carbon.kernel.version} - org.reflections - reflections - 0.9.9-RC1 + org.wso2.carbon + org.wso2.carbon.analytics.hive.stub + ${carbon.kernel.version} - org.apache.jclouds.api - cloudstack - ${jclouds.version} + com.google.code.gson + gson org.wso2.carbon - org.wso2.carbon.securevault - ${wso2carbon.version} + org.wso2.carbon.databridge.agent.thrift + ${carbon.kernel.version} - org.hectorclient.wso2 - hector-core - 1.1.0.wso2v1 - - - com.google.guava.wso2 - guava - - + org.apache.stratos + org.apache.stratos.metadata.client + ${project.version} - org.wso2.andes.wso2 - andes-client - 0.13.wso2v3 + org.apache.stratos + org.apache.stratos.mock.iaas.client + ${project.version} - org.apache.geronimo.specs.wso2 - geronimo-jms_1.1_spec - ${orbit.version.geronimo-jms_1.1_spec} + org.apache.stratos + kubernetes-api + ${kubernetes.api.version} org.wso2.carbon - org.wso2.carbon.analytics.hive.stub - ${wso2carbon.version} + org.wso2.carbon.ntask.core + ${carbon.kernel.version} + - org.apache.jclouds - jclouds-core + org.apache.jclouds.api + cloudstack ${jclouds.version} org.apache.jclouds - jclouds-compute - ${jclouds.version} - - - org.apache.jclouds.driver - jclouds-bouncycastle - ${jclouds.version} - - - org.bouncycastle - bcprov-jdk16 - - - - - org.apache.jclouds.driver - jclouds-sshj + jclouds-core ${jclouds.version} - org.apache.jclouds.driver - jclouds-log4j + org.apache.jclouds + jclouds-compute ${jclouds.version} @@ -222,7 +187,7 @@ org.apache.stratos aws-ec2 - ${project.jclouds.stratos.version} + ${jclouds.version} org.apache.jclouds.api @@ -230,9 +195,9 @@ ${jclouds.version} - org.apache.stratos + org.apache.jclouds.labs openstack-neutron - ${project.jclouds.stratos.version} + ${jclouds.version} org.apache.jclouds.api @@ -246,84 +211,23 @@ org.apache.stratos - vcloud - ${project.jclouds.stratos.version} - - - org.apache.stratos - gce - ${project.jclouds.stratos.version} - - - com.jamesmurty.utils.wso2 - java-xmlbuilder - 0.4.wso2v1 - - - com.google.code.gson - gson - ${gson2.version} - - - com.google.guice.wso2 - guice - ${google.guice.wso2.version} - - - com.google.guice.assistedinject.wso2 - guice-assistedinject - ${com.google.guice.assistedinject.wso2.version} - - - com.sun.jersey - jersey-core - ${sun.jersey.version} - - - net.oauth.core - oauth - 20100527 - - - commons-io.wso2 - commons-io - 2.0.0.wso2v1 - - - rhino.wso2 - js - 1.7.0.R1-wso2v3 - - - org.wso2.carbon - org.wso2.carbon.databridge.agent.thrift - ${wso2carbon.version} - - - org.wso2.carbon - org.wso2.carbon.ntask.core - ${wso2carbon.version} + google-compute-engine + ${jclouds.version} - org.apache.stratos - org.apache.stratos.metadata.client - ${project.version} + org.apache.jclouds.driver + jclouds-log4j + ${jclouds.version} - org.apache.stratos - org.apache.stratos.mock.iaas.client - ${project.version} + org.apache.jclouds.driver + jclouds-slf4j + ${jclouds.version} - org.apache.stratos - kubernetes-api - ${kubernetes.api.stratos.version} + org.apache.jclouds.driver + jclouds-sshj + ${jclouds.version} - - 2.2 - 3.0.wso2v1 - 1.12 - - - + \ No newline at end of file diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/Iaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/Iaas.java index 1b17ddc105..543f251f4b 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/Iaas.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/Iaas.java @@ -171,4 +171,17 @@ public void setIaasProvider(IaasProvider iaasProvider) { * @throws InvalidMemberException */ public abstract void terminateInstance(MemberContext memberContext) throws InvalidCartridgeTypeException, InvalidMemberException, MemberTerminationFailedException; + + /** + * Get the group name which will be used when creating a node via jclouds API + * + * @param memberContext + * @param payload + */ + public String getGroupName(MemberContext memberContext, byte[] payload){ + String clusterId = memberContext.getClusterId(); + String str = clusterId.length() > 10 ? clusterId.substring(0, 10) : clusterId.substring(0, clusterId.length()); + String group = str.replaceAll("[^a-z0-9-]", ""); + return group; + } } diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsIaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsIaas.java index 942fe9e69a..fbd5fc1be3 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsIaas.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsIaas.java @@ -110,9 +110,7 @@ public MemberContext startInstance(MemberContext memberContext, byte[] payload) // Should have a length between 3-15 this.setDynamicPayload(payload); - String clusterId = memberContext.getClusterId(); - String str = clusterId.length() > 10 ? clusterId.substring(0, 10) : clusterId.substring(0, clusterId.length()); - String group = str.replaceAll("[^a-z0-9-]", ""); + String group = getIaasProvider().getIaas().getGroupName(memberContext, payload); try { ComputeService computeService = getIaasProvider().getComputeService(); diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/cloudstack/CloudStackPartitionValidator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/cloudstack/CloudStackPartitionValidator.java index e487f6dec0..579da5bb4a 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/cloudstack/CloudStackPartitionValidator.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/cloudstack/CloudStackPartitionValidator.java @@ -28,7 +28,7 @@ import org.apache.stratos.cloud.controller.iaases.ec2.EC2PartitionValidator; import org.apache.stratos.cloud.controller.services.impl.CloudControllerServiceUtil; import org.apache.stratos.cloud.controller.util.CloudControllerConstants; -import org.apache.stratos.messaging.domain.topology.Scope; +import org.apache.stratos.cloud.controller.util.Scope; import java.util.Properties; @@ -54,8 +54,8 @@ public IaasProvider validate(Partition partition, Properties properties) throws Iaas updatedIaas = CloudControllerServiceUtil.buildIaas(updatedIaasProvider); updatedIaas.setIaasProvider(updatedIaasProvider); - if (properties.containsKey(Scope.zone.toString())) { - String zone = properties.getProperty(Scope.zone.toString()); + if (properties.containsKey(Scope.ZONE.toString())) { + String zone = properties.getProperty(Scope.ZONE.toString()); iaas.isValidZone(null, zone); updatedIaasProvider.setProperty(CloudControllerConstants.AVAILABILITY_ZONE, zone); updatedIaas = CloudControllerServiceUtil.buildIaas(updatedIaasProvider); diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/ec2/EC2PartitionValidator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/ec2/EC2PartitionValidator.java index 03f57df8aa..e3a78b6dc5 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/ec2/EC2PartitionValidator.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/ec2/EC2PartitionValidator.java @@ -28,7 +28,7 @@ import org.apache.stratos.cloud.controller.iaases.PartitionValidator; import org.apache.stratos.cloud.controller.services.impl.CloudControllerServiceUtil; import org.apache.stratos.cloud.controller.util.CloudControllerConstants; -import org.apache.stratos.messaging.domain.topology.Scope; +import org.apache.stratos.cloud.controller.util.Scope; import java.util.Properties; @@ -46,8 +46,8 @@ public class EC2PartitionValidator implements PartitionValidator { public IaasProvider validate(Partition partition, Properties properties) throws InvalidPartitionException { // validate the existence of the region and zone properties. try { - if (properties.containsKey(Scope.region.toString())) { - String region = properties.getProperty(Scope.region.toString()); + if (properties.containsKey(Scope.REGION.toString())) { + String region = properties.getProperty(Scope.REGION.toString()); if (iaasProvider.getImage() != null && !iaasProvider.getImage().contains(region)) { @@ -63,8 +63,8 @@ public IaasProvider validate(Partition partition, Properties properties) throws Iaas updatedIaas = CloudControllerServiceUtil.buildIaas(updatedIaasProvider); updatedIaas.setIaasProvider(updatedIaasProvider); - if (properties.containsKey(Scope.zone.toString())) { - String zone = properties.getProperty(Scope.zone.toString()); + if (properties.containsKey(Scope.ZONE.toString())) { + String zone = properties.getProperty(Scope.ZONE.toString()); iaas.isValidZone(region, zone); updatedIaasProvider.setProperty(CloudControllerConstants.AVAILABILITY_ZONE, zone); updatedIaas = CloudControllerServiceUtil.buildIaas(updatedIaasProvider); diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/gce/GCEIaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/gce/GCEIaas.java index 975fe0c399..5cb293495a 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/gce/GCEIaas.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/gce/GCEIaas.java @@ -27,6 +27,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.cloud.controller.domain.IaasProvider; +import org.apache.stratos.cloud.controller.domain.MemberContext; import org.apache.stratos.cloud.controller.domain.NetworkInterface; import org.apache.stratos.cloud.controller.exception.CloudControllerException; import org.apache.stratos.cloud.controller.exception.InvalidHostException; @@ -37,23 +38,23 @@ import org.apache.stratos.cloud.controller.util.CloudControllerConstants; import org.apache.stratos.cloud.controller.util.ComputeServiceBuilderUtil; import org.jclouds.ContextBuilder; -import org.jclouds.collect.IterableWithMarker; import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; -import org.jclouds.compute.options.TemplateOptions; import org.jclouds.domain.Location; import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; -import org.jclouds.googlecomputeengine.domain.*; +import org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions; +import org.jclouds.googlecomputeengine.domain.AttachDisk; +import org.jclouds.googlecomputeengine.domain.Disk; +import org.jclouds.googlecomputeengine.domain.Instance; +import org.jclouds.googlecomputeengine.domain.Operation; import org.jclouds.googlecomputeengine.features.DiskApi; import org.jclouds.googlecomputeengine.features.InstanceApi; -import org.jclouds.googlecomputeengine.features.RegionApi; -import org.jclouds.googlecomputeengine.features.ZoneApi; -import org.jclouds.googlecomputeengine.options.AttachDiskOptions; -import org.jclouds.googlecomputeengine.options.AttachDiskOptions.DiskType; +import org.jclouds.googlecomputeengine.options.DiskCreationOptions; +import java.net.URI; import java.util.*; import java.util.concurrent.atomic.AtomicReference; @@ -61,11 +62,9 @@ import static org.jclouds.util.Predicates2.retry; public class GCEIaas extends JcloudsIaas { - - private static final Log log = LogFactory.getLog(GCEIaas.class); - - private static final String PROJECTNAME = "projectName"; + public static final int MAX_WAIT_TIME = 60; // seconds + public static final String GCE_NETWORK_PROPERTY = "networkURI"; public GCEIaas(IaasProvider iaasProvider) { super(iaasProvider); @@ -91,10 +90,10 @@ public void buildTemplate() { throw new CloudControllerException(msg); } - log.info("gce buildTemplate"); - - TemplateBuilder templateBuilder = iaasInfo.getComputeService() - .templateBuilder(); + if (log.isDebugEnabled()) { + log.debug("Building template for Google Compute Engine IaaS"); + } + TemplateBuilder templateBuilder = iaasInfo.getComputeService().templateBuilder(); // set image id specified templateBuilder.imageId(iaasInfo.getImage()); @@ -106,8 +105,7 @@ public void buildTemplate() { if (location.getScope().toString().equalsIgnoreCase(CloudControllerConstants.ZONE_ELEMENT) && location.getId().equals(zone)) { templateBuilder.locationId(location.getId()); - log.info("ZONE has been set as " + zone - + " with id: " + location.getId()); + log.info("zone has been set as " + zone + " with id: " + location.getId()); break; } } @@ -117,14 +115,14 @@ public void buildTemplate() { // set instance type eg: m1.large templateBuilder.hardwareId(iaasInfo.getProperty(CloudControllerConstants.INSTANCE_TYPE)); } - // build the Template Template template = templateBuilder.build(); if (zone != null) { if (!template.getLocation().getId().equals(zone)) { - log.warn("couldn't find assignable ZONE of id :" + zone + - " in the IaaS. Hence using the default location as " + template.getLocation().getScope().toString() + + log.warn("couldn't find assignable zone of id :" + zone + + " in the IaaS. Hence using the default location as " + + template.getLocation().getScope().toString() + " with the id " + template.getLocation().getId()); } } @@ -134,15 +132,8 @@ public void buildTemplate() { // wish to assign IPs manually, it can be non-blocking. // is auto-assign-ip mode or manual-assign-ip mode? - default mode is // non-blocking - boolean blockUntilRunning = Boolean.parseBoolean(iaasInfo - .getProperty("autoAssignIp")); - template.getOptions().as(TemplateOptions.class) - .blockUntilRunning(blockUntilRunning); - - // this is required in order to avoid creation of additional security - // groups by Jclouds. - template.getOptions().as(TemplateOptions.class) - .inboundPorts(22, 80, 8080, 443, 8243); + boolean blockUntilRunning = Boolean.parseBoolean(iaasInfo.getProperty("autoAssignIp")); + template.getOptions().as(GoogleComputeEngineTemplateOptions.class).blockUntilRunning(blockUntilRunning); if (zone != null) { templateBuilder.locationId(zone); @@ -154,24 +145,33 @@ public void buildTemplate() { for (String propertyKey : iaasInfo.getProperties().keySet()) { if (propertyKey.startsWith(CloudControllerConstants.TAGS_AS_KEY_VALUE_PAIRS_PREFIX)) { - keyValuePairTagsMap.put(propertyKey.substring(CloudControllerConstants.TAGS_AS_KEY_VALUE_PAIRS_PREFIX.length()), - iaasInfo.getProperties().get(propertyKey)); - template.getOptions() - .userMetadata(keyValuePairTagsMap); + keyValuePairTagsMap.put(propertyKey.substring(CloudControllerConstants.TAGS_AS_KEY_VALUE_PAIRS_PREFIX + .length()), iaasInfo.getProperties().get(propertyKey)); + template.getOptions().as(GoogleComputeEngineTemplateOptions.class).userMetadata(keyValuePairTagsMap); } - log.info("usermeta data key:" + propertyKey + " value: " + iaasInfo.getProperties().get(propertyKey)); + log.info("User defined property [key]" + propertyKey + ", [value] " + + iaasInfo.getProperties().get(propertyKey)); } if (iaasInfo.getNetworkInterfaces() != null) { List networks = new ArrayList(iaasInfo.getNetworkInterfaces().length); for (NetworkInterface ni : iaasInfo.getNetworkInterfaces()) { networks.add(ni.getNetworkUuid()); - log.info("using network interface " + ni.getNetworkUuid()); } - template.getOptions().as(TemplateOptions.class).networks(networks); - log.info("using network interface " + networks); + template.getOptions().as(GoogleComputeEngineTemplateOptions.class).networks(networks); + log.info("Using network interfaces: " + networks); } + if (iaasInfo.getProperty(GCEIaas.GCE_NETWORK_PROPERTY) != null) { + try { + URI networkURI = new URI(iaasInfo.getProperty(GCEIaas.GCE_NETWORK_PROPERTY)); + template.getOptions().as(GoogleComputeEngineTemplateOptions.class).network(networkURI); + log.info("Using GCE network: " + networkURI.toString()); + } + catch (Exception e) { + log.error("Error while adding the network", e); + } + } // set Template iaasInfo.setTemplate(template); } @@ -226,25 +226,15 @@ public void releaseAddress(String ip) { @Override public boolean isValidRegion(String region) throws InvalidRegionException { IaasProvider iaasInfo = getIaasProvider(); - if (region == null || iaasInfo == null) { String msg = "Region or IaaSProvider is null: region: " + region + " - IaaSProvider: " + iaasInfo; log.error(msg); throw new InvalidRegionException(msg); } - GoogleComputeEngineApi api = getGCEApi(); - RegionApi regionApi = api.getRegionApiForProject(iaasInfo.getProperty(PROJECTNAME)); - - for (IterableWithMarker page : regionApi.list()) { - for (Region r : page) { - if (region.equalsIgnoreCase(r.getName())) { - log.debug("Found a matching region: " + region); - return true; - } - } + if (api.regions().get(region) != null) { + return true; } - String msg = "Invalid region: " + region + " in the iaas: " + iaasInfo.getType(); log.error(msg); throw new InvalidRegionException(msg); @@ -255,24 +245,16 @@ public boolean isValidZone(String region, String zone) throws InvalidZoneExcepti IaasProvider iaasInfo = getIaasProvider(); if (zone == null || iaasInfo == null) { - String msg = "Zone or IaaSProvider is null: region: " + region + - " zone: " + zone + " - IaaSProvider: " + iaasInfo; + String msg = "Zone or IaaSProvider is null. [region] " + region + ", [zone] " + zone + ", [IaaSProvider] " + + iaasInfo; log.error(msg); throw new InvalidZoneException(msg); } GoogleComputeEngineApi api = getGCEApi(); - ZoneApi zoneApi = api.getZoneApiForProject(iaasInfo.getProperty(PROJECTNAME)); - - for (IterableWithMarker page : zoneApi.list()) { - for (Zone z : page) { - if (zone.equalsIgnoreCase(z.getName())) { - log.debug("Found a matching zone: " + zone); - return true; - } - } + if (api.zones().get(zone) != null) { + return true; } - String msg = "Invalid zone: " + zone + " in the region: " + region + " and of the iaas: " + iaasInfo.getType(); log.error(msg); throw new InvalidZoneException(msg); @@ -302,19 +284,23 @@ public String createVolume(int sizeGB, String snapshotId) { String diskName = "stratos-disk-" + rand.nextInt(100000); DiskApi diskApi = getGCEDiskApi(); String zone = getZone(); - - log.debug("Creating volume: " + diskName + " in zone: " + zone + " of size: " + sizeGB); - - Operation oper = diskApi.createInZone(diskName, sizeGB, zone); - - oper = waitGCEOperationDone(oper); - if (oper.getStatus() != Operation.Status.DONE) { - log.error("Failed to create volume: " + diskName + " of size: " + sizeGB + - " in zone: " + zone + " operation: " + oper); - return null; + log.info("Creating volume: " + diskName + " in zone: " + zone + " of size: " + sizeGB); + try { + DiskCreationOptions diskCreationOptions = new DiskCreationOptions.Builder().sizeGb(sizeGB).sourceSnapshot + (new URI(snapshotId)).build(); + Operation oper = diskApi.create(diskName, diskCreationOptions); + oper = waitGCEOperationDone(oper); + if (!oper.status().equals(Operation.Status.DONE)) { + log.error("Failed to create volume: " + diskName + " of size: " + sizeGB + + " in zone: " + zone + " operation: " + oper); + return null; + } + return diskName; } - - return diskName; + catch (Exception e) { + log.error("Error creating volume", e); + } + return null; } @Override @@ -323,64 +309,55 @@ public String attachVolume(String instanceId, String volumeId, String deviceName InstanceApi instApi = getGCEInstanceApi(); String zone = getZone(); - log.debug("Trying to attach volume: " + volumeId + " to instance: " + instanceId + + log.info("Trying to attach volume: " + volumeId + " to instance: " + instanceId + " in zone: " + zone + " at devicename: " + deviceName); - Disk disk = diskApi.getInZone(zone, volumeId); + Disk disk = diskApi.get(volumeId); if (disk == null) { log.error("Failed to get volume: " + volumeId + " in zone: " + zone); return null; } - log.debug("Found volumeId: " + volumeId + " volume: " + disk); - - Operation oper = instApi.attachDiskInZone(zone, instanceId, - new AttachDiskOptions().type(DiskType.PERSISTENT) - .source(disk.getSelfLink()) - .mode(AttachDiskOptions.DiskMode.READ_WRITE) - .deviceName(deviceName)); - oper = waitGCEOperationDone(oper); - if (oper.getStatus() != Operation.Status.DONE) { - log.error("Failed to attach volume: " + volumeId + " to instance: " + instanceId + - " in zone: " + zone + " at device: " + deviceName + " operation: " + oper); - return null; + try { + Operation oper = + instApi.attachDisk(instanceId, AttachDisk.create(AttachDisk.Type.PERSISTENT, AttachDisk.Mode + .READ_WRITE, disk.selfLink(), deviceName, true, null, false, null, null)); + oper = waitGCEOperationDone(oper); + if (!oper.status().equals(Operation.Status.DONE)) { + log.error("Failed to attach volume: " + volumeId + " to instance: " + instanceId + + " in zone: " + zone + " at device: " + deviceName + " operation: " + oper); + return null; + } + return volumeId; } - - return volumeId; + catch (Exception e) { + log.error("Error attaching volume", e); + } + return null; } @Override public void detachVolume(String instanceId, String volumeId) { InstanceApi instApi = getGCEInstanceApi(); String zone = getZone(); - Instance inst = instApi.getInZone(zone, instanceId); - - log.debug("Trying to detach volume: " + volumeId + " from instance: " + instanceId + - " " + inst + " in zone: " + zone); - + Instance inst = instApi.get(instanceId); + log.info("Trying to detach volume: " + volumeId + " from instance: " + instanceId + " in zone: " + zone); if (inst == null) { log.error("Failed to find instance: " + instanceId + " in zone: " + zone); return; } - - for (Instance.AttachedDisk disk : inst.getDisks()) { - Instance.PersistentAttachedDisk persistentDisk = (Instance.PersistentAttachedDisk) disk; - - log.debug("Found disk - src: " + persistentDisk.getSourceDiskName() + - " devicename: " + persistentDisk.getDeviceName()); - - if (persistentDisk.getSourceDiskName().equals(volumeId)) { - Operation oper = instApi.detachDiskInZone(zone, instanceId, persistentDisk.getDeviceName().get()); + for (Instance.AttachedDisk disk : inst.disks()) { + if (disk.deviceName().equals(volumeId)) { + log.info("Found disk to be detached. Source: " + disk.source() + " devicename: " + disk.deviceName()); + Operation oper = instApi.detachDisk(instanceId, disk.deviceName()); oper = waitGCEOperationDone(oper); - if (oper.getStatus() != Operation.Status.DONE) { + if (!oper.status().equals(Operation.Status.DONE)) { log.error("Failed to detach volume: " + volumeId + " to instance: " + instanceId + - " in zone: " + zone + " at device: " + persistentDisk.getDeviceName() + - " result operation: " + oper); + " in zone: " + zone + " at device: " + disk.deviceName() + " result operation: " + oper); } return; } } - log.error("Cannot find volume: " + volumeId + " in instance: " + instanceId); } @@ -388,13 +365,11 @@ public void detachVolume(String instanceId, String volumeId) { public void deleteVolume(String volumeId) { DiskApi diskApi = getGCEDiskApi(); String zone = getZone(); - - log.debug("Deleting volume: " + volumeId + " in zone: " + zone); - - Operation oper = diskApi.deleteInZone(zone, volumeId); + log.info("Deleting volume: " + volumeId + " in zone: " + zone); + Operation oper = diskApi.delete(volumeId); oper = waitGCEOperationDone(oper); - if (oper.getStatus() != Operation.Status.DONE) { + if (!oper.status().equals(Operation.Status.DONE)) { log.error("Failed to delete volume: " + volumeId + " in zone: " + zone + " operation: " + oper); } @@ -419,19 +394,14 @@ private GoogleComputeEngineApi getGCEApi() { } private DiskApi getGCEDiskApi() { - IaasProvider iaasInfo = getIaasProvider(); - String projectName = iaasInfo.getProperty(PROJECTNAME); - return getGCEApi().getDiskApiForProject(projectName); + return getGCEApi().disksInZone(getZone()); } private InstanceApi getGCEInstanceApi() { - IaasProvider iaasInfo = getIaasProvider(); - String projectName = iaasInfo.getProperty(PROJECTNAME); - return getGCEApi().getInstanceApiForProject(projectName); + return getGCEApi().instancesInZone(getZone()); } private Operation waitGCEOperationDone(Operation operation) { - int maxWaitTime = 15; // 15 seconds IaasProvider iaasInfo = getIaasProvider(); Injector injector = ContextBuilder.newBuilder(iaasInfo.getProvider()) .credentials(iaasInfo.getIdentity(), iaasInfo.getCredential()) @@ -440,9 +410,16 @@ private Operation waitGCEOperationDone(Operation operation) { injector.getInstance(Key.get(new TypeLiteral>>() { }, Names.named("zone"))); AtomicReference operationReference = Atomics.newReference(operation); - retry(zoneOperationDonePredicate, maxWaitTime, 1, SECONDS).apply(operationReference); + retry(zoneOperationDonePredicate, MAX_WAIT_TIME, 1, SECONDS).apply(operationReference); return operationReference.get(); } -} + @Override + public String getGroupName(MemberContext memberContext, byte[] payload) { + String clusterId = memberContext.getClusterId(); + String str = clusterId.length() > 10 ? clusterId.substring(0, 10) : clusterId.substring(0, clusterId.length()); + String group = "stratos-" + str.replaceAll("[^a-z0-9-]", ""); + return group.toLowerCase(); + } +} \ No newline at end of file diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/gce/GCEPartitionValidator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/gce/GCEPartitionValidator.java index 71d7aa31ec..2b0db6295f 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/gce/GCEPartitionValidator.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/gce/GCEPartitionValidator.java @@ -22,9 +22,13 @@ import org.apache.commons.logging.LogFactory; import org.apache.stratos.cloud.controller.domain.IaasProvider; import org.apache.stratos.cloud.controller.domain.Partition; +import org.apache.stratos.cloud.controller.exception.InvalidIaasProviderException; import org.apache.stratos.cloud.controller.exception.InvalidPartitionException; +import org.apache.stratos.cloud.controller.iaases.Iaas; import org.apache.stratos.cloud.controller.iaases.PartitionValidator; -import org.apache.stratos.cloud.controller.iaases.vcloud.VCloudPartitionValidator; +import org.apache.stratos.cloud.controller.services.impl.CloudControllerServiceUtil; +import org.apache.stratos.cloud.controller.util.CloudControllerConstants; +import org.apache.stratos.cloud.controller.util.Scope; import java.util.Properties; @@ -34,17 +38,75 @@ */ public class GCEPartitionValidator implements PartitionValidator { - private static final Log log = LogFactory.getLog(VCloudPartitionValidator.class); - + private static final Log log = LogFactory.getLog(GCEPartitionValidator.class); private IaasProvider iaasProvider; + private Iaas iaas; @Override public IaasProvider validate(Partition partition, Properties properties) throws InvalidPartitionException { - return iaasProvider; + try { + if (properties.containsKey(Scope.REGION.toString())) { + String region = properties.getProperty(Scope.REGION.toString()); + + if (iaasProvider.getImage() != null && !iaasProvider.getImage().contains(region)) { + + String message = "Invalid partition detected, invalid region. [partition-id] " + partition.getId() + + ", [region] " + region; + log.error(message); + throw new InvalidPartitionException(message); + } + + iaas.isValidRegion(region); + + IaasProvider updatedIaasProvider = new IaasProvider(iaasProvider); + Iaas updatedIaas = CloudControllerServiceUtil.buildIaas(updatedIaasProvider); + updatedIaas.setIaasProvider(updatedIaasProvider); + + if (properties.containsKey(Scope.ZONE.toString())) { + String zone = properties.getProperty(Scope.ZONE.toString()); + iaas.isValidZone(region, zone); + updatedIaasProvider.setProperty(CloudControllerConstants.AVAILABILITY_ZONE, zone); + updatedIaas = CloudControllerServiceUtil.buildIaas(updatedIaasProvider); + updatedIaas.setIaasProvider(updatedIaasProvider); + } + + updateOtherProperties(updatedIaasProvider, properties); + return updatedIaasProvider; + } else { + return iaasProvider; + } + } + catch (Exception ex) { + String message = "Invalid partition detected: [partition-id] " + partition.getId(); + throw new InvalidPartitionException(message, ex); + } + } + + private void updateOtherProperties(IaasProvider updatedIaasProvider, Properties properties) { + Iaas updatedIaas; + try { + updatedIaas = CloudControllerServiceUtil.buildIaas(updatedIaasProvider); + + for (Object property : properties.keySet()) { + if (property instanceof String) { + String key = (String) property; + updatedIaasProvider.setProperty(key, properties.getProperty(key)); + if (log.isDebugEnabled()) { + log.debug("Added property " + key + " to the IaasProvider."); + } + } + } + updatedIaas = CloudControllerServiceUtil.buildIaas(updatedIaasProvider); + updatedIaas.setIaasProvider(updatedIaasProvider); + } + catch (InvalidIaasProviderException ignore) { + } + } @Override public void setIaasProvider(IaasProvider iaasProvider) { this.iaasProvider = iaasProvider; + this.iaas = iaasProvider.getIaas(); } } diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java index 5904346fb3..fa1a9b3825 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java @@ -23,6 +23,7 @@ import io.fabric8.kubernetes.api.model.EnvVar; import io.fabric8.kubernetes.api.model.Pod; import io.fabric8.kubernetes.api.model.Service; +import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang.NotImplementedException; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; @@ -107,7 +108,7 @@ public void setDynamicPayload(byte[] payloadByteArray) { if (parameterArray != null) { for (String parameter : parameterArray) { if (parameter != null) { - String[] nameValueArray = parameter.split(PAYLOAD_PARAMETER_NAME_VALUE_SEPARATOR); + String[] nameValueArray = parameter.split(PAYLOAD_PARAMETER_NAME_VALUE_SEPARATOR, 2); if ((nameValueArray != null) && (nameValueArray.length == 2)) { NameValuePair nameValuePair = new NameValuePair(nameValueArray[0], nameValueArray[1]); payload.add(nameValuePair); @@ -407,7 +408,7 @@ private void createPod(ClusterContext clusterContext, MemberContext memberContex // Create pod long podSeqNo = kubernetesClusterContext.getPodSeqNo().incrementAndGet(); String podId = "pod" + "-" + podSeqNo; - String podLabel = KubernetesIaasUtil.fixSpecialCharacters(clusterId); + String podLabel = DigestUtils.md5Hex(clusterId); String dockerImage = iaasProvider.getImage(); List environmentVariables = KubernetesIaasUtil.prepareEnvironmentVariables( clusterContext, memberContext); @@ -422,9 +423,9 @@ private void createPod(ClusterContext clusterContext, MemberContext memberContex kubernetesApi.createPod(podId, podLabel, dockerImage, cpu, memory, ports, environmentVariables); log.info(String.format("Pod started successfully: [application] %s [cartridge] %s [member] %s " + - "[pod] %s [cpu] %d [memory] %d MB", + "[pod] %s [pod-label] %s [cpu] %d [memory] %d MB", memberContext.getApplicationId(), memberContext.getCartridgeType(), - memberContext.getMemberId(), podId, cpu, memory)); + memberContext.getMemberId(), podId, podLabel, cpu, memory)); // Add pod id to member context memberContext.setKubernetesPodId(podId); @@ -510,12 +511,12 @@ private void createKubernetesServices(KubernetesApiClient kubernetesApi, Cluster // Find next service sequence no long serviceSeqNo = kubernetesClusterContext.getServiceSeqNo().incrementAndGet(); String serviceId = KubernetesIaasUtil.fixSpecialCharacters("service" + "-" + (serviceSeqNo)); - String serviceLabel = KubernetesIaasUtil.fixSpecialCharacters(clusterId); + String serviceLabel = DigestUtils.md5Hex(clusterId); if (log.isInfoEnabled()) { - log.info(String.format("Creating kubernetes service: [cluster] %s [service] %s " + + log.info(String.format("Creating kubernetes service: [cluster] %s [service] %s [service-label] %s " + "[protocol] %s [service-port] %d [container-port] %s", clusterId, - serviceId, clusterPortMapping.getProtocol(), + serviceId, serviceLabel, clusterPortMapping.getProtocol(), clusterPortMapping.getKubernetesServicePort(), containerPort)); } @@ -525,9 +526,18 @@ private void createKubernetesServices(KubernetesApiClient kubernetesApi, Cluster String containerPortName = KubernetesIaasUtil.preparePortNameFromPortMapping(clusterPortMapping); try { - // Services need to use minions private IP addresses for creating iptable rules - kubernetesApi.createService(serviceId, serviceLabel, servicePort, serviceType, containerPortName, - containerPort, sessionAffinity); + // If kubernetes service is already created, skip creating a new one + if (kubernetesApi.getService(serviceId) == null) { + // Services need to use minions private IP addresses for creating iptable rules + kubernetesApi.createService(serviceId, serviceLabel, servicePort, serviceType, containerPortName, + containerPort, sessionAffinity); + } else { + if (log.isDebugEnabled()) { + log.debug(String.format("Kubernetes service is already created: [cluster] %s [service] %s " + + "[protocol] %s [service-port] %d [container-port] %d", clusterId, + serviceId, clusterPortMapping.getProtocol(), servicePort, containerPort)); + } + } } finally { // Persist kubernetes service sequence no CloudControllerContext.getInstance().persist(); @@ -547,6 +557,7 @@ private void createKubernetesServices(KubernetesApiClient kubernetesApi, Cluster String[] minionPublicIPArray = minionPublicIPList.toArray(new String[minionPublicIPList.size()]); kubernetesService.setPublicIPs(minionPublicIPArray); kubernetesService.setProtocol(clusterPortMapping.getProtocol()); + kubernetesService.setPortName(clusterPortMapping.getName()); String kubernetesServiceType = service.getSpec().getType(); kubernetesService.setServiceType(kubernetesServiceType); @@ -622,15 +633,25 @@ private void generateKubernetesServicePorts(String applicationId, String cluster String serviceType = portMapping.getKubernetesPortType(); clusterPortMapping.setKubernetesServiceType(serviceType); - if (serviceType.equals(KubernetesConstants.NODE_PORT)) { - int nextServicePort = kubernetesClusterContext.getNextServicePort(); - if (nextServicePort == -1) { - throw new RuntimeException(String.format("Could not generate service port: [cluster-id] %s " + - "[port] %d", clusterId, portMapping.getPort())); + //If kubernetes service port is already set, skip setting a new one + if (clusterPortMapping.getKubernetesServicePort() == 0) { + if (serviceType.equals(KubernetesConstants.NODE_PORT)) { + int nextServicePort = kubernetesClusterContext.getNextServicePort(); + if (nextServicePort == -1) { + throw new RuntimeException(String.format("Could not generate service port: [cluster-id] %s " + + "[port] %d", clusterId, portMapping.getPort())); + } + clusterPortMapping.setKubernetesServicePort(nextServicePort); + } else { + clusterPortMapping.setKubernetesServicePort(portMapping.getPort()); } - clusterPortMapping.setKubernetesServicePort(nextServicePort); } else { - clusterPortMapping.setKubernetesServicePort(portMapping.getPort()); + if (log.isDebugEnabled()) { + log.debug(String.format("Kubernetes service port is already set: [application-id] %s " + + "[cluster-id] %s [port] %d [service-port] %d", + applicationId, clusterId, clusterPortMapping.getPort(), + clusterPortMapping.getKubernetesServicePort())); + } } // Add port mappings to payload diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/openstack/OpenstackPartitionValidator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/openstack/OpenstackPartitionValidator.java index 24f8e01933..a8077b82b6 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/openstack/OpenstackPartitionValidator.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/openstack/OpenstackPartitionValidator.java @@ -28,7 +28,7 @@ import org.apache.stratos.cloud.controller.iaases.PartitionValidator; import org.apache.stratos.cloud.controller.services.impl.CloudControllerServiceUtil; import org.apache.stratos.cloud.controller.util.CloudControllerConstants; -import org.apache.stratos.messaging.domain.topology.Scope; +import org.apache.stratos.cloud.controller.util.Scope; import java.util.Properties; @@ -47,8 +47,8 @@ public class OpenstackPartitionValidator implements PartitionValidator { public IaasProvider validate(Partition partition, Properties properties) throws InvalidPartitionException { try { // validate the existence of the zone and hosts properties. - if (properties.containsKey(Scope.region.toString())) { - String region = properties.getProperty(Scope.region.toString()); + if (properties.containsKey(Scope.REGION.toString())) { + String region = properties.getProperty(Scope.REGION.toString()); if (iaasProvider.getImage() != null && !iaasProvider.getImage().contains(region)) { @@ -64,8 +64,8 @@ public IaasProvider validate(Partition partition, Properties properties) throws Iaas updatedIaas = CloudControllerServiceUtil.buildIaas(updatedIaasProvider); updatedIaas.setIaasProvider(updatedIaasProvider); - if (properties.containsKey(Scope.zone.toString())) { - String zone = properties.getProperty(Scope.zone.toString()); + if (properties.containsKey(Scope.ZONE.toString())) { + String zone = properties.getProperty(Scope.ZONE.toString()); iaas.isValidZone(region, zone); updatedIaasProvider.setProperty(CloudControllerConstants.AVAILABILITY_ZONE, zone); diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/vcloud/VCloudIaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/vcloud/VCloudIaas.java deleted file mode 100644 index d87e04d4a7..0000000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/vcloud/VCloudIaas.java +++ /dev/null @@ -1,392 +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.cloud.controller.iaases.vcloud; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.domain.IaasProvider; -import org.apache.stratos.cloud.controller.domain.NetworkInterface; -import org.apache.stratos.cloud.controller.exception.CloudControllerException; -import org.apache.stratos.cloud.controller.iaases.JcloudsIaas; -import org.apache.stratos.cloud.controller.iaases.PartitionValidator; -import org.apache.stratos.cloud.controller.util.ComputeServiceBuilderUtil; -import org.jclouds.compute.ComputeService; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.Template; -import org.jclouds.compute.domain.TemplateBuilder; -import org.jclouds.compute.options.TemplateOptions; -import org.jclouds.vcloud.VCloudApi; -import org.jclouds.vcloud.compute.options.VCloudTemplateOptions; -import org.jclouds.vcloud.domain.DiskAttachOrDetachParams; -import org.jclouds.vcloud.domain.NetworkConnection; -import org.jclouds.vcloud.domain.Task; -import org.jclouds.vcloud.domain.Vm; -import org.jclouds.vcloud.domain.network.IpAddressAllocationMode; -import org.jclouds.vcloud.domain.network.OrgNetwork; -import org.jclouds.vcloud.features.VAppApi; -import org.jclouds.vcloud.features.VmApi; -import org.wso2.carbon.utils.CarbonUtils; - -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Hashtable; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; - - -public class VCloudIaas extends JcloudsIaas { - - - private static final Log log = LogFactory.getLog(VCloudIaas.class); - - private static final String SHELL_TYPE = "shellType"; - private static final String SCRIPTS_PATH = "scripts"; - private static final String CUSTOMIZATION_SCRIPT = "customization"; - private static final String PAYLOAD = "PAYLOAD"; - - public VCloudIaas(IaasProvider iaasProvider) { - super(iaasProvider); - } - - @Override - public void buildComputeServiceAndTemplate() { - // builds and sets Compute Service - ComputeService computeService = ComputeServiceBuilderUtil.buildDefaultComputeService(getIaasProvider()); - getIaasProvider().setComputeService(computeService); - - // builds and sets Template - buildTemplate(); - - } - - public void buildTemplate() { - IaasProvider iaasInfo = getIaasProvider(); - - if (iaasInfo.getComputeService() == null) { - String msg = "Compute service is null for IaaS provider: " - + iaasInfo.getName(); - log.fatal(msg); - throw new CloudControllerException(msg); - } - - //get 'native' version of jclouds' vCloud API. - ComputeServiceContext context = iaasInfo.getComputeService().getContext(); - VCloudApi api = context.unwrapApi(VCloudApi.class); - - - TemplateBuilder templateBuilder = iaasInfo.getComputeService() - .templateBuilder(); - - // set image id specified - templateBuilder.imageId(iaasInfo.getImage()); - - // build the Template - Template template = templateBuilder.build(); - - // if you wish to auto assign IPs, instance spawning call should be - // blocking, but if you - // wish to assign IPs manually, it can be non-blocking. - // is auto-assign-ip mode or manual-assign-ip mode? - default mode is - // non-blocking - boolean blockUntilRunning = Boolean.parseBoolean(iaasInfo - .getProperty("autoAssignIp")); - template.getOptions().as(TemplateOptions.class) - .blockUntilRunning(blockUntilRunning); - - // this is required in order to avoid creation of additional security - // groups by Jclouds. - template.getOptions().as(TemplateOptions.class) - .inboundPorts(22, 80, 8080, 443, 8243); - - if (iaasInfo.getNetworkInterfaces() != null) { - Set networksSet = new LinkedHashSet(iaasInfo.getNetworkInterfaces().length); - Hashtable vcloudNetworkOptions = new Hashtable(iaasInfo.getNetworkInterfaces().length); - - int i = 0; - for (NetworkInterface ni : iaasInfo.getNetworkInterfaces()) { - - String networkUuid = ni.getNetworkUuid(); - String networkName = null; - IpAddressAllocationMode ipAllocMode = IpAddressAllocationMode.NONE; - if (ni.getFixedIp() != null && !ni.getFixedIp().equals("")) { - ipAllocMode = IpAddressAllocationMode.MANUAL; - } else { - ipAllocMode = IpAddressAllocationMode.POOL; - } - - //fetch network name. - try { - OrgNetwork orgNet = api.getNetworkApi().getNetwork(new URI(networkUuid)); - networkName = orgNet.getName(); - } catch (URISyntaxException e) { - log.error("Network UUID '" + networkUuid + "' is not a URI/href."); - } - NetworkConnection nc = new NetworkConnection(networkName, i, ni.getFixedIp(), null, true, - null, //TODO: support fixed Mac addrs. - ipAllocMode); - networksSet.add(networkUuid); - vcloudNetworkOptions.put(networkUuid, nc); - - i++; - } - //new NetworkConnectionSection() - - //VmApi vmApi = api.getVmApi(); - //vmApi.updateNetworkConnectionOfVm(); - - template.getOptions().networks(networksSet); - template.getOptions().as(VCloudTemplateOptions.class).networkConnections(vcloudNetworkOptions); - } - - //template.getOptions().as(VCloudTemplateOptions.class) - // .ipAddressAllocationMode(IpAddressAllocationMode.POOL); - - // set Template - iaasInfo.setTemplate(template); - } - - @Override - public void setDynamicPayload(byte[] payload) { - // in vCloud case we need to run a script - IaasProvider iaasProvider = getIaasProvider(); - - if (iaasProvider.getTemplate() == null || payload == null) { - if (log.isDebugEnabled()) { - log.debug("Payload for vCloud not found"); - } - return; - } - - String shellType = iaasProvider.getProperty(SHELL_TYPE); - - if (shellType == null || shellType.isEmpty()) { - if (log.isDebugEnabled()) { - log.debug("Shell Type for vCloud Customization script not found from properties"); - } - return; - } - - if (log.isDebugEnabled()) { - log.debug(String.format("Shell Type '%s' will be used for vCloud Customization script", shellType)); - } - - // Payload is a String value - String payloadStr = new String(payload); - - if (log.isDebugEnabled()) { - log.debug(String.format("Payload '%s' will be used for vCloud Customization script", payload)); - } - - Template template = iaasProvider.getTemplate(); - - File scriptPath = new File(CarbonUtils.getCarbonConfigDirPath(), SCRIPTS_PATH); - - File customizationScriptFile = new File(new File(scriptPath, shellType), CUSTOMIZATION_SCRIPT); - - if (!customizationScriptFile.exists()) { - if (log.isWarnEnabled()) { - log.warn(String.format("The vCloud Customization script '%s' does not exist", - customizationScriptFile.getAbsolutePath())); - } - return; - } - - String customizationScript = null; - - try { - customizationScript = FileUtils.readFileToString(customizationScriptFile); - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error( - String.format("Error reading the vCloud Customization script '%s'", - customizationScriptFile.getAbsolutePath()), e); - } - } - - if (StringUtils.isEmpty(customizationScript)) { - if (log.isDebugEnabled()) { - log.debug("No content vCloud Customization script not found from properties"); - } - return; - } - - // Set payload - customizationScript = customizationScript.replaceAll(PAYLOAD, payloadStr); - - if (log.isDebugEnabled()) { - log.debug(String.format("The vCloud Customization script\n%s", customizationScript)); - } - - // Ensure the script is run. - if (customizationScript.length() >= 49000) { - log.warn("The vCloud customization script is >=49000 bytes in size; uploading dummy script and running real script via ssh."); - String dummyCustomizationScript = "#!/bin/sh\n" - + "#STRATOS: the real customization script will be invoked via ssh, since it exceeds the 49000 byte limit " - + "imposed by vCloud;\n" - + "#see " - + "http://pubs.vmware.com/vcd-55/topic/com.vmware.vcloud.api.doc_55/GUID-1BA3B7C5-B46C-48F7-8704-945BC47A940D.html\n"; - template.getOptions().as(VCloudTemplateOptions.class).customizationScript(dummyCustomizationScript); - template.getOptions().runScript(customizationScript); - } else { - template.getOptions().as(VCloudTemplateOptions.class).customizationScript(customizationScript); - } - - // Run the script - //template.getOptions().runScript(customizationScript); - } - - @Override - public boolean createKeyPairFromPublicKey(String region, String keyPairName, String publicKey) { - - // TODO - return false; - } - - @Override - public List associateAddresses(NodeMetadata node) { - - // TODO - return null; - - } - - @Override - public String associatePredefinedAddress(NodeMetadata node, String ip) { - return ""; - } - - @Override - public void releaseAddress(String ip) { - // TODO - } - - @Override - public boolean isValidRegion(String region) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean isValidZone(String region, String zone) { - // TODO Auto-generated method stub - return true; - } - - @Override - public boolean isValidHost(String zone, String host) { - // TODO Auto-generated method stub - return true; - } - - @Override - public PartitionValidator getPartitionValidator() { - return new VCloudPartitionValidator(); - } - - @Override - public String createVolume(int sizeGB, String snapshotId) { - // TODO Auto-generated method stub - return null; - } - - @Override - public String attachVolume(String instanceId, String volumeId, String deviceName) { - IaasProvider iaasInfo = getIaasProvider(); - - if (StringUtils.isEmpty(volumeId)) { - log.error("Volume provided to attach can not be null"); - } - - if (StringUtils.isEmpty(instanceId)) { - log.error("Instance provided to attach can not be null"); - } - - URI instanceIdHref = null; - URI volumeIdHref = null; - try { - //the instanceId format is a bit silly for vCloud. - instanceIdHref = new URI("https:/" + instanceId); - } catch (URISyntaxException e) { - log.error("Failed to attach volume, because the instance id cannot be converted into a url by concatenating " - + "'https:/' with " + instanceId + ". Full stacktrace: " + e.toString()); - return null; - } - try { - volumeIdHref = new URI(volumeId); - } catch (URISyntaxException e) { - log.error("Failed to attach voluume, because the volume id '" + volumeId + "' is not a valid href (URI))" - + e.toString()); - } - - //get 'native' version of jclouds' vCloud API. - ComputeServiceContext context = iaasInfo.getComputeService() - .getContext(); - - VCloudApi api = context.unwrapApi(VCloudApi.class); - - //Disks need to be attached to individual VMs, not vApps. The instanceId is the VApp. - VAppApi vAppApi = api.getVAppApi(); - Set vmsInVapp = vAppApi.getVApp(instanceIdHref).getChildren(); - //Each vApp today has just 1 VM in it. Validate assumption. - assert (vmsInVapp.size() == 1); - Vm vm = vmsInVapp.iterator().next(); - URI vmHref = vm.getHref(); - VmApi vmApi = api.getVmApi(); - - // invest - /* - VCloudHardDisk.Builder hardDiskBuilder = new VCloudHardDisk.Builder(); - VCloudHardDisk hardDisk = hardDiskBuilder.instanceID(volumeId).build(); - VCloudVirtualHardwareSection vvhs = vm.getVirtualHardwareSection(); - VCloudHardDisk.Builder Vchd = new VCloudHardDisk.Builder(); - vvhs.toBuilder().item(Vchd.capacity(3).instanceID("hgfhgf").build()).build(); - VApp va = vAppApi.getVApp(instanceIdHref); - - */ //EO invest - DiskAttachOrDetachParams params = new DiskAttachOrDetachParams(volumeIdHref); - Task t = vmApi.attachDisk(vmHref, params); - - log.info(String.format("Volume [id]: %s attachment for instance [id]: %s was successful [status]: Attaching. Iaas : %s, Task: %s", volumeId, instanceId, iaasInfo, t)); - return "Attaching"; - } - - @Override - public void detachVolume(String instanceId, String volumeId) { - // TODO Auto-generated method stub - - } - - @Override - public void deleteVolume(String volumeId) { - // TODO Auto-generated method stub - - } - - @Override - public String getIaasDevice(String device) { - return device; - } - -} diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/vcloud/VCloudPartitionValidator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/vcloud/VCloudPartitionValidator.java deleted file mode 100644 index 5a197411a4..0000000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/vcloud/VCloudPartitionValidator.java +++ /dev/null @@ -1,56 +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.cloud.controller.iaases.vcloud; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.domain.IaasProvider; -import org.apache.stratos.cloud.controller.domain.Partition; -import org.apache.stratos.cloud.controller.exception.InvalidPartitionException; -import org.apache.stratos.cloud.controller.iaases.Iaas; -import org.apache.stratos.cloud.controller.iaases.PartitionValidator; - -import java.util.Properties; - - -/** - * The VCloud {@link org.apache.stratos.cloud.controller.iaases.PartitionValidator} implementation. - */ -public class VCloudPartitionValidator implements PartitionValidator { - - @SuppressWarnings("unused") - private static final Log log = LogFactory.getLog(VCloudPartitionValidator.class); - private IaasProvider iaasProvider; - @SuppressWarnings("unused") - private Iaas iaas; - - @Override - public IaasProvider validate(Partition partition, Properties properties) throws InvalidPartitionException { - //TODO: implement real validation logic - return iaasProvider; - - } - - @Override - public void setIaasProvider(IaasProvider iaas) { - this.iaasProvider = iaas; - this.iaas = iaas.getIaas(); - } - -} diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/internal/CloudControllerServiceComponent.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/internal/CloudControllerServiceComponent.java index 21eb37a6aa..2e21e8e9d7 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/internal/CloudControllerServiceComponent.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/internal/CloudControllerServiceComponent.java @@ -69,9 +69,7 @@ * cardinality="1..1" policy="dynamic" bind="setConfigurationContextService" unbind="unsetConfigurationContextService" */ public class CloudControllerServiceComponent { - private static final Log log = LogFactory.getLog(CloudControllerServiceComponent.class); - private static final String CLOUD_CONTROLLER_COORDINATOR_LOCK = "cloud.controller.coordinator.lock"; private static final String THREAD_POOL_ID = "cloud.controller.thread.pool"; private static final String SCHEDULER_THREAD_POOL_ID = "cloud.controller.scheduler.thread.pool"; @@ -85,6 +83,9 @@ public class CloudControllerServiceComponent { private ScheduledExecutorService scheduler; protected void activate(final ComponentContext context) { + if (log.isDebugEnabled()) { + log.debug("Activating CloudControllerServiceComponent..."); + } try { executorService = StratosThreadPool.getExecutorService(THREAD_POOL_ID, THREAD_POOL_SIZE); scheduler = StratosThreadPool.getScheduledExecutorService(SCHEDULER_THREAD_POOL_ID, @@ -124,7 +125,8 @@ public void run() { executeCoordinatorTasks(); } - componentStartUpSynchronizer.waitForWebServiceActivation("CloudControllerService"); + componentStartUpSynchronizer.waitForAxisServiceActivation(Component.CloudController, + "CloudControllerService"); componentStartUpSynchronizer.setComponentStatus(Component.CloudController, true); log.info("Cloud controller service component activated"); } catch (Exception e) { diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java index a11c5bf2dd..ecd2728bab 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java @@ -451,6 +451,16 @@ public static void handleMemberInitializedEvent(MemberContext memberContext) { MemberStatus.Initialized); return; } else { + + Cluster cluster = service.getCluster(memberContext.getClusterId()); + String clusterId = cluster.getClusterId(); + ClusterContext clusterContext = CloudControllerContext.getInstance().getClusterContext(clusterId); + List kubernetesServices = clusterContext.getKubernetesServices(); + + if (kubernetesServices != null) { + cluster.setKubernetesServices(kubernetesServices); + } + member.setStatus(MemberStatus.Initialized); log.info("Member status updated to initialized"); @@ -844,11 +854,9 @@ public static void handleClusterActivatedEvent(ClusterStatusClusterActivatedEven try { TopologyManager.acquireWriteLock(); List kubernetesServices = clusterContext.getKubernetesServices(); - cluster.setKubernetesServices(kubernetesServices); if (kubernetesServices != null) { - // Set kubernetes services - cluster.setKubernetesServices(kubernetesServices); + try { // Generate access URLs for kubernetes services for (KubernetesService kubernetesService : kubernetesServices) { diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Scope.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Scope.java similarity index 91% rename from components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Scope.java rename to components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Scope.java index 4c228b3517..984494e79c 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Scope.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Scope.java @@ -16,11 +16,11 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.stratos.messaging.domain.topology; +package org.apache.stratos.cloud.controller.util; /** * represents the scope of each partition which can be configured in stratos. */ public enum Scope { - provider, region, zone, host + PROVIDER, REGION, ZONE, HOST } diff --git a/components/org.apache.stratos.common/pom.xml b/components/org.apache.stratos.common/pom.xml index 578cc501a7..1371b4ee25 100644 --- a/components/org.apache.stratos.common/pom.xml +++ b/components/org.apache.stratos.common/pom.xml @@ -18,19 +18,18 @@ --> + 4.0.0 org.apache.stratos stratos-components-parent - 4.1.1 + 4.1.2-SNAPSHOT - 4.0.0 org.apache.stratos.common bundle Apache Stratos - Common - org.apache.felix @@ -39,7 +38,6 @@ org.apache.felix maven-bundle-plugin - true @@ -72,14 +70,17 @@ org.wso2.carbon org.wso2.carbon.registry.core + ${carbon.kernel.version} org.wso2.carbon org.wso2.carbon.user.core + ${carbon.kernel.version} org.wso2.carbon org.wso2.carbon.user.mgt + ${carbon.kernel.version} org.apache.stratos @@ -99,12 +100,13 @@ junit junit + ${junit.version} test org.wso2.carbon org.wso2.carbon.databridge.commons - ${wso2carbon.version} + ${carbon.kernel.version} commons-lang.wso2 @@ -124,7 +126,7 @@ org.wso2.carbon org.wso2.carbon.databridge.agent.thrift - ${wso2carbon.version} + ${carbon.kernel.version} - + \ No newline at end of file diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/application/ApplicationBean.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/application/ApplicationBean.java index 71e0c6c0ea..1c7295db91 100644 --- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/application/ApplicationBean.java +++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/application/ApplicationBean.java @@ -37,6 +37,7 @@ public class ApplicationBean implements Serializable { private String alias; private String status; private ComponentBean components; + private boolean signUpsExist; private List property; public String getApplicationId() { @@ -102,4 +103,12 @@ public List getProperty() { public void setProperty(List property) { this.property = property; } + + public boolean isSignUpsExist() { + return signUpsExist; + } + + public void setSignUpsExist(boolean signUpsExist) { + this.signUpsExist = signUpsExist; + } } diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/client/StratosManagerServiceClient.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/client/StratosManagerServiceClient.java index 909d52eadf..a7dd9ad9e0 100644 --- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/client/StratosManagerServiceClient.java +++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/client/StratosManagerServiceClient.java @@ -112,6 +112,29 @@ public ApplicationSignUp getApplicationSignUp(String applicationId, int tenantId return stub.getApplicationSignUp(applicationId, tenantId); } + /** + * Check application signup availability + * @param applicationId + * @param tenantId + * @return + * @throws StratosManagerServiceApplicationSignUpExceptionException + * @throws RemoteException + */ + public boolean applicationSignUpExist(String applicationId, int tenantId) throws StratosManagerServiceApplicationSignUpExceptionException, RemoteException { + return stub.applicationSignUpExist(applicationId, tenantId); + } + + /** + * Check application signup availability + * @param applicationId + * @return + * @throws StratosManagerServiceApplicationSignUpExceptionException + * @throws RemoteException + */ + public boolean applicationSignUpsExist(String applicationId) throws StratosManagerServiceApplicationSignUpExceptionException, RemoteException { + return stub.applicationSignUpsExist(applicationId); + } + /** * Get application signups. * diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/CommonServiceComponent.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/CommonServiceComponent.java index e2d6eed971..1059988778 100644 --- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/CommonServiceComponent.java +++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/CommonServiceComponent.java @@ -53,10 +53,12 @@ * cardinality="1..1" policy="dynamic" bind="setConfigurationContextService" unbind="unsetConfigurationContextService" */ public class CommonServiceComponent { - private static Log log = LogFactory.getLog(CommonServiceComponent.class); protected void activate(ComponentContext context) { + if (log.isDebugEnabled()) { + log.debug("Activating CommonServiceComponent..."); + } try { final BundleContext bundleContext = context.getBundleContext(); if (CommonUtil.getStratosConfig() == null) { @@ -80,6 +82,7 @@ public void run() { long startTime = System.currentTimeMillis(); log.info("Waiting for the hazelcast instance to be initialized..."); while (ServiceReferenceHolder.getInstance().getHazelcastInstance() == null) { + log.info("Waiting for Hazelcast instance to be initialized..."); Thread.sleep(1000); if ((System.currentTimeMillis() - startTime) >= StratosConstants.HAZELCAST_INSTANCE_INIT_TIMEOUT) { throw new RuntimeException("Hazelcast instance was not initialized within " @@ -97,7 +100,6 @@ public void run() { thread.setName("Distributed object provider registration thread"); thread.start(); } else { - // Register distributed object provider service registerDistributedObjectProviderService(bundleContext); registerComponentStartUpSynchronizer(bundleContext); } diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/ComponentStartUpSynchronizerImpl.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/ComponentStartUpSynchronizerImpl.java index cb4bb1d4ac..39f8364c44 100644 --- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/ComponentStartUpSynchronizerImpl.java +++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/internal/ComponentStartUpSynchronizerImpl.java @@ -39,11 +39,10 @@ * Stratos component startup synchronizer. */ public class ComponentStartUpSynchronizerImpl implements ComponentStartUpSynchronizer { - private static final Log log = LogFactory.getLog(ComponentStartUpSynchronizerImpl.class); - private static final String COMPONENT_STATUS_MAP = "stratos.component.status.map"; - private static final String COMPONENT_STARTUP_SYNCHRONIZER_ENABLED = "stratos.component.startup.synchronizer.enabled"; + private static final String COMPONENT_STARTUP_SYNCHRONIZER_ENABLED = + "stratos.component.startup.synchronizer.enabled"; private static final String COMPONENT_ACTIVATION_CHECK_INTERVAL = "stratos.component.activation.check.interval"; private static final String COMPONENT_ACTIVATION_TIMEOUT = "stratos.component.activation.timeout"; private static final long DEFAULT_COMPONENT_ACTIVATION_CHECK_INTERVAL = 1000; @@ -64,12 +63,12 @@ public class ComponentStartUpSynchronizerImpl implements ComponentStartUpSynchro componentActivationCheckInterval = Long.getLong(COMPONENT_ACTIVATION_CHECK_INTERVAL, DEFAULT_COMPONENT_ACTIVATION_CHECK_INTERVAL); - log.info(String.format("Component activation check interval: %s seconds", + log.info(String.format("Component activation check interval: %s seconds.", (componentActivationCheckInterval / 1000))); componentActivationTimeout = Long.getLong(COMPONENT_ACTIVATION_TIMEOUT, DEFAULT_COMPONENT_ACTIVATION_TIMEOUT); - log.info(String.format("Component activation timeout: %s seconds", (componentActivationTimeout / 1000))); + log.info(String.format("Component activation timeout: %s seconds.", (componentActivationTimeout / 1000))); } /** @@ -86,17 +85,16 @@ public boolean isEnabled() { * Set the status of a component. * * @param component - * @param active + * @param isActive */ @Override - public void setComponentStatus(Component component, boolean active) { - componentStatusMap.put(component, active); - - if (active) { + public void setComponentStatus(Component component, boolean isActive) { + componentStatusMap.put(component, isActive); + if (isActive) { notifyComponentActivationEventListeners(component); - log.info(String.format("%s activated", component)); + log.info(String.format("%s activated.", component)); } else { - log.info(String.format("%s inactivated", component)); + log.info(String.format("%s inactivated.", component)); } } @@ -112,8 +110,9 @@ private void notifyComponentActivationEventListeners(Component component) { ComponentActivationEventListener componentActivationEventListener = (ComponentActivationEventListener) eventListener; componentActivationEventListener.activated(component); - } catch (Exception e) { - log.error("An error occurred while notifying component activation event listener", e); + } + catch (Exception e) { + log.error("An error occurred while notifying component activation event listener.", e); } } } @@ -141,32 +140,28 @@ public boolean isComponentActive(Component component) { */ @Override public void waitForComponentActivation(Component owner, Component component) { - if (!componentStartUpSynchronizerEnabled) { - log.debug(String.format("Component activation check is disabled, %s did not wait for %s to be activated", + log.info(String.format("Component activation check is disabled, %s did not wait for %s to be activated.", owner, component)); return; } - long startTime = System.currentTimeMillis(); - boolean logged = false; + log.info(String.format("%s is set to wait for %s to be activated.", owner, component)); while (!isComponentActive(component)) { - if (!logged) { - log.info(String.format("%s is waiting for %s to be activated...", - owner, component)); - logged = true; + if (log.isDebugEnabled()) { + log.debug(String.format("%s is waiting for %s to be activated...", owner, component)); } - try { Thread.sleep(componentActivationCheckInterval); - } catch (InterruptedException ignore) { + } + catch (InterruptedException ignore) { throw new RuntimeException(String.format("Thread interrupted, %s could not wait for " + - "%s to be activated", owner, component)); + "%s to be activated.", owner, component)); } long currentTime = System.currentTimeMillis(); if ((currentTime - startTime) > componentActivationTimeout) { - throw new RuntimeException(String.format("%s did not activated within %d seconds ", + throw new RuntimeException(String.format("%s did not activate within %d seconds.", component, (componentActivationTimeout / 1000))); } } @@ -175,31 +170,32 @@ public void waitForComponentActivation(Component owner, Component component) { /** * Wait for a web service to be activated. * - * @param serviceName + * @param axisServiceName * @throws AxisFault */ @Override - public void waitForWebServiceActivation(String serviceName) throws AxisFault { - + public void waitForAxisServiceActivation(Component owner, String axisServiceName) throws AxisFault { if (!componentStartUpSynchronizerEnabled) { - log.debug(String.format("Component activation check is disabled, did not wait for %s to be activated", - serviceName)); + log.info(String.format("Component activation check is disabled, did not wait for %s to be activated.", + axisServiceName)); return; } AxisConfiguration axisConfiguration = CarbonConfigurationContextFactory.getConfigurationContext() .getAxisConfiguration(); - AxisService cloudControllerService = axisConfiguration.getService(serviceName); - if (!cloudControllerService.isActive()) { - while (!cloudControllerService.isActive()) { - log.info(String.format("Waiting for %s web service to be activated...", serviceName)); + AxisService axisService = axisConfiguration.getService(axisServiceName); + log.info(String.format("%s is set to wait for %s Axis service to be activated.", owner, axisServiceName)); + if (!axisService.isActive()) { + while (!axisService.isActive()) { + log.info(String.format("%s is waiting for %s Axis service to be activated...", owner, axisServiceName)); try { Thread.sleep(componentActivationCheckInterval); - } catch (InterruptedException ignore) { + } + catch (InterruptedException ignore) { return; } } - log.info(String.format("%s web service activated", serviceName)); + log.info(String.format("%s Axis service activated.", axisServiceName)); } } @@ -212,4 +208,4 @@ public void waitForWebServiceActivation(String serviceName) throws AxisFault { public void addEventListener(ComponentStartUpEventListener eventListener) { eventListeners.add(eventListener); } -} +} \ No newline at end of file diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/services/ComponentStartUpSynchronizer.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/services/ComponentStartUpSynchronizer.java index 1eebdeb89b..e4320d61f5 100644 --- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/services/ComponentStartUpSynchronizer.java +++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/services/ComponentStartUpSynchronizer.java @@ -35,7 +35,7 @@ public interface ComponentStartUpSynchronizer { void waitForComponentActivation(Component owner, Component component); - void waitForWebServiceActivation(String serviceName) throws AxisFault; + void waitForAxisServiceActivation(Component owner, String serviceName) throws AxisFault; void addEventListener(ComponentStartUpEventListener eventListener); } diff --git a/components/org.apache.stratos.custom.handlers/pom.xml b/components/org.apache.stratos.custom.handlers/pom.xml index 157b37540f..9d914d11f8 100644 --- a/components/org.apache.stratos.custom.handlers/pom.xml +++ b/components/org.apache.stratos.custom.handlers/pom.xml @@ -16,21 +16,20 @@ ~ specific language governing permissions and limitations ~ under the License. --> - + + 4.0.0 org.apache.stratos stratos-components-parent - 4.1.1 + 4.1.2-SNAPSHOT - 4.0.0 org.apache.stratos.custom.handlers bundle Apache Stratos - Custom Handlers Custom Handlers - http://apache.org + org.wso2.carbon @@ -50,27 +49,27 @@ org.wso2.carbon org.wso2.carbon.logging - ${wso2carbon.version} + ${carbon.kernel.version} org.wso2.carbon org.wso2.carbon.core - ${wso2carbon.version} + ${carbon.kernel.version} org.wso2.carbon org.wso2.carbon.core.common - ${wso2carbon.version} + ${carbon.kernel.version} org.wso2.carbon org.wso2.carbon.core.services - ${wso2carbon.version} + ${carbon.kernel.version} org.wso2.carbon org.wso2.carbon.utils - ${wso2carbon.version} + ${carbon.kernel.version} opensaml.wso2 @@ -92,7 +91,6 @@ org.apache.felix maven-bundle-plugin - 1.4.0 true @@ -117,4 +115,4 @@ - + \ No newline at end of file diff --git a/components/org.apache.stratos.custom.handlers/src/main/java/org/apache/stratos/custom/handlers/internal/SignedJWTAuthenticatorServiceComponent.java b/components/org.apache.stratos.custom.handlers/src/main/java/org/apache/stratos/custom/handlers/internal/SignedJWTAuthenticatorServiceComponent.java index 390368bbda..1caa31cfb1 100644 --- a/components/org.apache.stratos.custom.handlers/src/main/java/org/apache/stratos/custom/handlers/internal/SignedJWTAuthenticatorServiceComponent.java +++ b/components/org.apache.stratos.custom.handlers/src/main/java/org/apache/stratos/custom/handlers/internal/SignedJWTAuthenticatorServiceComponent.java @@ -42,7 +42,6 @@ * unbind="unsetRealmService" */ public class SignedJWTAuthenticatorServiceComponent { - private static final Log log = LogFactory.getLog(SignedJWTAuthenticatorServiceComponent.class); private static RealmService realmService = null; private static BundleContext bundleContext = null; @@ -67,6 +66,9 @@ public static void setBundleContext(BundleContext bundleContext) { } protected void activate(ComponentContext cxt) { + if (log.isDebugEnabled()) { + log.debug("Activating SignedJWTAuthenticatorServiceComponent..."); + } try { SignedJWTAuthenticator authenticator = new SignedJWTAuthenticator(); SignedJWTAuthenticatorServiceComponent.setBundleContext(cxt.getBundleContext()); @@ -74,19 +76,18 @@ protected void activate(ComponentContext cxt) { props.put(CarbonConstants.AUTHENTICATOR_TYPE, authenticator.getAuthenticatorName()); cxt.getBundleContext().registerService(CarbonServerAuthenticator.class.getName(), authenticator, props); - } catch (Exception e) { + } + catch (Exception e) { log.error(e.getMessage(), e); // throwing so that server will not start throw new RuntimeException("Failed to start the Signed JWT Authenticator Bundle" + e.getMessage(), e); } - log.debug("Signed JWT Authenticator is activated"); + log.info("Signed JWT Authenticator is activated"); } protected void deactivate(ComponentContext context) { - if (log.isDebugEnabled()) { - log.debug("Signed JWT Authenticator is deactivated"); - } + log.debug("Signed JWT Authenticator is deactivated"); } protected void unsetRealmService(RealmService realmService) { diff --git a/components/org.apache.stratos.deployment/pom.xml b/components/org.apache.stratos.deployment/pom.xml deleted file mode 100644 index 42f86f12bc..0000000000 --- a/components/org.apache.stratos.deployment/pom.xml +++ /dev/null @@ -1,97 +0,0 @@ - - - - org.apache.stratos - stratos-components-parent - 4.1.1 - - - 4.0.0 - org.apache.stratos.deployment - bundle - Apache Stratos - Deployment - - - - - - org.apache.felix - maven-scr-plugin - - - org.apache.felix - maven-bundle-plugin - - true - - - ${project.artifactId} - ${project.artifactId} - - org.apache.stratos.deployment.internal.* - - - !org.apache.stratos.deployment.internal.*, - org.apache.stratos.deployment.* - - - !javax.xml.namespace, - org.apache.axis2.*; version="${axis2.osgi.version.range}", - javax.xml.namespace; version=0.0.0, - javax.servlet;version="${imp.pkg.version.javax.servlet}", - javax.servlet.http;version="${imp.pkg.version.javax.servlet}", - *;resolution:=optional - - - - - - - - - - org.apache.stratos - org.apache.stratos.common - ${project.version} - - - org.apache.axis2.wso2 - axis2 - - - log4j - log4j - - - org.wso2.carbon - org.wso2.carbon.registry.core - ${wso2carbon.version} - - - commons-logging - commons-logging - - - - 1.6.1.wso2v8 - - - diff --git a/components/org.apache.stratos.deployment/src/main/java/org/apache/stratos/deployment/CloudDeploymentInterceptor.java b/components/org.apache.stratos.deployment/src/main/java/org/apache/stratos/deployment/CloudDeploymentInterceptor.java deleted file mode 100644 index f6abe30f23..0000000000 --- a/components/org.apache.stratos.deployment/src/main/java/org/apache/stratos/deployment/CloudDeploymentInterceptor.java +++ /dev/null @@ -1,92 +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.deployment; - -import org.apache.axiom.om.OMElement; -import org.apache.axis2.AxisFault; -import org.apache.axis2.description.AxisModule; -import org.apache.axis2.description.AxisOperation; -import org.apache.axis2.description.AxisService; -import org.apache.axis2.description.AxisServiceGroup; -import org.apache.axis2.description.Parameter; -import org.apache.axis2.engine.AxisConfiguration; -import org.apache.axis2.engine.AxisEvent; -import org.apache.axis2.engine.AxisObserver; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.xml.namespace.QName; -import java.util.ArrayList; - -/** - * Deployment interceptor for handling modification of ServiceAdmin so that the service list is not - * displayed when the user has not logged in. - */ -public class CloudDeploymentInterceptor implements AxisObserver { - private static final Log log = LogFactory.getLog(CloudDeploymentInterceptor.class); - - public void init(AxisConfiguration axisConfiguration) { - } - - public void serviceUpdate(AxisEvent axisEvent, AxisService axisService) { - try { - if (axisEvent.getEventType() == AxisEvent.SERVICE_DEPLOY && - axisService.getName().equals("ServiceAdmin")){ - AxisOperation operation = axisService.getOperation(new QName("listServiceGroups")); - ArrayList params = operation.getParameters(); - for(Parameter param: params) { - operation.removeParameter(param); - } - Parameter authAction = new Parameter("AuthorizationAction", - "/permission/admin/manage/monitor/service"); - operation.addParameter(authAction); - } - } catch (AxisFault e) { - log.error("Cannot add AuthorizationAction parameter to ServiceAdmin", e); - } - } - - public void serviceGroupUpdate(AxisEvent axisEvent, AxisServiceGroup axisServiceGroup) { - } - - public void moduleUpdate(AxisEvent axisEvent, AxisModule axisModule) { - } - - public void addParameter(Parameter parameter) throws AxisFault { - } - - public void removeParameter(Parameter parameter) throws AxisFault { - } - - public void deserializeParameters(OMElement omElement) throws AxisFault { - } - - public Parameter getParameter(String s) { - return null; - } - - public ArrayList getParameters() { - return null; - } - - public boolean isParameterLocked(String s) { - return false; - } -} diff --git a/components/org.apache.stratos.deployment/src/main/java/org/apache/stratos/deployment/SuperTenantRolePlayer.java b/components/org.apache.stratos.deployment/src/main/java/org/apache/stratos/deployment/SuperTenantRolePlayer.java deleted file mode 100644 index 9f75ea98ed..0000000000 --- a/components/org.apache.stratos.deployment/src/main/java/org/apache/stratos/deployment/SuperTenantRolePlayer.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.stratos.deployment; - -import org.apache.axiom.soap.RolePlayer; -import org.wso2.carbon.base.MultitenantConstants; -import org.wso2.carbon.context.CarbonContext; - -import java.util.List; -import java.util.ArrayList; - -public class SuperTenantRolePlayer implements RolePlayer{ - - private List roles; - - public SuperTenantRolePlayer() { - this.roles = new ArrayList(); - this.roles.add("supertenant"); - } - - public List getRoles() { - return this.roles; - } - - public boolean isUltimateDestination() { - return (CarbonContext.getCurrentContext().getTenantId() == - MultitenantConstants.SUPER_TENANT_ID); - } -} diff --git a/components/org.apache.stratos.deployment/src/main/java/org/apache/stratos/deployment/internal/CloudDeploymentServiceComponent.java b/components/org.apache.stratos.deployment/src/main/java/org/apache/stratos/deployment/internal/CloudDeploymentServiceComponent.java deleted file mode 100644 index 62f2ed0978..0000000000 --- a/components/org.apache.stratos.deployment/src/main/java/org/apache/stratos/deployment/internal/CloudDeploymentServiceComponent.java +++ /dev/null @@ -1,74 +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.deployment.internal; - -import org.apache.axis2.context.ConfigurationContext; -import org.apache.axis2.description.Parameter; -import org.apache.axis2.engine.AxisConfiguration; -import org.apache.axis2.engine.AxisObserver; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.deployment.CloudDeploymentInterceptor; -import org.apache.stratos.deployment.SuperTenantRolePlayer; -import org.osgi.service.component.ComponentContext; -import org.wso2.carbon.CarbonConstants; -import org.wso2.carbon.utils.ConfigurationContextService; - -import java.util.Dictionary; -import java.util.Hashtable; - -/** - * @scr.component name="org.apache.stratos.deployment.internal.CloudDeploymentServiceComponent" immediate="true" - * @scr.reference name="config.context.service" - * interface="org.wso2.carbon.utils.ConfigurationContextService" cardinality="1..1" - * policy="dynamic" bind="setConfigurationContextService" - * unbind="unsetConfigurationContextService" - */ -public class CloudDeploymentServiceComponent { - private static final Log log = LogFactory.getLog(CloudDeploymentServiceComponent.class); - - protected void activate(ComponentContext ctxt) { - //TODO: Modify the permission in the UI - try { - ConfigurationContext configContext = DataHolder.getInstance().getServerConfigContext(); - Dictionary props = new Hashtable(); - props.put(CarbonConstants.AXIS2_CONFIG_SERVICE, AxisObserver.class.getName()); - ctxt.getBundleContext().registerService(AxisObserver.class.getName(), new CloudDeploymentInterceptor(),props); - - // register the role player for this configuration - AxisConfiguration axisConfiguration = configContext.getAxisConfiguration(); - axisConfiguration.addParameter(new Parameter("rolePlayer", new SuperTenantRolePlayer())); - } catch (Exception e) { - log.error("CloudDeploymentServiceComponent activation failed", e); - } - } - - protected void deactivate(ComponentContext ctxt) { - - } - - protected void setConfigurationContextService(ConfigurationContextService contextService) { - DataHolder.getInstance().setServerConfigContext(contextService.getServerConfigContext()); - } - - protected void unsetConfigurationContextService(ConfigurationContextService contextService) { - DataHolder.getInstance().setServerConfigContext(null); - } -} diff --git a/components/org.apache.stratos.deployment/src/main/java/org/apache/stratos/deployment/internal/DataHolder.java b/components/org.apache.stratos.deployment/src/main/java/org/apache/stratos/deployment/internal/DataHolder.java deleted file mode 100644 index dde4d170fe..0000000000 --- a/components/org.apache.stratos.deployment/src/main/java/org/apache/stratos/deployment/internal/DataHolder.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.stratos.deployment.internal; - -import org.apache.axis2.context.ConfigurationContext; - -/** - * DataHolder for Service deployment component - */ -public class DataHolder { - private static DataHolder instance = new DataHolder(); - - private ConfigurationContext serverConfigContext; - - public static DataHolder getInstance() { - return instance; - } - - private DataHolder() { - } - - public ConfigurationContext getServerConfigContext() { - return serverConfigContext; - } - - public void setServerConfigContext(ConfigurationContext serverConfigContext) { - this.serverConfigContext = serverConfigContext; - } -} diff --git a/components/org.apache.stratos.email.sender/pom.xml b/components/org.apache.stratos.email.sender/pom.xml deleted file mode 100644 index a5b07fcafd..0000000000 --- a/components/org.apache.stratos.email.sender/pom.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - - org.apache.stratos - stratos-components-parent - 4.1.1 - ../pom.xml - - - 4.0.0 - org.apache.stratos.email.sender - bundle - Apache Stratos - Email Sender Component - - - - - - org.apache.felix - maven-scr-plugin - - - org.apache.felix - maven-bundle-plugin - - true - - - ${project.artifactId} - ${project.artifactId} - - org.apache.stratos.email.sender.internal.*, - org.apache.stratos.email.senderder.util.*, - - - org.apache.stratos.email.sender.api.* - - - !javax.xml.namespace, - javax.xml.namespace; version=0.0.0, - javax.servlet;version="${imp.pkg.version.javax.servlet}", - javax.servlet.http;version="${imp.pkg.version.javax.servlet}", - *;resolution:=optional - - - - - - - - - - org.apache.axis2.wso2 - axis2 - - - log4j - log4j - - - org.wso2.carbon - org.wso2.carbon.registry.core - - - commons-logging - commons-logging - - - - diff --git a/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/BulkEmailSender.java b/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/BulkEmailSender.java deleted file mode 100644 index afe752f4ca..0000000000 --- a/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/BulkEmailSender.java +++ /dev/null @@ -1,103 +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.email.sender.api; - -import org.apache.axiom.om.OMAbstractFactory; -import org.apache.axiom.om.OMElement; -import org.apache.axis2.AxisFault; -import org.apache.axis2.Constants; -import org.apache.axis2.addressing.EndpointReference; -import org.apache.axis2.client.Options; -import org.apache.axis2.client.ServiceClient; -import org.apache.axis2.context.ConfigurationContext; -import org.apache.axis2.context.MessageContext; -import org.apache.axis2.transport.base.BaseConstants; -import org.apache.axis2.transport.mail.MailConstants; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.email.sender.util.Util; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * The class that handles the bulk email sending logic for stratos. - */ -public class BulkEmailSender extends EmailSender{ - private static Log log = LogFactory.getLog(BulkEmailSender.class); - - public BulkEmailSender(EmailSenderConfiguration config) { - super(config); - } - - /** - * Sends the email - * @param bulkEmailData List of email data holder objects - * @throws Exception, if sending the email notification failed. - */ - public void sendBulkEmails(List bulkEmailData) throws Exception { - - final List emailDataHolderList = bulkEmailData; - - final ServiceClient serviceClient; - ConfigurationContext configContext = Util.getConfigurationContext(); - if (configContext != null) { - serviceClient = new ServiceClient(configContext, null); - } else { - serviceClient = new ServiceClient(); - } - - new Thread() { - public void run() { - - for(EmailDataHolder dataHolder : emailDataHolderList){ - - String subject = getMessageTitle(dataHolder.getEmailParameters()); - String body = getMessageBody(dataHolder.getEmailParameters()); - String email = dataHolder.getEmail(); // no change in here, - - Map headerMap = new HashMap(); - headerMap.put(MailConstants.MAIL_HEADER_SUBJECT, subject); - OMElement payload = OMAbstractFactory.getOMFactory().createOMElement( - BaseConstants.DEFAULT_TEXT_WRAPPER, null); - payload.setText(body); - - try { - Options options = new Options(); - options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE); - options.setProperty(MessageContext.TRANSPORT_HEADERS, headerMap); - options.setProperty(MailConstants.TRANSPORT_MAIL_FORMAT, - MailConstants.TRANSPORT_FORMAT_TEXT); - options.setTo(new EndpointReference("mailto:" + email)); - serviceClient.setOptions(options); - serviceClient.fireAndForget(payload); - serviceClient.cleanup(); - } catch (AxisFault e) { - String msg = "Error in delivering the message, " + - "subject: " + subject + ", to: " + email + "."; - log.error(msg); - } - } - - } - }.start(); - } - -} diff --git a/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/EmailDataHolder.java b/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/EmailDataHolder.java deleted file mode 100644 index 73d9199695..0000000000 --- a/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/EmailDataHolder.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.apache.stratos.email.sender.api; -/* - * - * 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. - * -*/ - - -import java.util.Map; - -//This holds the email address and email parameter map -public class EmailDataHolder { - - private String email; - private Map emailParameters; - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public Map getEmailParameters() { - return emailParameters; - } - - public void setEmailParameters(Map emailParameters) { - this.emailParameters = emailParameters; - } -} diff --git a/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/EmailSender.java b/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/EmailSender.java deleted file mode 100644 index 851227dc82..0000000000 --- a/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/EmailSender.java +++ /dev/null @@ -1,111 +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.email.sender.api; - -import org.apache.stratos.email.sender.util.Util; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.axis2.transport.mail.MailConstants; -import org.apache.axis2.transport.base.BaseConstants; -import org.apache.axis2.client.Options; -import org.apache.axis2.client.ServiceClient; -import org.apache.axis2.context.ConfigurationContext; -import org.apache.axis2.context.MessageContext; -import org.apache.axiom.om.OMElement; -import org.apache.axiom.om.OMAbstractFactory; -import org.apache.axis2.Constants; -import org.apache.axis2.AxisFault; -import org.apache.axis2.addressing.EndpointReference; - -import java.util.Map; -import java.util.HashMap; - -/** - * The class that handles the email sending logic for stratos. - */ -public class EmailSender{ - private static Log log = LogFactory.getLog(EmailSender.class); - private EmailSenderConfiguration config = null; - - public EmailSender(EmailSenderConfiguration config) { - this.config = config; - } - - /** - * Sends the email - * @param toEmail Email Address (To:) - * @param userParameters - map of user parameters - * @throws Exception, if sending the email notification failed. - */ - public void sendEmail(String toEmail, MapuserParameters) throws Exception { - final String subject = getMessageTitle(userParameters); - final String body = getMessageBody(userParameters); - final String email = toEmail; // no change in here, - new Thread() { - public void run() { - Map headerMap = new HashMap(); - headerMap.put(MailConstants.MAIL_HEADER_SUBJECT, subject); - OMElement payload = OMAbstractFactory.getOMFactory().createOMElement( - BaseConstants.DEFAULT_TEXT_WRAPPER, null); - payload.setText(body); - - try { - ServiceClient serviceClient; - ConfigurationContext configContext = Util.getConfigurationContext(); - if (configContext != null) { - serviceClient = new ServiceClient(configContext, null); - } else { - serviceClient = new ServiceClient(); - } - Options options = new Options(); - options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE); - options.setProperty(MessageContext.TRANSPORT_HEADERS, headerMap); - options.setProperty(MailConstants.TRANSPORT_MAIL_FORMAT, - MailConstants.TRANSPORT_FORMAT_TEXT); - options.setTo(new EndpointReference("mailto:" + email)); - serviceClient.setOptions(options); - serviceClient.fireAndForget(payload); - log.debug("Sending confirmation mail to " + email); - } catch (AxisFault e) { - String msg = "Error in delivering the message, " + - "subject: " + subject + ", to: " + email + "."; - log.error(msg); - } - } - }.start(); - } - - /** - * gets the title of the message - * @param userParameters - map of user parameters - * @return the title of the message - */ - protected String getMessageTitle(Map userParameters) { - return Util.replacePlaceHolders(config.getSubject(), userParameters); - } - - /** - * gets the body of the message - * @param userParameters - map of user parameters - * @return the body of the message - */ - protected String getMessageBody(Map userParameters) { - return Util.replacePlaceHolders(config.getBody(), userParameters); - } -} diff --git a/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/EmailSenderConfiguration.java b/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/EmailSenderConfiguration.java deleted file mode 100644 index 706ccac30f..0000000000 --- a/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/EmailSenderConfiguration.java +++ /dev/null @@ -1,134 +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.email.sender.api; - -import org.apache.axiom.om.OMElement; -import org.apache.axiom.om.impl.builder.StAXOMBuilder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -/** - * The class that handles the configuration of the email sender for Stratos - */ -public class EmailSenderConfiguration { - private static Log log = LogFactory.getLog(EmailSenderConfiguration.class); - - public final static String DEFAULT_VALUE_SUBJECT = "EmailSender"; - public final static String DEFAULT_VALUE_MESSAGE = "Sent form WSO2 Carbon"; - - private String fromEmail; - private String subject = DEFAULT_VALUE_SUBJECT; - private String body = DEFAULT_VALUE_MESSAGE; - private Map customParameters; - - public Map getCustomParameters() { - return customParameters; - } - - public void setCustomParameters(Map customParameters) { - this.customParameters = customParameters; - } - - - public String getSubject() { - return subject; - } - - public void setSubject(String subject) { - this.subject = subject.trim(); - } - - public String getBody() { - return body; - } - - public void setBody(String emailMessage) { - this.body = emailMessage.trim(); - } - - public String getFromEmail() { - return fromEmail; - } - - public void setFromEmail(String fromEmail) { - this.fromEmail = fromEmail; - } - - /** - * Loads the email sender configuration - * @param configFilename configuration file name - * @return EmailSenderConfiguration. - */ - public static EmailSenderConfiguration loadEmailSenderConfiguration(String configFilename) { - File configFile = new File(configFilename); - if (!configFile.exists()) { - log.error("Email sender configuration File is not present at: " + configFilename); - return null; - } - EmailSenderConfiguration config = new EmailSenderConfiguration(); - FileInputStream ip = null; - try { - ip = new FileInputStream(configFile); - XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(ip); - StAXOMBuilder builder = new StAXOMBuilder(parser); - OMElement documentElement = builder.getDocumentElement(); - Iterator it = documentElement.getChildElements(); - while (it.hasNext()) { - OMElement element = (OMElement) it.next(); - if ("subject".equals(element.getLocalName())) { - config.setSubject(element.getText()); - } else if ("body".equals(element.getLocalName())) { - config.setBody(element.getText()); - } else if ("customParameters".equals(element.getLocalName())) { - Map customParameters = new HashMap(); - Iterator customParamIt = element.getChildElements(); - while (customParamIt.hasNext()) { - OMElement customElement = (OMElement) it.next(); - customParameters.put(customElement.getLocalName(), customElement.getText()); - } - config.setCustomParameters(customParameters); - } - } - return config; - } catch (Exception e) { - String msg = "Error in loading configuration for email verification: " + - configFilename + "."; - log.error(msg, e); - return null; - } finally { - if (ip != null) { - try { - ip.close(); - } catch (IOException e) { - log.warn("Could not close InputStream for file " + configFile.getAbsolutePath()); - } - } - - } - } -} diff --git a/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/internal/EmailSenderServiceComponent.java b/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/internal/EmailSenderServiceComponent.java deleted file mode 100644 index 0667603664..0000000000 --- a/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/internal/EmailSenderServiceComponent.java +++ /dev/null @@ -1,83 +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.email.sender.internal; - -import org.apache.stratos.email.sender.util.Util; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.osgi.service.component.ComponentContext; -import org.wso2.carbon.registry.core.service.RegistryService; -import org.wso2.carbon.user.core.service.RealmService; -import org.wso2.carbon.utils.CarbonUtils; -import org.wso2.carbon.utils.ConfigurationContextService; - -/** - * @scr.component name="org.apache.stratos.email.sender" - * immediate="true" - * @scr.reference name="registry.service" - * interface="org.wso2.carbon.registry.core.service.RegistryService" cardinality="1..1" - * policy="dynamic" bind="setRegistryService" unbind="unsetRegistryService" - * @scr.reference name="user.realmservice.default" interface="org.wso2.carbon.user.core.service.RealmService" - * cardinality="1..1" policy="dynamic" bind="setRealmService" - * unbind="unsetRealmService" - * @scr.reference name="configuration.context.service" - * interface="org.wso2.carbon.utils.ConfigurationContextService" cardinality="1..1" - * policy="dynamic" bind="setConfigurationContextService" unbind="unsetConfigurationContextService" - */ -public class EmailSenderServiceComponent { - private static Log log = LogFactory.getLog(EmailSenderServiceComponent.class); - - protected void activate(ComponentContext context) { - try { - log.debug("******* Email Sender bundle is activated ******* "); - } catch (Exception e) { - log.error("******* Email Sender bundle failed activating ****", e); - } - } - - protected void deactivate(ComponentContext context) { - log.debug("******* Email Sender bundle is deactivated ******* "); - } - protected void setRegistryService(RegistryService registryService) { - Util.setRegistryService(registryService); - } - - protected void unsetRegistryService(RegistryService registryService) { - Util.setRegistryService(null); - } - - protected void setRealmService(RealmService realmService) { - Util.setRealmService(realmService); - } - - protected void unsetRealmService(RealmService realmService) { - Util.setRealmService(null); - } - - protected void setConfigurationContextService(ConfigurationContextService configurationContextService){ - log.debug("Receiving ConfigurationContext Service"); - Util.setConfigurationContextService(configurationContextService); - - } - - protected void unsetConfigurationContextService(ConfigurationContextService configurationContextService){ - log.debug("Unsetting ConfigurationContext Service"); - Util.setConfigurationContextService(null); - } -} diff --git a/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/util/Util.java b/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/util/Util.java deleted file mode 100644 index a16880dead..0000000000 --- a/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/util/Util.java +++ /dev/null @@ -1,106 +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.email.sender.util; - -import org.apache.axis2.context.ConfigurationContext; -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.api.RealmConfiguration; -import org.wso2.carbon.user.core.service.RealmService; -import org.wso2.carbon.user.core.tenant.TenantManager; -import org.wso2.carbon.utils.ConfigurationContextService; - -import java.util.Map; -import java.util.regex.Matcher; - -/** - * Utility methods for the email sender component - */ -public class Util { - - private static RegistryService registryService; - private static RealmService realmService; - private static ConfigurationContextService configurationContextService; - - - public static ConfigurationContextService getConfigurationContextService() { - return configurationContextService; - } - - public static void setConfigurationContextService( - ConfigurationContextService configurationContextService) { - Util.configurationContextService = configurationContextService; - } - - public static ConfigurationContext getConfigurationContext() { - if (configurationContextService.getServerConfigContext() == null) { - return null; - } - return configurationContextService.getServerConfigContext(); - } - - public static synchronized void setRegistryService(RegistryService service) { - if (registryService == null) { - registryService = service; - } - } - - public static RegistryService getRegistryService() { - return registryService; - } - - public static synchronized void setRealmService(RealmService service) { - if (realmService == null) { - realmService = service; - } - } - - public static RealmService getRealmService() { - return realmService; - } - - public static TenantManager getTenantManager() { - return realmService.getTenantManager(); - } - - public static RealmConfiguration getBootstrapRealmConfiguration() { - return realmService.getBootstrapRealmConfiguration(); - } - - public static UserRegistry getGovernanceSystemRegistry(int tenantId) throws RegistryException { - return registryService.getGovernanceSystemRegistry(tenantId); - } - - /** - * Replace the {place-holders} with the respective value provided - * @param text string - * @param userParameters - map of user parameters - * @return replaced text for the email {title or body} - */ - public static String replacePlaceHolders(String text, Map userParameters) { - if (userParameters != null) { - for (Map.Entry entry : userParameters.entrySet()) { - String key = entry.getKey(); - text = text.replaceAll("\\{" + key + "\\}", Matcher.quoteReplacement(entry.getValue())); - } - } - return text; - } -} diff --git a/components/org.apache.stratos.kubernetes.client/pom.xml b/components/org.apache.stratos.kubernetes.client/pom.xml index d65e7cd4df..091d6459a7 100644 --- a/components/org.apache.stratos.kubernetes.client/pom.xml +++ b/components/org.apache.stratos.kubernetes.client/pom.xml @@ -20,19 +20,17 @@ - + 4.0.0 org.apache.stratos stratos-components-parent - 4.1.1 + 4.1.2-SNAPSHOT - 4.0.0 org.apache.stratos.kubernetes.client bundle Apache Stratos - Kubernetes API Java Client A Java client library written for Kubernetes API - http://apache.org @@ -43,16 +41,18 @@ commons-logging commons-logging + 1.1.1 junit junit + ${junit.version} test org.apache.stratos kubernetes-api - ${kubernetes.api.stratos.version} + ${kubernetes.api.version} @@ -71,8 +71,8 @@ org.apache.stratos.kubernetes.client.exceptions, - io.fabric8.kubernetes.api.*;version=${kubernetes.api.stratos.version}, - io.fabric8.kubernetes.api.model.*;version=${kubernetes.api.stratos.version}, + io.fabric8.kubernetes.api.*;version=${kubernetes.api.version}, + io.fabric8.kubernetes.api.model.*;version=${kubernetes.api.version}, *;resolution:=optional * @@ -131,4 +131,4 @@ - + \ No newline at end of file diff --git a/components/org.apache.stratos.load.balancer.common/pom.xml b/components/org.apache.stratos.load.balancer.common/pom.xml index 77ddcbb58b..4a57e2a3ad 100644 --- a/components/org.apache.stratos.load.balancer.common/pom.xml +++ b/components/org.apache.stratos.load.balancer.common/pom.xml @@ -19,24 +19,22 @@ --> - + 4.0.0 org.apache.stratos stratos-components-parent - 4.1.1 + 4.1.2-SNAPSHOT - 4.0.0 org.apache.stratos.load.balancer.common bundle Apache Stratos - Load Balancer - Common - http://apache.org org.wso2.carbon org.wso2.carbon.core - ${wso2carbon.version} + ${carbon.kernel.version} junit @@ -46,7 +44,7 @@ org.wso2.carbon org.wso2.carbon.logging - ${wso2carbon.version} + ${carbon.kernel.version} org.apache.stratos @@ -66,12 +64,12 @@ org.wso2.carbon org.wso2.carbon.databridge.agent.thrift - ${wso2carbon.version} + ${carbon.kernel.version} org.wso2.carbon org.wso2.carbon.databridge.commons - ${wso2carbon.version} + ${carbon.kernel.version} @@ -107,4 +105,4 @@ - + \ No newline at end of file diff --git a/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/internal/LoadBalancerCommonServiceComponent.java b/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/internal/LoadBalancerCommonServiceComponent.java index e61e0e65eb..d4cc1e7166 100644 --- a/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/internal/LoadBalancerCommonServiceComponent.java +++ b/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/internal/LoadBalancerCommonServiceComponent.java @@ -35,11 +35,13 @@ public class LoadBalancerCommonServiceComponent { private static final Log log = LogFactory.getLog(LoadBalancerCommonServiceComponent.class); protected void activate(ComponentContext context) { + if (log.isDebugEnabled()) { + log.debug("Activating LoadBalancerCommonServiceComponent..."); + } try { - if (log.isDebugEnabled()) { - log.debug("Load Balancer Common Service bundle activated"); - } - } catch (Exception e) { + log.debug("Load Balancer Common Service bundle activated"); + } + catch (Exception e) { log.error("Could not activate Load Balancer Common Service bundle", e); } } diff --git a/components/org.apache.stratos.load.balancer.extension.api/pom.xml b/components/org.apache.stratos.load.balancer.extension.api/pom.xml index 8604405c8a..6710019793 100644 --- a/components/org.apache.stratos.load.balancer.extension.api/pom.xml +++ b/components/org.apache.stratos.load.balancer.extension.api/pom.xml @@ -17,34 +17,19 @@ ~ specific language governing permissions and limitations ~ under the License. --> - 4.0.0 - org.apache.stratos stratos-components-parent - 4.1.1 + 4.1.2-SNAPSHOT org.apache.stratos.load.balancer.extension.api Apache Stratos - Load Balancer - Extension API An extension API for integrating third party load balancers with Apache Stratos. - - - wso2-nexus - WSO2 internal Repository - http://maven.wso2.org/nexus/content/groups/wso2-public/ - - true - daily - ignore - - - - org.apache.stratos @@ -57,4 +42,4 @@ ${project.version} - + \ No newline at end of file diff --git a/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/internal/LoadBalancerExtensionAPIServiceComponent.java b/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/internal/LoadBalancerExtensionAPIServiceComponent.java index 10e0496733..61ddac3737 100644 --- a/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/internal/LoadBalancerExtensionAPIServiceComponent.java +++ b/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/internal/LoadBalancerExtensionAPIServiceComponent.java @@ -40,6 +40,9 @@ public class LoadBalancerExtensionAPIServiceComponent { * @param context component context */ protected void activate(ComponentContext context) { + if (log.isDebugEnabled()) { + log.debug("Activating LoadBalancerExtensionAPIServiceComponent..."); + } try { if (log.isDebugEnabled()) { log.debug("Load Balancer Extension API Service bundle activated"); diff --git a/components/org.apache.stratos.load.balancer/pom.xml b/components/org.apache.stratos.load.balancer/pom.xml index ef8aafed08..070d252da0 100644 --- a/components/org.apache.stratos.load.balancer/pom.xml +++ b/components/org.apache.stratos.load.balancer/pom.xml @@ -19,34 +19,27 @@ --> - + 4.0.0 org.apache.stratos stratos-components-parent - 4.1.1 + 4.1.2-SNAPSHOT - 4.0.0 org.apache.stratos.load.balancer bundle Apache Stratos - Load Balancer - http://apache.org org.wso2.carbon org.wso2.carbon.mediation.initializer - ${wso2carbon.version} + ${carbon.kernel.version} org.wso2.carbon org.wso2.carbon.mediation.dependency.mgt - ${wso2carbon.version} - - - org.apache.synapse - synapse-core - ${synapse.core.version} + ${carbon.kernel.version} org.apache.stratos @@ -62,7 +55,6 @@ - org.apache.felix maven-scr-plugin @@ -70,7 +62,6 @@ org.apache.felix maven-bundle-plugin - true @@ -92,4 +83,4 @@ - + \ No newline at end of file diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java index 4577735c9d..a7761cd022 100644 --- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java +++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java @@ -98,6 +98,9 @@ public class LoadBalancerServiceComponent { private LoadBalancerStatisticsNotifier statisticsNotifier; protected void activate(ComponentContext ctxt) { + if (log.isDebugEnabled()) { + log.debug("Activating LoadBalancerServiceComponent..."); + } try { ClusteringAgent clusteringAgent = ServiceReferenceHolder.getInstance().getAxisConfiguration().getClusteringAgent(); boolean clusteringEnabled = (clusteringAgent != null); diff --git a/components/org.apache.stratos.logging.view.ui/pom.xml b/components/org.apache.stratos.logging.view.ui/pom.xml deleted file mode 100644 index f721050328..0000000000 --- a/components/org.apache.stratos.logging.view.ui/pom.xml +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - - - org.apache.stratos - stratos-components-parent - 4.1.1 - - - 4.0.0 - org.apache.stratos.logging.view.ui - bundle - Apache Stratos - Logging View UI - http://apache.org - Log Viewer UI Bundle - - - - org.apache.felix - maven-bundle-plugin - - true - - - ${project.artifactId} - ${project.artifactId} - - org.apache.stratos.logging.view.ui.* - - - org.wso2.carbon.logging.view.stub.*; - version="${carbon.platform.package.import.version.range}", - *;resolution:=optional - - - UIBundle - - - - - - - - - org.wso2.carbon - org.wso2.carbon.ui - ${wso2carbon.version} - - - org.wso2.carbon - org.wso2.carbon.logging.view.stub - ${wso2carbon.version} - - - org.apache.stratos - org.apache.stratos.manager.service.stub - ${project.version} - - - diff --git a/components/org.apache.stratos.logging.view.ui/src/main/java/org/apache/stratos/logging/view/ui/LogViewerClient.java b/components/org.apache.stratos.logging.view.ui/src/main/java/org/apache/stratos/logging/view/ui/LogViewerClient.java deleted file mode 100644 index b46940d6ea..0000000000 --- a/components/org.apache.stratos.logging.view.ui/src/main/java/org/apache/stratos/logging/view/ui/LogViewerClient.java +++ /dev/null @@ -1,272 +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.logging.view.ui; - -import org.apache.axis2.AxisFault; -import org.apache.axis2.Constants; -import org.apache.axis2.client.Options; -import org.apache.axis2.client.ServiceClient; -import org.apache.axis2.context.ConfigurationContext; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.logging.view.stub.LogViewerLogViewerException; -import org.wso2.carbon.logging.view.stub.LogViewerStub; -import org.wso2.carbon.logging.view.stub.types.carbon.LogEvent; -import org.wso2.carbon.logging.view.stub.types.carbon.PaginatedLogEvent; -import org.wso2.carbon.logging.view.stub.types.carbon.PaginatedLogInfo; - -import javax.activation.DataHandler; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletResponse; -import java.io.InputStream; -import java.rmi.RemoteException; - -public class LogViewerClient { - private static final Log log = LogFactory.getLog(LogViewerClient.class); - public LogViewerStub stub; - - public LogViewerClient(String cookie, String backendServerURL, ConfigurationContext configCtx) - throws AxisFault { - String serviceURL = backendServerURL + "LogViewer"; - - stub = new LogViewerStub(configCtx, serviceURL); - ServiceClient client = stub._getServiceClient(); - Options option = client.getOptions(); - option.setManageSession(true); - option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie); - option.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE); - } - - - public void cleaLogs() throws Exception { - stub.clearLogs(); - } - - public void downloadArchivedLogFiles(String logFile, HttpServletResponse response, String domain, String serverKey) - throws Exception { - try { - logFile = logFile.replace(".gz", ""); - ServletOutputStream outputStream = response.getOutputStream(); - response.setContentType("application/txt"); - response.setHeader("Content-Disposition", - "attachment;filename=" + logFile.replaceAll("\\s", "_")); - DataHandler data = stub.downloadArchivedLogFiles(logFile, domain, serverKey); - InputStream fileToDownload = data.getInputStream(); - int c; - while ((c = fileToDownload.read()) != -1) { - outputStream.write(c); - } - outputStream.flush(); - outputStream.flush(); - } catch (Exception e) { - String msg = "Error occurred while getting logger data. Backend service may be unavailable"; - log.error(msg, e); - throw e; - } - } - - public int getLineNumbers(String logFile) - throws Exception { - try { - return stub.getLineNumbers(logFile); - } catch (RemoteException e) { - String msg = "Error occurred while getting logger data. Backend service may be unavailable"; - log.error(msg, e); - throw e; - } - } - - public PaginatedLogInfo getPaginatedLogInfo(int pageNumber, String tenantDomain, - String serviceName) throws Exception { - try { - return stub.getPaginatedLogInfo(pageNumber, tenantDomain, serviceName); - } catch (RemoteException e) { - String msg = "Error occurred while getting logger data. Backend service may be unavailable"; - log.error(msg, e); - throw e; - } - } - - public LogEvent[] getLogs(String type, String keyword, String domain, String serverkey) throws Exception { - if (type == null || type.equals("")) { - type = "ALL"; - } - try { - return stub.getLogs(type, keyword, domain, serverkey); - } catch (RemoteException e) { - String msg = "Error occurred while getting logger data. Backend service may be unavailable"; - log.error(msg, e); - throw e; - } - } - - public LogEvent[] getApplicationLogs(String type, String keyword, String applicationName, String domain, String serverKey) - throws Exception { - if (type == null || type.equals("")) { - type = "ALL"; - } - if (applicationName == null || applicationName.equals("")) { - applicationName = "FIRST"; - } - try { - return stub.getApplicationLogs(type, keyword, applicationName, domain, serverKey); - } catch (RemoteException e) { - String msg = "Error occurred while getting logger data. Backend service may be unavailable"; - log.error(msg, e); - throw e; - } - } - - public String[] getLogLinesFromFile(String logFile, int maxLogs, int start, int end) throws Exception { - try { - return stub.getLogLinesFromFile(logFile, maxLogs, start, end); - } catch (RemoteException e) { - String msg = "Error occurred while getting logger data. Backend service may be unavailable"; - log.error(msg, e); - throw e; - } - } - - /*public String[] getSubscribedCartridgeList() throws Exception { - try { - return appMgtStub.getSubscribedCartridgeAliases(); - } catch (RemoteException e) { - String msg = "Error occurred while getting logger data. Backend service may be unavailable"; - log.error(msg, e); - throw e; - } - }*/ - - public String[] getApplicationNames(String domain, String serverKey) throws LogViewerLogViewerException, RemoteException { - try { - return stub.getApplicationNames(domain, serverKey); - } catch (RemoteException e) { - String msg = "Error occurred while getting logger data. Backend service may be unavailable"; - log.error(msg, e); - throw e; - } - } - - public int getNoOfLogEvents() throws Exception { - try { - return 20;// stub.getNoOfLogEvents(); - } catch (Exception e) { - String msg = "Error occurred while getting logger data. Backend service may be unavailable"; - log.error(msg, e); - throw e; - } - } - - public String[] getServiceNames() throws RemoteException, LogViewerLogViewerException { - try { - return stub.getServiceNames(); - } catch (RemoteException e) { - String msg = "Error occurred while getting logger data. Backend service may be unavailable"; - log.error(msg, e); - throw e; - } - } - - public boolean isFileAppenderConfiguredForST() throws RemoteException { - try { - return stub.isFileAppenderConfiguredForST(); - } catch (RemoteException e) { - String msg = "Error occurred while getting logger data. Backend service may be unavailable"; - log.error(msg, e); - throw e; - } - } - - public PaginatedLogEvent getPaginatedLogEvents(int pageNumber, String type, String keyword, String domain, String serverKey) - throws Exception { - try { - return stub.getPaginatedLogEvents(pageNumber, type, keyword, domain, serverKey); - } catch (RemoteException e) { - String msg = "Error occurred while getting logger data. Backend service may be unavailable"; - log.error(msg, e); - throw e; - } - } - - public PaginatedLogEvent getPaginatedApplicationLogEvents(int pageNumber, String type, - String keyword, String appName, String domain, String serverKey) throws Exception { - try { - return stub.getPaginatedApplicationLogEvents(pageNumber, type, keyword, appName, domain, serverKey); - } catch (RemoteException e) { - String msg = "Error occurred while getting logger data. Backend service may be unavailable"; - log.error(msg, e); - throw e; - } - } - - public PaginatedLogInfo getLocalLogFiles(int pageNo, String domain, String serverKey) throws Exception { - - try { - return stub.getLocalLogFiles(pageNo, domain, serverKey); - } catch (Exception e) { - String msg = "Error occurred while getting logger data. Backend service may be unavailable"; - log.error(msg, e); - throw e; - } - - } - - public boolean isLogEventReciverConfigured() throws RemoteException { - try { - return stub.isLogEventReciverConfigured(); - } catch (RemoteException e) { - String msg = "Error occurred while getting logger data. Backend service may be unavailable"; - log.error(msg, e); - throw e; - } - } - - public String getImageName(String type) { - if (type.equals("INFO")) { - return "images/information.gif"; - } else if (type.equals("ERROR")) { - return "images/error.png"; - } else if (type.equals("WARN")) { - return "images/warn.png"; - } else if (type.equals("DEBUG")) { - return "images/debug.png"; - } else if (type.equals("TRACE")) { - return "images/trace.png"; - } else if (type.equals("FATAL")) { - return "images/fatal.png"; - } - return ""; - } - - public String[] getLogLevels() { - return new String[]{"ALL", "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE"}; - } - - public boolean isManager() throws RemoteException { - return stub.isManager(); - } - - public boolean isValidTenant(String domain) throws RemoteException { - return stub.isValidTenant(domain); - - } - -} - diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/META-INF/component.xml b/components/org.apache.stratos.logging.view.ui/src/main/resources/META-INF/component.xml deleted file mode 100644 index 5ce1b1588a..0000000000 --- a/components/org.apache.stratos.logging.view.ui/src/main/resources/META-INF/component.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - -

- logs_menu - logsmenutext - org.apache.stratos.logging.view.ui.i18n.Resources - monitor_menu - ../log-view/index.jsp - region4 - 10 - monitor - ../log-view/images/script_gear.gif - /permission/admin/monitor/logging - - - - app_log_menu - applogsmenutext - org.apache.stratos.logging.view.ui.i18n.Resources - monitor_menu - ../log-view/application_log_viewer.jsp - region4 - 3 - monitor - ../log-view/images/script_gear.gif - /permission/admin/monitor/logging - - - - diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/org/apache/stratos/logging/view/ui/i18n/Resources.properties b/components/org.apache.stratos.logging.view.ui/src/main/resources/org/apache/stratos/logging/view/ui/i18n/Resources.properties deleted file mode 100644 index 7d3bf24429..0000000000 --- a/components/org.apache.stratos.logging.view.ui/src/main/resources/org/apache/stratos/logging/view/ui/i18n/Resources.properties +++ /dev/null @@ -1,66 +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. -# -# - -archived.logs=Show archived logs -adv.search=Show advanced search -max.exceed.message=Maximum Number of Log Retrieval for the Day Exceeded... Your latest logs will be omitted. -logsmenutext=System Logs -applogsmenutext=Application Logs -viewlogsmenutext=View Logs text -system.logs=System Logs -app.logs=Application Logs -system.logs.view = System Log View -view=View -download=Download -search.logs=Search Logs -file.size = File Size -clear.all=Clear All Logs -clear.all.log.message=Do you want to clear all the logs -no.logs=--- No log entries found. --- -invalid.tenant= --- Invalid tenant domain --- -file.name = File Name -date = Date -action = Action -log.tail = Log Tail -service.name = Subscribed Cartridge Aliases -log.head = Log Head -log.message = Log Message -log.type = Type -local.log.location.information = Logs are taken from the local file system. -remote.log.location.information = Logs are taken from the remote log hosted server. -log.head.help = Enter the number of log lines to be displayed from the top-down. -tenant.domain = Tenant Domain -return.rows = Return Rows -show.at.or.before = Show at or Between -advanced.properties = Advanced Properties -priority = Priority -keyword = Keyword -logger = Logger -application.name=Application Name -filter.system.logs=Filter System Logs -date.format=mm/dd/yyyy hh:mm -date.example=(eg 2012-05-18 06:21:39) -view.stack.trace=More -view.logs.within.the.past.thirty.mins=Logs taken within past thirty minutes. -view.logs.between=Logs taken between. -log.level=Level -current.time=Current Time Zone: - diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/application_log_viewer.jsp b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/application_log_viewer.jsp deleted file mode 100644 index 592c8d793c..0000000000 --- a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/application_log_viewer.jsp +++ /dev/null @@ -1,376 +0,0 @@ - -<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" - prefix="carbon" %> -<%@ page import="org.apache.stratos.logging.view.ui.LogViewerClient" %> -<%@ page import="org.apache.axis2.context.ConfigurationContext" %> -<%@ page import="org.wso2.carbon.CarbonConstants" %> -<%-- <%@ page --%> - -<%@ page import="org.wso2.carbon.utils.ServerConstants" %> -<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %> -<%@ page import="org.wso2.carbon.logging.view.stub.types.carbon.PaginatedLogEvent" %> -<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %> -<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %> -<%@ page import="org.wso2.carbon.ui.util.CharacterEncoder" %> -<%@ page import="org.wso2.carbon.logging.view.stub.types.carbon.LogEvent" %> -<%@ page import="java.text.SimpleDateFormat" %> - - - - - - - - - - View Application Logs - - - -<% - String backendServerURL = CarbonUIUtil - .getServerURL(config.getServletContext(), session); - ConfigurationContext configContext = (ConfigurationContext) config.getServletContext() - .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT); - String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE); - LogViewerClient logViewerClient; - LogEvent[] events = null; - String type; - String keyword; - String action; - String pageNumberStr = request.getParameter("pageNumber"); - int pageNumber = 0; - int numberOfPages = 0; - PaginatedLogEvent paginatedLogEvents = null; - String parameter = ""; - boolean isSuperTenant = CarbonUIUtil.isSuperTenant(request); - boolean isManager = false; - String tenantDomain = request.getParameter("tenantDomain"); - String serviceName = request.getParameter("serviceName"); - String showMaxStr = request.getParameter("showMax"); - String serviceNames[]; - boolean isValidTenant = true; - boolean showMax = false; - showMax = Boolean.parseBoolean(showMaxStr); - try { - pageNumber = Integer.parseInt(pageNumberStr); - } catch (NumberFormatException ignored) { - // page number format exception - } - String appName; - String applicationNames[] = null; - try { - type = CharacterEncoder.getSafeText(request.getParameter("type")); - type = (type == null) ? "" : type; - keyword = CharacterEncoder.getSafeText(request.getParameter("keyword")); - keyword = (keyword == null) ? "" : keyword; - action = CharacterEncoder.getSafeText(request.getParameter("action")); - appName = request.getParameter("appName"); - logViewerClient = new LogViewerClient(cookie, backendServerURL, configContext); - isValidTenant = logViewerClient.isValidTenant(tenantDomain); - if (tenantDomain == null) { - tenantDomain = ""; - } - if (serviceName == null) { - serviceName = ""; - } - if (isValidTenant) { - applicationNames = logViewerClient.getApplicationNames(tenantDomain, serviceName); - if (appName == null && applicationNames != null && applicationNames.length > 0) { - appName = applicationNames[0]; - } - if (applicationNames == null) { - applicationNames = new String[]{"No applications"}; - appName = applicationNames[0]; - } else if (applicationNames != null && applicationNames.length == 0) { - applicationNames = new String[]{"No applications"}; - appName = applicationNames[0]; - } - paginatedLogEvents = logViewerClient.getPaginatedApplicationLogEvents(pageNumber, type, keyword, appName, tenantDomain, serviceName); - } - if (applicationNames == null) { - applicationNames = new String[]{"No applications"}; - appName = applicationNames[0]; - } - isManager = logViewerClient.isManager(); - serviceNames = logViewerClient.getServiceNames(); - if (paginatedLogEvents != null) { - events = paginatedLogEvents.getLogInfo(); - numberOfPages = paginatedLogEvents.getNumberOfPages(); - } - - parameter = "type=" + type + "&keyword=" + keyword + "&appName=" + appName; - } catch (Exception e) { - CarbonUIMessage.sendCarbonUIMessage(e.getMessage(), CarbonUIMessage.ERROR, request, - e); -%> - -<% - return; - } -%> - - - -
-

- -

- -
- - - - - - - - -
- - - - - - - - - - - - - - - <% - SimpleDateFormat dateFormat = new SimpleDateFormat("Z"); - String date = dateFormat.format(System.currentTimeMillis()); - %> - - -
- - - - - - - - - - - - - - - - - <%= "GMT " + date%> -
-
- - -
- - - - - - - - -
- - - - <% - if (!isValidTenant) { %> - - - <% - } else { - - - if (events == null || events.length == 0 || events[0] == null) { - %> - - <% - } else { - int index = 0; - for (LogEvent logMessage : events) { - index++; - if (index % 2 != 0) { - %> - - - - - - - - - <% - } else { - %> - - - <% - } - %> - - - - <% - String imgId = "traceSymbolMax" + index; - %> - - - - <% - String id = "traceTable" + index; - if (index % 2 != 0) { - %> - - <% - } else { - %> - - - <% - } - %> - - - - <% - } - } - } - %> - -
- - - - - -
- - <%=logMessage.getLogTime()%> - - <%=CharacterEncoder.getSafeText(logMessage.getMessage())%> -
- -
- - - -
-
-
- - \ No newline at end of file diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/cassandra_log_viewer.jsp b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/cassandra_log_viewer.jsp deleted file mode 100644 index 5f44c0d122..0000000000 --- a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/cassandra_log_viewer.jsp +++ /dev/null @@ -1,482 +0,0 @@ - -<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" - prefix="carbon" %> -<%@ page import="org.apache.stratos.logging.view.ui.LogViewerClient" %> -<%@ page import="org.apache.axis2.context.ConfigurationContext" %> -<%@ page import="org.wso2.carbon.CarbonConstants" %> -<%-- <%@ page --%> - -<%@ page import="org.wso2.carbon.utils.ServerConstants" %> -<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %> - -<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %> -<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %> -<%@ page import="org.wso2.carbon.logging.view.stub.types.carbon.LogEvent" %> - - - - - - - - - View System Logs - - -<% - String backendServerURL = CarbonUIUtil - .getServerURL(config.getServletContext(), session); - ConfigurationContext configContext = (ConfigurationContext) config.getServletContext() - .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT); - String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE); - LogViewerClient logViewerClient; - LogEvent[] events; - String tenantDomain = ""; - String serviceName = "WSO2 Stratos Manager"; - boolean isLogsFromSyslog; - boolean isSTSyslog = false; - String serviceNames[]; - boolean isManager = false; - boolean showManager = false; - String logIndex = request.getParameter("logIndex"); - String start = request.getParameter("start"); - - String end = request.getParameter("end"); - boolean showTenantDomain = false; - boolean isStratosService = false; - tenantDomain = request.getParameter("tenantDomain"); - serviceName = request.getParameter("serviceName"); - Boolean isDateGiven = false; - String priority = request.getParameter("priority"); - String logger = request.getParameter("logger"); - String keyWord = request.getParameter("keyword"); -// LogEvent logs[]; - if (start != null && !start.equals("null") && !start.equals("")) { - isDateGiven = true; - } - int returnRows; - logIndex = (logIndex == null) ? "20" : logIndex; - tenantDomain = (tenantDomain == null) ? "" : tenantDomain; - start = (start == null) ? "" : start; - end = (end == null) ? "" : end; - priority = (priority == null) ? "ALL" : priority; - keyWord = (keyWord == null) ? "" : keyWord; - logger = (logger == null) ? "" : logger; - try { - returnRows = (logIndex == null) ? 20 : Integer.parseInt(logIndex); - logViewerClient = new LogViewerClient(cookie, backendServerURL, configContext); - isLogsFromSyslog = logViewerClient.isDataFromSysLog(tenantDomain); - isSTSyslog = logViewerClient.isSTSyslogConfig(tenantDomain); - isManager = logViewerClient.isManager(); - serviceNames = logViewerClient.getServiceNames(); - ; - serviceName = (serviceName == null) ? "WSO2 Stratos Manager" : serviceName; - tenantDomain = (tenantDomain == null) ? "" : tenantDomain; - isStratosService = logViewerClient.isStratosService(); - showTenantDomain = (isSTSyslog && isLogsFromSyslog && isStratosService); - showManager = (isManager && isLogsFromSyslog); - events = logViewerClient.getSystemLogs(start, end, - logger, priority, "", serviceName, "", Integer.parseInt(logIndex)); - System.out.println("events " + events); - System.out.println("Return Rows " + logIndex); - System.out.println("isDateGiven " + isDateGiven); - System.out.println("start " + start + " : " + start); - System.out.println("end " + end + " : " + end); - System.out.println("Priority " + priority); - System.out.println("Logger " + logger); - System.out.println("Keyword " + keyWord); - - System.out.println(); - System.out.println(); - - // logs = logViewerClient.getAllLogs(); - } catch (Exception e) { - CarbonUIMessage.sendCarbonUIMessage(e.getMessage(), CarbonUIMessage.ERROR, request, - e); -%> - -<% - return; - } -%> - - - -
-

- -

- -
- - <% - if (showTenantDomain || showManager) { - %>

- - - - - - -
- - - - <% - if (showTenantDomain) { - %> - - - - - - <% - } else { - %> - - <% - } - if (showManager) { - %> - - - - - - - <% - } else { - %> - - <% - } - %> - - - -
- - - - - - - - -
-
-

- <% - } - %> - - - - - - - - - -
- <%-- - <%-- page="view.jsp" pageNumberParameterName="pageNumber" parameters="<%=parameter%>"/> --%> - <% - if (!isDateGiven) { - %> - - - <% - } else { - %> - <%=start%> and <%=end%> - - <% - } - %>
-
-
- - - - - - - - - - - - - -
- - - - - - - - - - - - - -
- -
- - - - - <% - if (!isDateGiven) { - %> Now
- "> -
-
<% - } else { - - %> - Now
- " checked> - -
-
<% - - } - %> -
-
-
-
- - - - - - <%-- - <%-- page="view.jsp" pageNumberParameterName="pageNumber" parameters="<%=parameter%>"/> --%> - - -
- - - - - - - - - - <% - if (events == null || events.length == 0 || events[0] == null) {%> - - <% - } else { - int index = 0; - for (LogEvent logMessage : events) { - index++; - if (index % 2 != 0) { - %> - - <% - } else { - %> - - - <% - }%> - - - - <%String imgId = "traceSymbolMax" + index; %> - - - - <% - String id = "traceTable" + index; - if (index % 2 != 0) { - %> - - <% - } else { - %> - - - <% - }%> - - - - <% - } - } - %> - -
- - - - - -
- - <%=logMessage.getLogTime()%> - - <%=logMessage.getMessage()%> -
-
- - - -
-
-
- - \ No newline at end of file diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/docs/images/application.jpg b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/docs/images/application.jpg deleted file mode 100755 index 735ec242de..0000000000 Binary files a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/docs/images/application.jpg and /dev/null differ diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/docs/images/log.jpg b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/docs/images/log.jpg deleted file mode 100644 index 9470e10805..0000000000 Binary files a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/docs/images/log.jpg and /dev/null differ diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/docs/images/logIndex.jpg b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/docs/images/logIndex.jpg deleted file mode 100755 index 4741e7d850..0000000000 Binary files a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/docs/images/logIndex.jpg and /dev/null differ diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/docs/images/logview.jpg b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/docs/images/logview.jpg deleted file mode 100755 index bc9dc75090..0000000000 Binary files a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/docs/images/logview.jpg and /dev/null differ diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/docs/userguide.html b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/docs/userguide.html deleted file mode 100644 index 41a9a3c101..0000000000 --- a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/docs/userguide.html +++ /dev/null @@ -1,90 +0,0 @@ - - - - - - Monitor Logs - User Guide - - - - -

Monitor Logs

- -

Logs can be displayed as System logs or application logs.System Logs shows the log events of the system logs - depending on the product. Application logs filter logs by the application, it can be services or web applications. - There are two ways to configure system logs, 1) through Memory Appender where logs will be taken from the memory, 2) - BAMLogEventAppender where logs will be published to bam and log events will be taken from BAM storages. Only the - latest daily logs messages will be displayed in the UI where the logs events can be filtered accordingly. Log events - are archived daily per tenant per product per date and can be downloaded for further analysis. -

- -

The log messages, displayed in this page are obtained from a memory appender. Hence, the severity(log level) of the - displayed log messages are equal or higher than the threshold of the memory appender. For more information on - appenders, loggers and their log levels, please visit here.

- -

Log files on disk

- -

The location of the log files on disk is specified in the log4j.configuration file.

- -

View Logs

- -

This log events are displayed from bottom-up manner. You can also search for a - particular log by a keyword using the Search Logs - feature.

-
    -
  1. In the navigator, under Monitor, click Logs. The System Logs/Application Logs page - appears.  -
  2. - -
  3. In the View list, select the - category of logs you want to view. The available categories are, -
  4. -
- -
- INFO  - Information messages - WARN  - Warning messages - ERROR  - Error messages - DEBUG  - Debug messages - TRACE  - Trace messages - FATAL - Fatal error messages -
-
    -
- -

- -

Figure 1: Monitor Logs

- -

- -

Figure 2: Archived Logs

- -

To filter out application specific logs, go to Monitor -> Application Logs. This will display application specific - logs.

- - -

- -

Figure 3: Application Logs

- - diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/download-ajaxprocessor.jsp b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/download-ajaxprocessor.jsp deleted file mode 100755 index 1faff1c673..0000000000 --- a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/download-ajaxprocessor.jsp +++ /dev/null @@ -1,88 +0,0 @@ - - -<%@page import="java.io.OutputStreamWriter" %> -<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %> -<%@ page import="org.apache.stratos.logging.view.ui.LogViewerClient" %> -<%@ page import="org.apache.axis2.context.ConfigurationContext" %> -<%@ page import="org.wso2.carbon.CarbonConstants" %> -<%@ page import="org.wso2.carbon.utils.ServerConstants" %> -<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %> -<%@ page import="org.wso2.carbon.utils.CarbonUtils" %> -<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %> - - - -<% - String backendServerURL = CarbonUIUtil - .getServerURL(config.getServletContext(), session); - ConfigurationContext configContext = (ConfigurationContext) config.getServletContext() - .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT); - String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE); - LogViewerClient logViewerClient; - String message = ""; - String tenantDomain = ""; - String serviceName = "WSO2 Stratos Manager"; - String downloadFile = request.getParameter("logFile"); - try { - out.clear(); - out = pageContext.pushBody(); - out.clearBuffer(); - ServletOutputStream outputStream = response.getOutputStream(); - response.setContentType("application/txt"); - response.setHeader("Content-Disposition", "attachment;filename=" + downloadFile.replaceAll("\\s", "_")); - logViewerClient = new LogViewerClient(cookie, backendServerURL, configContext); - OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream); - tenantDomain = request.getParameter("tenantDomain"); - serviceName = request.getParameter("serviceName"); - tenantDomain = (tenantDomain == null) ? "" : tenantDomain; - serviceName = (serviceName == null) ? "WSO2 Stratos Manager" : serviceName; - int fileSize = logViewerClient.getLineNumbers(downloadFile) + 1; - System.out.println("fileSize " + fileSize); - int pages = (int) Math.ceil((double) fileSize / 2000); - - for (int i = 0; i < pages; i++) { - int start = (i * 2000) + 1; - int end = start + 2000; - String logIndex = Integer.toString(fileSize); - String logs[] = logViewerClient.getLogLinesFromFile(downloadFile, fileSize, - start, end); - for (String logMessage : logs) { - outputStreamWriter.write(logMessage + "\n"); - } - - } - outputStreamWriter.flush(); - outputStream.flush(); - out.flush(); - outputStreamWriter.close(); - outputStream.close(); - out.close(); - } catch (Exception e) { - CarbonUIMessage.sendCarbonUIMessage(e.getMessage(), CarbonUIMessage.ERROR, request, - e); -%> - -<% - return; - } -%> diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/downloadgz-ajaxprocessor.jsp b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/downloadgz-ajaxprocessor.jsp deleted file mode 100755 index 26bfee86a7..0000000000 --- a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/downloadgz-ajaxprocessor.jsp +++ /dev/null @@ -1,69 +0,0 @@ - - -<%@page import="java.io.OutputStreamWriter" %> -<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %> -<%@ page import="org.apache.stratos.logging.view.ui.LogViewerClient" %> -<%@ page import="org.apache.axis2.context.ConfigurationContext" %> -<%@ page import="org.wso2.carbon.CarbonConstants" %> -<%@ page import="org.wso2.carbon.utils.ServerConstants" %> -<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %> -<%@ page import="org.wso2.carbon.utils.CarbonUtils" %> -<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %> - - - -<% - String backendServerURL = CarbonUIUtil - .getServerURL(config.getServletContext(), session); - ConfigurationContext configContext = (ConfigurationContext) config.getServletContext() - .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT); - String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE); - LogViewerClient logViewerClient; - String message = ""; - String tenantDomain = ""; - String serviceName = "WSO2 Stratos Manager"; - String downloadFile = request.getParameter("logFile"); - String fileName = downloadFile; - //String fileName = downloadFile.replace(".gz",""); - try { - out.clear(); - out = pageContext.pushBody(); - out.clearBuffer(); - tenantDomain = request.getParameter("tenantDomain"); - serviceName = request.getParameter("serviceName"); - tenantDomain = (tenantDomain == null) ? "" : tenantDomain; - serviceName = (serviceName == null) ? "WSO2 Stratos Manager" : serviceName; - logViewerClient = new LogViewerClient(cookie, backendServerURL, configContext); - logViewerClient.downloadArchivedLogFiles(fileName, response, tenantDomain, serviceName); - - //out.flush(); - // out.close(); - } catch (Exception e) { - CarbonUIMessage.sendCarbonUIMessage(e.getMessage(), CarbonUIMessage.ERROR, request, - e); -%> - -<% - return; - } -%> diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/cancel.gif b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/cancel.gif deleted file mode 100644 index f74130eb22..0000000000 Binary files a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/cancel.gif and /dev/null differ diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/collapse.gif b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/collapse.gif deleted file mode 100644 index 83d7fd23ad..0000000000 Binary files a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/collapse.gif and /dev/null differ diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/debug.png b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/debug.png deleted file mode 100644 index 273fd49ee4..0000000000 Binary files a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/debug.png and /dev/null differ diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/download.gif b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/download.gif deleted file mode 100755 index d88c9b4527..0000000000 Binary files a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/download.gif and /dev/null differ diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/error.png b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/error.png deleted file mode 100644 index 59558a5830..0000000000 Binary files a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/error.png and /dev/null differ diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/expand.gif b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/expand.gif deleted file mode 100644 index 116e12047f..0000000000 Binary files a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/expand.gif and /dev/null differ diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/fatal.png b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/fatal.png deleted file mode 100644 index 9a099668b9..0000000000 Binary files a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/fatal.png and /dev/null differ diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/information.gif b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/information.gif deleted file mode 100644 index a9c63b1715..0000000000 Binary files a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/information.gif and /dev/null differ diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/magnifier.gif b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/magnifier.gif deleted file mode 100644 index 86f81ed357..0000000000 Binary files a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/magnifier.gif and /dev/null differ diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/minus.gif b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/minus.gif deleted file mode 100755 index 8ff04bc41c..0000000000 Binary files a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/minus.gif and /dev/null differ diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/plus.gif b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/plus.gif deleted file mode 100755 index 1a0e2c9aa0..0000000000 Binary files a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/plus.gif and /dev/null differ diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/script_gear.gif b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/script_gear.gif deleted file mode 100644 index dc4174a2ac..0000000000 Binary files a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/script_gear.gif and /dev/null differ diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/search.gif b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/search.gif deleted file mode 100644 index 86f81ed357..0000000000 Binary files a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/search.gif and /dev/null differ diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/trace.png b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/trace.png deleted file mode 100644 index 64e7412431..0000000000 Binary files a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/trace.png and /dev/null differ diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/view.gif b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/view.gif deleted file mode 100755 index 9a1c6e2330..0000000000 Binary files a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/view.gif and /dev/null differ diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/warn.png b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/warn.png deleted file mode 100644 index be22d38ffc..0000000000 Binary files a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/images/warn.png and /dev/null differ diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/index.jsp b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/index.jsp deleted file mode 100644 index 23545fc0e1..0000000000 --- a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/index.jsp +++ /dev/null @@ -1,671 +0,0 @@ - -<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" - prefix="carbon" %> -<%@ page import="org.apache.stratos.logging.view.ui.LogViewerClient" %> -<%@ page import="org.apache.axis2.context.ConfigurationContext" %> -<%@ page import="org.wso2.carbon.CarbonConstants" %> -<%@ page import="org.wso2.carbon.logging.view.stub.types.carbon.LogInfo" %> -<%-- <%@ page --%> - -<%@ page import="org.wso2.carbon.utils.ServerConstants" %> -<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %> - -<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %> -<%@ page import="org.wso2.carbon.logging.view.stub.types.carbon.PaginatedLogInfo" %> -<%@ page import="org.wso2.carbon.logging.view.stub.types.carbon.PaginatedLogEvent" %> - -<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %> -<%@ page import="org.wso2.carbon.ui.util.CharacterEncoder" %> -<%@ page import="org.wso2.carbon.logging.view.stub.types.carbon.LogEvent" %> -<%@ page import="java.util.regex.Matcher" %> -<%@ page import="java.util.regex.Pattern" %> -<%@ page import="java.text.SimpleDateFormat" %> -<%@ page import="java.util.Calendar" %> -<%@ page import="java.util.Date" %> -<%@ page import="java.util.TimeZone" %> - - - - - - - - - View System Logs - - - -<%! - private boolean isArchiveFile(String fileName) { - String archivePattern = "[a-zA-Z]*\\.log"; - CharSequence inputStr = fileName; - Pattern pattern = Pattern.compile(archivePattern); - Matcher matcher = pattern.matcher(inputStr); - return matcher.find(); - } -%> -<% - String backendServerURL = CarbonUIUtil - .getServerURL(config.getServletContext(), session); - ConfigurationContext configContext = (ConfigurationContext) config.getServletContext() - .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT); - String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE); - LogViewerClient logViewerClient; - LogEvent[] events = null; - String type; - String keyword; - String action; - boolean showLogFiles; - String pageNumberStr = request.getParameter("pageNumber"); - String pageIndexNumberStr = request.getParameter("pageIndexNumber"); - String showMaxStr = request.getParameter("showMax"); - int pageNumber = 0; - int pageIndexNumber = 0; - int numberOfIndexPages = 0; - int numberOfPages = 0; - int noOfRows = 0; - boolean showMax = false; - boolean isSuperTenant = CarbonUIUtil.isSuperTenant(request); - boolean isManager = false; - String tenantDomain = request.getParameter("tenantDomain"); - String serviceName = request.getParameter("serviceName"); - String serviceNames[]; - LogInfo[] logInfo = null; - PaginatedLogInfo paginatedLogInfo = null; - PaginatedLogEvent paginatedLogEvents = null; - String parameter = ""; - String indexParameter = ""; - boolean isValidTenant = true; - String collapseAdv = request.getParameter("collapse"); - boolean isCollapse = Boolean.parseBoolean(collapseAdv); - showMax = Boolean.parseBoolean(showMaxStr); - try { - pageNumber = Integer.parseInt(pageNumberStr); - } catch (NumberFormatException ignored) { - // page number format exception - } - try { - pageIndexNumber = Integer.parseInt(pageIndexNumberStr); - } catch (NumberFormatException ignored) { - // page number format exception - } - try { - type = CharacterEncoder.getSafeText(request.getParameter("type")); - type = (type == null) ? "" : type; - if (tenantDomain == null) { - tenantDomain = ""; - } - if (serviceName == null) { - serviceName = ""; - } - //tenantDomain = (tenantDomain == null) ? "" : tenantDomain; - keyword = CharacterEncoder.getSafeText(request.getParameter("keyword")); - keyword = (keyword == null) ? "" : keyword; - action = CharacterEncoder.getSafeText(request.getParameter("action")); - logViewerClient = new LogViewerClient(cookie, backendServerURL, configContext); - isValidTenant = logViewerClient.isValidTenant(tenantDomain); - if (isValidTenant) { - paginatedLogEvents = logViewerClient.getPaginatedLogEvents(pageNumber, type, - keyword, tenantDomain, serviceName); - paginatedLogInfo = logViewerClient.getLocalLogFiles(pageIndexNumber, tenantDomain, serviceName); - } - - if (paginatedLogEvents != null) { - noOfRows = paginatedLogEvents.getNumberOfPages() * 15; - events = paginatedLogEvents.getLogInfo(); - numberOfPages = paginatedLogEvents.getNumberOfPages(); - } - if (paginatedLogInfo != null) { - logInfo = paginatedLogInfo.getLogInfo(); - numberOfIndexPages = paginatedLogInfo.getNumberOfPages(); - } - isManager = logViewerClient.isManager(); - if (isManager) { - serviceNames = logViewerClient.getServiceNames(); - } else { - serviceNames = logViewerClient.getServiceNames(); - } - showLogFiles = (logInfo != null); - if (isManager) { - if (isSuperTenant) { - parameter = "type=" + type + "&keyword=" + keyword + "&serviceName=" + serviceName + - "&tenantDomain=" + tenantDomain + "&collapse=" + isCollapse; - indexParameter = "type=" + type + "&keyword=" + keyword + "&showMax=" + true + "&serviceName=" + serviceName + - "&tenantDomain=" + tenantDomain + "&collapse=" + isCollapse; - } else { - parameter = "type=" + type + "&keyword=" + keyword + "&serviceName=" + serviceName + - "&collapse=" + isCollapse; - indexParameter = "type=" + type + "&keyword=" + keyword + "&showMax=" + true + "&serviceName=" + serviceName + - "&collapse=" + isCollapse; - } - } else { - parameter = "type=" + type + "&keyword=" + keyword; - indexParameter = "type=" + type + "&keyword=" + keyword + "&showMax=" + true; - } - - } catch (Exception e) { - CarbonUIMessage.sendCarbonUIMessage(e.getMessage(), CarbonUIMessage.ERROR, request, - e); -%> - -<% - return; - } -%> - - - -
-

- -

- -
- - <% - if (isManager) { - %> - - - - - - <% - if (isCollapse) { - %> - - - - - <% - } else { - %> - - - - <% - } - %> - - - - - - -
- <% - } else { - %> - - - - <% - } - - if (noOfRows > 40000) { - %> -
- Maximum log limit exceeded!!!.
- - We only list 40 000 logs through the log viewer(your latest logs will be omitted in the log display), - Please download the daily archived logs, for the full log report. -

- <% - } - %> -
- - - - - - -
- - - - - - <% - if (isManager && isSuperTenant) { - %> - - - - <% - } else if (isManager && !isSuperTenant) { - - %> - - - - <% - } else if (!isManager) { - %> - - - - - - <% - SimpleDateFormat dateFormat = new SimpleDateFormat("Z"); - String date = dateFormat.format(System.currentTimeMillis()); - %> - - <% - - } - %> - - - -
- - - - - - - - - - - - - - - - - - - - - - - - <%= "GMT " + date%> -
-
- - -
- - - - - - - - - - <% - if (showLogFiles) { - %> - - <% - if (showMax) { - %> - - <% - } else { - - %> - - <% - } - %> - - "> - - - - - - <% - } - %> - -
- - - - - - - - - - <% - if (!isValidTenant) { %> - - - <% - } else { - - - if (events == null || events.length == 0 || events[0] == null) { - %> - - <% - } else { - int index = 0; - for (LogEvent logMessage : events) { - index++; - if (index % 2 != 0) { - %> - - <% - } else { - %> - - - <% - } - %> - - - - <% - String imgId = "traceSymbolMax" + index; - %> - - - - <% - String id = "traceTable" + index; - if (index % 2 != 0) { - %> - - <% - } else { - %> - - - <% - } - %> - - - - <% - } - } - } - %> - -
- - - - - -
- - <%=logMessage.getLogTime()%> - - <%=CharacterEncoder.getSafeText(logMessage.getMessage())%> -
- -
- - - - - - - - - - - -
- - - - - - - - - - <% - int index = -1; - for (LogInfo logMessage : logInfo) { - ++index; - if (index % 2 != 0) { - %> - - <% - } else { - %> - - - <% - } - if (logMessage.getLogName().trim().equalsIgnoreCase("NO_LOG_FILES")) { - %> - - - <% - } else { - String logFile = logMessage.getLogName(); - String logDate = logMessage.getLogDate(); - String logSize = logMessage.getFileSize(); - %> - - - - - - - <% - } - %> - - - - <% - } - %> -
<%=logFile%> - <%=logDate%> - <%=logSize%> - - <% - if (isArchiveFile(logFile)) { - %> - - <% - } else { - %> - - <% - } - %> -
- -
-
-
-
-
- - - diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/index_old.jsp b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/index_old.jsp deleted file mode 100755 index 48aeb71109..0000000000 --- a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/index_old.jsp +++ /dev/null @@ -1,204 +0,0 @@ - -<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %> -<%@ page import="org.apache.stratos.logging.view.ui.LogViewerClient" %> -<%@ page import="org.apache.axis2.context.ConfigurationContext" %> -<%@ page import="org.wso2.carbon.CarbonConstants" %> -<%@ page import="org.wso2.carbon.logging.view.ui.LogViewerStub.LogMessage" %> -<%@ page import="org.wso2.carbon.utils.ServerConstants" %> -<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %> -<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %> - - - - -<% - String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session); - ConfigurationContext configContext = - (ConfigurationContext) config.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT); - - String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE); - LogViewerClient logViewerClient; - String type; - String keyword; - String action; - LogMessage[] logMessages; - try { - logViewerClient = new LogViewerClient(cookie, backendServerURL, configContext); - - type = request.getParameter("type"); - keyword = request.getParameter("keyword"); - action = request.getParameter("action"); - if (action != null && action.equals("clear-logs")) { - logViewerClient.cleaLogs(); - } - logMessages = logViewerClient.getLogs(type, keyword); - - } catch (Exception e) { - CarbonUIMessage.sendCarbonUIMessage(e.getMessage(), CarbonUIMessage.ERROR, request, e); -%> - -<% - return; - } -%> - - - -
-

- -
- - - - - - - -
- - - - - - - - - -
- - - -
-
- - -
- - - - - - - - - - - -
- - - - <% - int index = -1; - for (LogMessage logMessage : logMessages) { - ++index; - if (index % 2 != 0) { - - %> - - <% - - } else { - - %> - - <% - } - - String logLevel = logMessage.getType(); - if (logLevel == null || logLevel.equals("")) { - %> - - <% - } else { - %> - - <% - } - %> - - - - <% - } - %> -
- - - <% - if (logMessage.getLogMessage().equalsIgnoreCase("NO_LOGS")) { - %> - - <% - } else { - %> - <%=logMessage.getLogMessage()%> - <% } %> -
-
- ?');return false;" - value="" class="button" - name="clearLogs" type="button"> -
-
-
-
diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/js/logviewer.js b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/js/logviewer.js deleted file mode 100644 index 2565405b80..0000000000 --- a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/js/logviewer.js +++ /dev/null @@ -1,912 +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. - */ - -/* - log.js contains scripts need to handle log information. - */ -function viewSingleLogLevels() { - var loglevel = document.getElementById("logLevelID"); - var loglevel_index = null; - var loglevel_value = null; - if (loglevel != null) { - loglevel_index = loglevel.selectedIndex; - if (loglevel_index != null) { - loglevel_value = loglevel.options[loglevel_index].value; - } - } - if (loglevel_value != null && loglevel_value != "") { - location.href = "index.jsp?type=" + loglevel_value; - } else { - return; - } -} - -function viewApplicationLogs() { - var loglevel = document.getElementById("logLevelID"); - var appName = document.getElementById("appName"); - var loglevel_index = null; - var loglevel_value = null; - var appName_index = null; - var appName_value = null; - if (loglevel != null) { - loglevel_index = loglevel.selectedIndex; - if (loglevel_index != null) { - loglevel_value = loglevel.options[loglevel_index].value; - } - } - - if (appName != null) { - appName_index = appName.selectedIndex; - if (appName_index != null) { - appName_value = appName.options[appName_index].value; - } - } - if (loglevel_value == "Custom") { - loglevel_value = "ALL"; - } - if (loglevel_value != null && loglevel_value != "") { - location.href = "application_log_viewer.jsp?type=" + loglevel_value + "&appName=" + appName_value; - } else if (appName_value != null && appName_value != "") { - location.href = "application_log_viewer.jsp?type=" + loglevel_value + "&appName=" + appName_value; - } else { - return; - } -} - -function viewSingleLogLevel() { - var loglevel = document.getElementById("logLevelID"); - var tenantDomain = document.getElementById("tenantDomain").value; - var serviceName = document.getElementById("serviceName").value; - var logFile = document.getElementById("logFile").value; - var loglevel_index = null; - var loglevel_value = null; - if (loglevel != null) { - loglevel_index = loglevel.selectedIndex; - if (loglevel_index != null) { - loglevel_value = loglevel.options[loglevel_index].value; - } - } - if (loglevel_value != null && loglevel_value != "") { - location.href = "syslog_index.jsp?type=" + loglevel_value + "&logFile=" + logFile + "&tenantDomain=" + tenantDomain + "&serviceName=" + serviceName; - } else { - return; - } - -} - -function getTenantSpecificIndex() { - var loglevel = document.getElementById("logLevelID"); - var loglevel_index = null; - var loglevel_value = null; - var tenantDomain = document.getElementById("tenantDomain").value; - var serviceName = document.getElementById("serviceName"); - var servicelevel_idex = null; - var service_value = null; - if (loglevel != null) { - loglevel_index = loglevel.selectedIndex; - if (loglevel_index != null) { - loglevel_value = loglevel.options[loglevel_index].value; - } - if (loglevel_value == "Custom") { - loglevel_value = "ALL"; - } - } - if (serviceName != null) { - servicelevel_idex = serviceName.selectedIndex; - if (servicelevel_idex != null) { - service_value = serviceName.options[servicelevel_idex].value; - } - } - var keyword = document.getElementById("logkeyword"); - if (keyword != null && keyword != undefined && keyword.value != null && keyword.value != undefined) { - if (keyword.value == "") { - if (serviceName != null) { - location.href = "index.jsp?type=" + loglevel_value + "&tenantDomain=" + tenantDomain; - } else { - location.href = "index.jsp?type=" + loglevel_value + "&tenantDomain=" + tenantDomain + "&serviceName=" + serviceName; - } - } else { - if (serviceName != null) { - location.href = "index.jsp?type=" + loglevel_value + "&tenantDomain=" + - tenantDomain + "&serviceName=" + serviceName + "&keyword=" + keyword.value; - } else { - location.href = "index.jsp?type=" + loglevel_value + "&tenantDomain=" + - tenantDomain + "&keyword=" + keyword.value; - } - } - } else { - return; - } - -} - -function getTenantApplicationSpecificIndex() { - var loglevel = document.getElementById("logLevelID"); - var appName = document.getElementById("appName"); - var loglevel_index = null; - var loglevel_value = null; - var appName_index = null; - var appName_value = null; - var servicelevel_idex = null; - var service_value = null; - var tenantDomain = document.getElementById("tenantDomain"); - var serviceName = document.getElementById("serviceName"); - if (loglevel != null) { - loglevel_index = loglevel.selectedIndex; - if (loglevel_index != null) { - loglevel_value = loglevel.options[loglevel_index].value; - } - } - - if (appName != null) { - appName_index = appName.selectedIndex; - if (appName_index != null) { - appName_value = appName.options[appName_index].value; - } - } - - if (serviceName != null) { - servicelevel_idex = serviceName.selectedIndex; - if (servicelevel_idex != null) { - service_value = serviceName.options[servicelevel_idex].value; - } - } - - if (loglevel_value == "Custom") { - loglevel_value = "ALL"; - } - var keyword = document.getElementById("logkeyword"); - if (keyword != null && keyword != undefined) { - if (keyword.value == "") { - if (serviceName != null) { - location.href = "application_log_viewer.jsp?type=" + loglevel_value + "&serviceName=" + service_value - + "&appName=" + appName_value + "&tenantDomain=" + tenantDomain.value; - } else { - location.href = "application_log_viewer.jsp?type=" + loglevel_value + "&appName=" + appName_value + - "&tenantDomain=" + tenantDomain.value; - } - } else { - if (serviceName != null) { - location.href = "application_log_viewer.jsp?type=" + loglevel_value + "&keyword=" + keyword.value + - "&serviceName=" + service_value + "&appName=" + appName_value; - } else { - location.href = "application_log_viewer.jsp?type=" + loglevel_value + "&keyword=" + keyword.value + - "&appName=" + appName_value; - } - } - } else { - return; - } - - -} - -function getTenantProductSpecificIndex() { - var loglevel = document.getElementById("logLevelID"); - var appName = document.getElementById("appName"); - var loglevel_index = null; - var loglevel_value = null; - var appName_index = null; - var appName_value = null; - var servicelevel_idex = null; - var service_value = null; - var tenantDomain = document.getElementById("tenantDomain"); - var serviceName = document.getElementById("serviceName"); - if (loglevel != null) { - loglevel_index = loglevel.selectedIndex; - if (loglevel_index != null) { - loglevel_value = loglevel.options[loglevel_index].value; - } - } - - if (serviceName != null) { - servicelevel_idex = serviceName.selectedIndex; - if (servicelevel_idex != null) { - service_value = serviceName.options[servicelevel_idex].value; - } - } - - if (appName != null) { - appName_index = appName.selectedIndex; - if (appName_index != null) { - appName_value = appName.options[appName_index].value; - } - } - if (loglevel_value == "Custom") { - loglevel_value = "ALL"; - } - var keyword = document.getElementById("logkeyword"); - if (keyword != null && keyword != undefined) { - if (keyword.value == "") { - if (tenantDomain != null && tenantDomain != undefined) { - location.href = "application_log_viewer.jsp?type=" + loglevel_value + "&appName=" + appName_value + - "&tenantDomain=" + tenantDomain.value + "&serviceName=" + service_value; - } else { - location.href = "application_log_viewer.jsp?type=" + loglevel_value + "&appName=" + appName_value + - "&serviceName=" + service_value; - } - } else { - if (tenantDomain != null && tenantDomain != undefined) { - location.href = "application_log_viewer.jsp?type=" + loglevel_value + "&appName=" + appName_value + - "&tenantDomain=" + tenantDomain.value + "&serviceName=" + service_value + "&keyword=" + keyword.value; - } else { - location.href = "application_log_viewer.jsp?type=" + loglevel_value + "&appName=" + appName_value + - "&serviceName=" + service_value + "&keyword=" + keyword.value; - } - } - } else { - return; - } -} - -function getProductTenantSpecificIndex() { - var loglevel = document.getElementById("logLevelID"); - var loglevel_index = null; - var loglevel_value = null; - var tenantDomain = document.getElementById("tenantDomain"); - - var serviceName = document.getElementById("serviceName"); - if (loglevel != null) { - loglevel_index = loglevel.selectedIndex; - if (loglevel_index != null) { - loglevel_value = loglevel.options[loglevel_index].value; - } - if (loglevel_value == "Custom") { - loglevel_value = "ALL"; - } - } - var keyword = document.getElementById("logkeyword"); - if (keyword != null && keyword != undefined) { - if (keyword.value == "") { - if (tenantDomain != null && tenantDomain != undefined) { - location.href = "index.jsp?type=" + loglevel_value + "&tenantDomain=" + tenantDomain.value + "&serviceName=" + serviceName.value; - } else { - location.href = "index.jsp?type=" + loglevel_value + "&serviceName=" + serviceName.value; - } - - } else { - if (tenantDomain != null && tenantDomain != undefined) { - location.href = "index.jsp?type=" + loglevel_value + "&serviceName=" + serviceName.value + - "&tenantDomain=" + tenantDomain.value + "&keyword=" + keyword.value; - } else { - location.href = "index.jsp?type=" + loglevel_value + "&serviceName=" + serviceName.value + - "&keyword=" + keyword.value; - } - } - } else { - return; - } -} - -function submitenter(e) { - var keycode; - if (window.event) { - keycode = window.event.keyCode; - } else if (e) { - keycode = e.which; - } - if (keycode == 13) { - searchLogs(); - return true; - } else { - return true; - } -} - -function submitenterNormal(e) { - var keycode; - if (window.event) { - keycode = window.event.keyCode; - } else if (e) { - keycode = e.which; - } - if (keycode == 13) { - searchNormal(); - return true; - } else { - return true; - } -} - -function submitenterNormalManager(e) { - var keycode; - if (window.event) { - keycode = window.event.keyCode; - } else if (e) { - keycode = e.which; - } - if (keycode == 13) { - searchNormalManager(); - return true; - } else { - return true; - } -} -function submitenterTenant(e) { - var keycode; - if (window.event) { - keycode = window.event.keyCode; - } else if (e) { - keycode = e.which; - } - if (keycode == 13) { - getTenantSpecificIndex(); - return true; - } else { - return true; - } -} - -function submitenterbottomUp(e) { - var keycode; - if (window.event) { - keycode = window.event.keyCode; - } - else if (e) { - keycode = e.which; - } - if (keycode == 13) { - searchLogBottomLogs(); - return true; - } - else { - return true; - } -} - -function isNumeric(str) { - var validChars = "0123456789"; - var isNumber = true; - var char; - for (i = 0; i < str.length && isNumber == true; i++) { - char = str.charAt(i); - if (validChars.indexOf(char) == -1) { - isNumber = false; - } - } - return isNumber; -} - - -function searchLogBottomLogs() { - var logFile = document.getElementById("logFile").value; - var log_index = document.getElementById("logIndex").value; - var loglevel = document.getElementById("logLevelID"); - var serviceName = document.getElementById("serviceName").value; - var loglevel_index = null; - var loglevel_value = null; - var tenantDomain = document.getElementById("tenantDomain").value; - if (log_index == '') { - CARBON.showWarningDialog('Head index cannot be empty'); - return false; - } - if (!isNumeric(log_index)) { - CARBON.showWarningDialog('Enter non negative numeric values for log head'); - return false; - } - if (log_index < 1) { - CARBON.showWarningDialog('Log index should be between 1 and 10000000'); - return false; - } - if (log_index > 10000000) { - CARBON.showWarningDialog('Log index should be between 1 and 10000000'); - return false; - } - if (loglevel != null) { - loglevel_index = loglevel.selectedIndex; - if (loglevel_index != null) { - loglevel_value = loglevel.options[loglevel_index].value; - if (loglevel_value == "Custom") { - loglevel_value = "ALL"; - } - } - } - var keyword = document.getElementById("keyword"); - if (keyword != null && keyword != undefined && keyword.value != null - && keyword.value != undefined) { - if (keyword.value == "") { - location.href = "view.jsp?type=ALL&logIndex=" + log_index + "&logFile=" + logFile + "&tenantDomain=" + tenantDomain + "&serviceName=" + serviceName; - } else { - location.href = "view.jsp?type=" + loglevel_value + "&keyword=" - + keyword.value + "&logIndex=" + log_index + "&logFile=" + logFile + "&tenantDomain=" + tenantDomain + "&serviceName=" + serviceName; - } - } else { - return; - } -} -function searchLogs() { - var loglevel = document.getElementById("logLevelID"); - var tenantDomain = document.getElementById("tenantDomain"); - var serviceName = document.getElementById("serviceName"); - var loglevel_index = null; - var loglevel_value = null; - var servicelevel_idex = null; - var service_value = null; - var collapseVal = document.getElementById("propertyTableSearch"); - var collapse = "false"; - - if (loglevel != null) { - loglevel_index = loglevel.selectedIndex; - if (loglevel_index != null) { - loglevel_value = loglevel.options[loglevel_index].value; - } - if (loglevel_value == "Custom") { - loglevel_value = "ALL"; - } - } - if (collapseVal.style.display == "") { - collapse = "true"; - } - - if (serviceName != null) { - servicelevel_idex = serviceName.selectedIndex; - if (servicelevel_idex != null) { - service_value = serviceName.options[servicelevel_idex].value; - } - } - var propertyTab = document.getElementById('propertyTable'); - var propertySymbolMax = document.getElementById('propertySymbolMax'); - - var keyword = document.getElementById("logkeyword"); - if (keyword != null && keyword != undefined) { - if (keyword.value == "") { - if (tenantDomain != null && tenantDomain != undefined) { - if (serviceName != null) { - location.href = "index.jsp?type=" + loglevel_value + "&tenantDomain=" + tenantDomain.value + - "&serviceName=" + service_value + "&collapse=" + collapse; - } else { - location.href = "index.jsp?type=" + loglevel_value + "&tenantDomain=" + tenantDomain.value + - "&collapse=" + collapse; - } - } else { - if (serviceName != null) { - location.href = "index.jsp?type=" + loglevel_value + "&serviceName=" + service_value + "&collapse=" + collapse; - } else { - location.href = "index.jsp?type=" + loglevel_value + "&collapse=" + collapse; - } - } - } else { - if (tenantDomain != null && tenantDomain != undefined) { - if (serviceName != null) { - location.href = "index.jsp?type=" + loglevel_value + "&tenantDomain=" + tenantDomain.value + - "&serviceName=" + service_value + "&keyword=" + keyword.value + "&collapse=" + collapse; - } else { - location.href = "index.jsp?type=" + loglevel_value + "&tenantDomain=" + tenantDomain.value + - "&keyword=" + keyword.value + "&collapse=" + collapse; - } - - } else { - if (serviceName != null) { - location.href = "index.jsp?type=" + loglevel_value + "&serviceName=" + service_value + - "&keyword=" + keyword.value + "&collapse=" + collapse; - } else { - location.href = "index.jsp?type=" + loglevel_value + - "&keyword=" + keyword.value + "&collapse=" + collapse; - } - - } - } - } else { - return; - } -} - -function searchNormal() { - var loglevel = document.getElementById("logLevelID"); - var loglevel_index = null; - var loglevel_value = null; - if (loglevel != null) { - loglevel_index = loglevel.selectedIndex; - if (loglevel_index != null) { - loglevel_value = loglevel.options[loglevel_index].value; - } - if (loglevel_value == "Custom") { - loglevel_value = "ALL"; - } - } - var keyword = document.getElementById("logkeyword"); - if (keyword != null && keyword != undefined && keyword.value != null && keyword.value != undefined) { - if (keyword.value == "") { - location.href = "index.jsp?type=" + loglevel_value; - } else { - location.href = "index.jsp?type=" + loglevel_value + "&keyword=" + keyword.value; - } - } else { - return; - } -} - -function searchNormalManager() { - var loglevel = document.getElementById("logLevelID"); - var serviceName = document.getElementById("serviceName"); - var servicelevel_idex = null; - var service_value = null; - var loglevel_index = null; - var loglevel_value = null; - var collapseVal = document.getElementById("propertyTableSearch"); - var collapse = "false"; - if (loglevel != null) { - loglevel_index = loglevel.selectedIndex; - if (loglevel_index != null) { - loglevel_value = loglevel.options[loglevel_index].value; - } - if (loglevel_value == "Custom") { - loglevel_value = "ALL"; - } - } - if (collapseVal.style.display == "") { - collapse = "true"; - } - - if (serviceName != null) { - servicelevel_idex = serviceName.selectedIndex; - if (servicelevel_idex != null) { - service_value = serviceName.options[servicelevel_idex].value; - } - } - var keyword = document.getElementById("logkeyword"); - if (keyword != null && keyword != undefined && keyword.value != null && keyword.value != undefined) { - if (keyword.value == "") { - location.href = "index.jsp?type=" + loglevel_value + "&serviceName=" + service_value + "&collapse=" + collapse; - } else { - location.href = "index.jsp?type=" + loglevel_value + "&keyword=" + keyword.value + - "&serviceName=" + service_value + "&collapse=" + collapse; - } - } else { - return; - } -} - - -function showQueryProperties() { - var propertyTab = document.getElementById('propertyTable'); - var propertySymbolMax = document.getElementById('propertySymbolMax'); - if (propertyTab.style.display == 'none') { - propertyTab.style.display = ''; - propertySymbolMax.setAttribute('style', 'background-image:url(images/minus.gif);'); - } else { - propertyTab.style.display = 'none'; - propertySymbolMax.setAttribute('style', 'background-image:url(images/plus.gif);'); - } -} - -function showQueryPropertiesSearch() { - var propertyTab = document.getElementById('propertyTableSearch'); - var propertySymbolMax = document.getElementById('propertySymbolMaxSearch'); - if (propertyTab.style.display == 'none') { - propertyTab.style.display = ''; - propertySymbolMax.setAttribute('style', 'background-image:url(images/minus.gif);'); - } else { - propertyTab.style.display = 'none'; - propertySymbolMax.setAttribute('style', 'background-image:url(images/plus.gif);'); - } -} -function appSubmitenter(e) { - var keycode; - if (window.event) { - keycode = window.event.keyCode; - } else if (e) { - keycode = e.which; - } - if (keycode == 13) { - searchAppLogs(); - return true; - } else { - return true; - } -} - -function appSubmitenterTenant(e) { - var keycode; - if (window.event) { - keycode = window.event.keyCode; - } else if (e) { - keycode = e.which; - } - if (keycode == 13) { - getTenantApplicationSpecificIndex(); - return true; - } else { - return true; - } -} -function searchAppLogs() { - var loglevel = document.getElementById("logLevelID"); - var appName = document.getElementById("appName"); - var loglevel_index = null; - var loglevel_value = null; - var appName_index = null; - var appName_value = null; - if (loglevel != null) { - loglevel_index = loglevel.selectedIndex; - if (loglevel_index != null) { - loglevel_value = loglevel.options[loglevel_index].value; - } - } - if (loglevel_value == "Custom") { - loglevel_value = "ALL"; - } - if (appName != null) { - appName_index = appName.selectedIndex; - if (appName_index != null) { - appName_value = appName.options[appName_index].value; - } - } - var keyword = document.getElementById("logkeyword"); - if (keyword != null && keyword != undefined) { - if (keyword.value == "") { - location.href = "application_log_viewer.jsp?type=" + loglevel_value + "&appName=" + appName_value; - } else { - location.href = "application_log_viewer.jsp?type=" + loglevel_value + "&keyword=" + keyword.value + "&appName=" + appName_value; - } - } else { - return; - } -} - -function searchAppLogsAdv() { - var loglevel = document.getElementById("logLevelID"); - var appName = document.getElementById("appName"); - - var tenantDomain = document.getElementById("tenantDomain"); - var serviceName = document.getElementById("serviceName"); - - var servicelevel_idex = null; - var service_value = null; - var loglevel_index = null; - var loglevel_value = null; - var appName_index = null; - var appName_value = null; - if (loglevel != null) { - loglevel_index = loglevel.selectedIndex; - if (loglevel_index != null) { - loglevel_value = loglevel.options[loglevel_index].value; - } - } - if (loglevel_value == "Custom") { - loglevel_value = "ALL"; - } - if (appName != null) { - appName_index = appName.selectedIndex; - if (appName_index != null) { - appName_value = appName.options[appName_index].value; - } - } - - if (serviceName != null) { - servicelevel_idex = serviceName.selectedIndex; - if (servicelevel_idex != null) { - service_value = serviceName.options[servicelevel_idex].value; - } - } - var keyword = document.getElementById("logkeyword"); - if (keyword != null && keyword != undefined) { - if (keyword.value == "") { - if (tenantDomain != null && tenantDomain != undefined) { - if (serviceName != null) { - location.href = "application_log_viewer.jsp?type=" + loglevel_value + "&tenantDomain=" + - tenantDomain.value + "&serviceName=" + service_value + "&appName=" + appName_value; - } else { - location.href = "application_log_viewer.jsp?type=" + loglevel_value + "&tenantDomain=" + - tenantDomain.value + "&appName=" + appName_value; - } - } else { - if (serviceName != null) { - location.href = "application_log_viewer.jsp?type=" + loglevel_value + "&serviceName=" + service_value + - "&appName=" + appName_value; - } else { - location.href = "application_log_viewer.jsp?type=" + loglevel_value + "&appName=" + appName_value; - } - } - } else { - if (tenantDomain != null && tenantDomain != undefined) { - if (serviceName != null) { - location.href = "application_log_viewer.jsp?type=" + loglevel_value + "&tenantDomain=" + - tenantDomain.value + - "&serviceName=" + service_value + "&keyword=" + keyword.value + "&appName=" + appName_value; - } else { - location.href = "application_log_viewer.jsp?type=" + loglevel_value + "&tenantDomain=" + tenantDomain.value + - "&keyword=" + keyword.value + "&appName=" + appName_value; - } - - } else { - if (serviceName != null) { - location.href = "application_log_viewer.jsp?type=" + loglevel_value + "&serviceName=" + service_value + - "&keyword=" + keyword.value + "&appName=" + appName_value; - } else { - location.href = "application_log_viewer.jsp?type=" + loglevel_value + - "&keyword=" + keyword.value + "&appName=" + appName_value; - } - - } - } - } else { - return; - } -} - -function searchLog111() { - var loglevel = document.getElementById("logLevelID"); - var logFile = document.getElementById("logFile").value; - var serviceName = document.getElementById("serviceName").value; - var loglevel_index = null; - var loglevel_value = null; - var tenantDomain = document.getElementById("tenantDomain").value; - if (loglevel != null) { - loglevel_index = loglevel.selectedIndex; - if (loglevel_index != null) { - loglevel_value = loglevel.options[loglevel_index].value; - } - } - var keyword = document.getElementById("keyword"); - if (keyword != null && keyword != undefined && keyword.value != null && keyword.value != undefined) { - if (keyword.value == "") { - location.href = "syslog_index.jsp?type=ALL" + "&logFile=" + logFile + "&tenantDomain=" + tenantDomain; - } else { - location.href = "syslog_index.jsp?type=" + loglevel_value + "&keyword=" + keyword.value + "&logFile=" + logFile + "&tenantDomain=" + tenantDomain + "&serviceName=" + serviceName; - } - } else { - return; - } -} - -function clearLogEntries(message) { - CARBON.showConfirmationDialog(message, function () { - location.href = "syslog_index.jsp?action=clear-logs"; - }); -} - -function viewSingleSysLogLevel() { - var loglevel = document.getElementById("logLevelID"); - var serviceName = document.getElementById("serviceName").value; - var logFile = document.getElementById("logFile").value; - var tenantDomain = document.getElementById("tenantDomain").value; - var loglevel_index = null; - var loglevel_value = null; - if (loglevel != null) { - loglevel_index = loglevel.selectedIndex; - if (loglevel_index != null) { - loglevel_value = loglevel.options[loglevel_index].value; - } - } - if (loglevel_value != null && loglevel_value != "") { - location.href = "view.jsp?type=" + loglevel_value + "&logFile=" + logFile + "&tenantDomain=" + tenantDomain + "&serviceName=" + serviceName; - } else { - return; - } -} - -function clearProperties() { - document.getElementById("logIndex").value = ""; - document.getElementById("type").value = "ALL"; - document.getElementById("keyword").value = ""; -} - -function searchTenantLog() { - var loglevel = document.getElementById("logLevelID"); - var serviceName = document.getElementById("serviceName").value; - var logFile = document.getElementById("logFile").value; - var tenantDomain = document.getElementById("tenantDomain").value; - var loglevel_index = null; - var loglevel_value = null; - if (loglevel != null) { - loglevel_index = loglevel.selectedIndex; - if (loglevel_index != null) { - loglevel_value = loglevel.options[loglevel_index].value; - if (loglevel_value == "Custom") { - loglevel_value = "ALL"; - } - } - } - var keyword = document.getElementById("keyword"); - if (keyword != null && keyword != undefined && keyword.value != null - && keyword.value != undefined) { - if (keyword.value == "") { - location.href = "view.jsp?type=ALL" + "&logFile=" + logFile + "&tenantDomain=" + tenantDomain + "&serviceName=" + serviceName; - } else { - location.href = "view.jsp?type=" + loglevel_value - + "&keyword=" + keyword.value + "&logFile=" + logFile + "&tenantDomain=" + tenantDomain + "&serviceName=" + serviceName; - } - } else { - return; - } -} - -function getFilteredLogs() { - - var loglevel = document.getElementById("logLevelID"); - var log_index = document.getElementById("logIndex").value; - var appName = document.getElementById("appName"); - var start = document.getElementById("start").value; - var end = document.getElementById("end").value; - if (document.getElementById("NowradioDate").checked) { - start = ''; - end = ''; - } - var serviceName = null; - var tenantDomain = null; - // regular expression to match required date format - var reTdate = '\\d{4}-\\d{1,2}-\\d{1,2}\\s\\d{1,2}:\\d{1,2}'; - var re = new RegExp(reTdate); - - if (start != '' && !start.match(re)) { - CARBON.showWarningDialog('Invalid start date Format'); - return false; - } - if (end != '' && !end.match(re)) { - CARBON.showWarningDialog('Invalid end date Format'); - return false; - } -// // regular expression to match required time format -// var reTime = /^\d{1,2}:\d{2}([ap]m)?$/; -// if(time != '' && !time.match(reTime)) { -// CARBON.showWarningDialog('Invalid Time Format'); -// return false; -// } - - if (document.getElementById("serviceName") != null) { - serviceName = document.getElementById("serviceName").value - } - if (document.getElementById("tenantDomain") != null) { - tenantDomain = document.getElementById("tenantDomain").value - } - var loglevel_index = null; - var loglevel_value = null; - - if (loglevel != null) { - loglevel_index = loglevel.selectedIndex; - if (loglevel_index != null) { - loglevel_value = loglevel.options[loglevel_index].value; - if (loglevel_value == "Custom") { - loglevel_value = "ALL"; - } - } - } - var keyword = document.getElementById("keyword").value; - var logger = document.getElementById("logger").value; - if (appName != null) { - appName = document.getElementById("appName").value; - location.href = "application_log_viewer.jsp?priority=" + loglevel_value - + "&keyword=" + keyword + "&logIndex=" + log_index - + "&tenantDomain=" + tenantDomain + "&serviceName=" + serviceName - + "&logger=" + logger + "&start=" + start + "&appName=" + appName - + "&end=" + end; - } else { - location.href = "cassandra_log_viewer.jsp?priority=" + loglevel_value - + "&keyword=" + keyword + "&logIndex=" + log_index - + "&tenantDomain=" + tenantDomain + "&serviceName=" + serviceName - + "&logger=" + logger + "&start=" + start - + "&end=" + end; - } - -} - - -function showTrace(obj) { - var traceTab = document.getElementById('traceTable' + obj); - var traceSymbolMax = document.getElementById('traceSymbolMax' + obj); - if (traceTab.style.display == 'none') { - traceTab.style.display = ''; - traceSymbolMax.setAttribute('style', 'background-image:url(images/minus.gif);'); - } else { - traceTab.style.display = 'none'; - traceSymbolMax.setAttribute('style', 'background-image:url(images/plus.gif);'); - } -} - diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/syslog_index.jsp b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/syslog_index.jsp deleted file mode 100644 index 3faaca3425..0000000000 --- a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/syslog_index.jsp +++ /dev/null @@ -1,372 +0,0 @@ - -<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" - prefix="carbon" %> -<%@ page import="org.apache.stratos.logging.view.ui.LogViewerClient" %> -<%@ page import="org.apache.axis2.context.ConfigurationContext" %> -<%@ page import="org.wso2.carbon.CarbonConstants" %> -<%@ page - import="org.wso2.carbon.logging.view.stub.types.carbon.LogMessage" %> -<%@ page import="org.wso2.carbon.utils.ServerConstants" %> -<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %> -<%@ page import="org.wso2.carbon.logging.view.stub.types.carbon.PaginatedLogInfo" %> -<%@ page import="org.wso2.carbon.logging.view.stub.types.carbon.LogEvent" %> -<%@ page import="org.wso2.carbon.logging.view.stub.types.carbon.LogInfo" %> -<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %> -<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %> -<%@ page import="java.util.regex.Matcher" %> -<%@ page import="java.util.regex.Pattern" %> - - - - -<%! - private boolean isArchiveFile(String fileName) { - String archivePattern = "[a-zA-Z]*\\.gz"; - CharSequence inputStr = fileName; - Pattern pattern = Pattern.compile(archivePattern); - Matcher matcher = pattern.matcher(inputStr); - return matcher.find(); - } -%> -<% - String backendServerURL = CarbonUIUtil - .getServerURL(config.getServletContext(), session); - ConfigurationContext configContext = (ConfigurationContext) config.getServletContext() - .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT); - - String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE); - LogViewerClient logViewerClient; - String action; - LogMessage[] logMessages; - LogInfo[] logInfo; - String tenantDomain = ""; - String serviceName = "WSO2 Stratos Manager"; - boolean isLogsFromSyslog; - PaginatedLogInfo paginatedLogInfo; - boolean isStratosService = false; - String pageNumberStr = request.getParameter("pageNumber"); - boolean isSTSyslog = false; - String serviceNames[]; - boolean isManager = false; - boolean showManager = false; - if (pageNumberStr == null) { - pageNumberStr = "0"; - } - boolean showTenantDomain = false; - int pageNumber = 0; - int numberOfPages = 0; - try { - pageNumber = Integer.parseInt(pageNumberStr); - } catch (NumberFormatException ignored) { - // page number format exception - } - try { - - logViewerClient = new LogViewerClient(cookie, backendServerURL, configContext); - action = request.getParameter("action"); - tenantDomain = request.getParameter("tenantDomain"); - serviceName = request.getParameter("serviceName"); - isLogsFromSyslog = logViewerClient.isDataFromSysLog(tenantDomain); - isSTSyslog = logViewerClient.isSTSyslogConfig(tenantDomain); - isManager = logViewerClient.isManager(); - - serviceName = (serviceName == null) ? "WSO2 Stratos Manager" : serviceName; - tenantDomain = (tenantDomain == null) ? "" : tenantDomain; - serviceNames = logViewerClient.getServiceNames(); - isStratosService = logViewerClient.isStratosService(); - showTenantDomain = (isSTSyslog && isLogsFromSyslog && isStratosService); - showManager = (isManager && isLogsFromSyslog); - if (logViewerClient.isLogsConfigured(tenantDomain)) { - paginatedLogInfo = logViewerClient.getPaginatedLogInfo(pageNumber, - tenantDomain, serviceName); - if (paginatedLogInfo != null) { - logInfo = paginatedLogInfo.getLogInfo(); - numberOfPages = paginatedLogInfo.getNumberOfPages(); - //logMessages = logViewerClient.getTenentLogs(); - - //logMessages = logViewerClient.getLogs(type, keyword); - - for (int i = 0; i < logInfo.length; i++) { - String logFile = logInfo[i].getLogName(); - String logDate = logInfo[i].getLogDate(); - String logSize = logInfo[i].getLogDate(); - } - } else { - logViewerClient.getPaginatedLogInfo(pageNumber, - tenantDomain, serviceName); - CarbonUIMessage.sendCarbonUIMessage( - "Please configure syslog in order to view tenant specific logs.", - CarbonUIMessage.ERROR, request); -%> - -<% - return; - } - -} else { - logViewerClient.getPaginatedLogInfo(pageNumber, - tenantDomain, serviceName); - CarbonUIMessage.sendCarbonUIMessage( - "Please configure syslog in order to view tenant specific logs.", - CarbonUIMessage.ERROR, request); -%> - -<% - return; - } - -} catch (Exception e) { - CarbonUIMessage.sendCarbonUIMessage(e.getLocalizedMessage(), CarbonUIMessage.ERROR, request, - e); -%> - -<% - return; - } -%> - - - -
-

- -

- -
-
- <% - if (isLogsFromSyslog) { - %> - - - <% - } else { - %> - - - <% - } - %> - -

- <% - if (showTenantDomain || showManager) { - %> - - - - - - -
- - - - <% - if (showTenantDomain) { - %> - - - - - - <% - } else { - %> - - <% - } - if (showManager) { - %> - - - - - - - <% - } else { - %> - - <% - } - %> - - - -
- - - - - - - - -
-
- <% - } - %> -

- - - - - - - - -
- - - - - - - - - - <% - int index = -1; - for (LogInfo logMessage : logInfo) { - ++index; - if (index % 2 != 0) { - %> - - <% - } else { - %> - - - <% - } - if (logMessage.getLogName().trim().equalsIgnoreCase("NO_LOG_FILES")) { - %> - - - <% - } else { - String logFile = logMessage.getLogName().replace("0_", ""); - String logDate = logMessage.getLogDate().replace("0_", ""); - String logSize = logMessage.getFileSize(); - %> - - - - - - - <% - } - %> - - - - <% - } - %> -
<%=logFile%> - <%=logDate%> - <%=logSize%> - - <% if (!isArchiveFile(logFile)) { %> - - <% - } - %> - <% if (isArchiveFile(logFile)) { %> - - <% - } else { - %> - - <% - } - %> -
-
- -
-
-
diff --git a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/view.jsp b/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/view.jsp deleted file mode 100755 index 560a2c33b1..0000000000 --- a/components/org.apache.stratos.logging.view.ui/src/main/resources/web/log-view/view.jsp +++ /dev/null @@ -1,314 +0,0 @@ - -<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" - prefix="carbon" %> -<%@ page import="org.apache.stratos.logging.view.ui.LogViewerClient" %> -<%@ page import="org.apache.axis2.context.ConfigurationContext" %> -<%@ page import="org.wso2.carbon.ui.util.CharacterEncoder" %> -<%@ page import="org.wso2.carbon.CarbonConstants" %> -<%@ page import="org.wso2.carbon.logging.view.stub.types.carbon.LogMessage" %> -<%@ page import="org.wso2.carbon.utils.ServerConstants" %> -<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %> -<%@ page import="org.wso2.carbon.logging.view.stub.types.carbon.PaginatedLogMessage" %> -<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %> - - - - - <% - String backendServerURL = CarbonUIUtil - .getServerURL(config.getServletContext(), session); - ConfigurationContext configContext = (ConfigurationContext) config.getServletContext() - .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT); - - String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE); - LogViewerClient logViewerClient; - String logIndex = ""; - String keyword; - String action; - String logFile; - String type; - String keyWordString = ""; - String serviceName = "WSO2 Stratos Manager"; - String tenantDomain = ""; - LogMessage[] logMessages; - PaginatedLogMessage paginatedLogMsgs; - String pageNumberStr = request.getParameter("pageNumber"); - logFile = request.getParameter("logFile"); - String parameter = ""; - if (pageNumberStr == null) { - pageNumberStr = "0"; - } - int pageNumber = 0; - int numberOfPages = 0; - try { - pageNumber = Integer.parseInt(pageNumberStr); - } catch (NumberFormatException ignored) { - // page number format exception - } - String numberOfBottomLines = ""; - try { - logViewerClient = new LogViewerClient(cookie, backendServerURL, configContext); - logIndex = request.getParameter("logIndex"); - keyword = request.getParameter("keyword"); - serviceName = request.getParameter("serviceName"); - tenantDomain = request.getParameter("tenantDomain"); - keyWordString = (keyword == null) ? "" : keyword; - keyWordString = (keyWordString.equals("null")) ? "" : keyWordString; - serviceName = (serviceName == null) ? "WSO2 Stratos Manager" : serviceName; - if (keyWordString.trim().equals("")) { - keyword = null; - } - action = request.getParameter("action"); - type = request.getParameter("type"); - type = (type == null) ? "ALL" : type; - tenantDomain = (tenantDomain == null) ? "" : tenantDomain; - int start = (pageNumber * 200) + 1; - int end = (pageNumber * 200) + 200; - int maxLines = logViewerClient.getLineNumbers(logFile, tenantDomain, serviceName); - int maxLenPerItr = (pageNumber + 1) * 1000; - if (maxLines > 1000) { - - } - String logIndex1 = Integer.toString(maxLines); - if (logIndex != null && !logIndex.equals("null") && !logIndex.equals("")) { - //int index = Integer.parseInt(logIndex); - paginatedLogMsgs = logViewerClient.getPaginatedLogMessage(pageNumber, type, - keyword, logFile, logIndex, maxLines, start, end, tenantDomain, serviceName); - } else { - paginatedLogMsgs = logViewerClient.getPaginatedBottomUpLogMessage(pageNumber, - type, keyword, logFile, maxLines, start, end, tenantDomain, serviceName); - //paginatedLogMsgs = logViewerClient.getPaginatedLogMessage(pageNumber, type, keyword, logFile, logIndex1, maxLines, start, end); - } - logMessages = paginatedLogMsgs.getLogInfo(); - numberOfPages = paginatedLogMsgs.getNumberOfPages(); - if (logIndex != null && !logIndex.endsWith("null")) { - numberOfBottomLines = logIndex; - } - parameter = "logFile=" + logFile + "&logIndex=" + logIndex + "&type=" + type - + "&keyword=" + keyword + "&tenantDomain=" + tenantDomain + "&serviceName=" + serviceName; - - } catch (Exception e) { - CarbonUIMessage.sendCarbonUIMessage(e.getMessage(), CarbonUIMessage.ERROR, request, - e); - %> - - <% - return; - } - %> - - -
-

- -

- -
- - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
-
- -
- <%-- - <%-- page="view.jsp" pageNumberParameterName="pageNumber" parameters="<%=parameter%>"/> --%> - - - - - - - - - <% - } - %> - - - <%-- - <%-- page="view.jsp" pageNumberParameterName="pageNumber" parameters="<%=parameter%>"/> --%> - - -
- - - - - - - - - - <% - int index = -1; - int i = 0; - for (LogMessage logMessage : logMessages) { - ++index; - i++; - if (index % 2 != 0) { - %> - - <% - } else { - %> - - - <% - } - if (logMessage != null) { - String logLevel = logMessage.getType(); - if (logLevel == null || logLevel.equals("")) { - %> - - <% - } else { - %> - - <% - } - %> - - - - <% - } - } - %> - -
- - - -
- - <% - if (logMessage.getLogMessage().equalsIgnoreCase("NO_LOGS")) { - %> <% - } else { - %> <%=CharacterEncoder.getSafeText(logMessage.getLogMessage())%> <% - } - %> -
- <% - if (i >= 199) { - %> - -
Only 200 log messages are displayed, please for more ... - -
- -
-
-
- diff --git a/components/org.apache.stratos.manager.console/console/applications_form.jag b/components/org.apache.stratos.manager.console/console/applications_form.jag index ad1745ca8b..6f63501991 100644 --- a/components/org.apache.stratos.manager.console/console/applications_form.jag +++ b/components/org.apache.stratos.manager.console/console/applications_form.jag @@ -57,6 +57,8 @@ if (!elements) { }else if(elements.action == 'deploy'){ applicationHbs = 'applicationDeploy'; applicationPolicyData = util.RESTCalls.getApplicationPolicies(); + }else if(elements.action == 'signup'){ + applicationHbs = 'applicationSignup'; } }else{ diff --git a/components/org.apache.stratos.manager.console/console/controllers/applications/application_requests.jag b/components/org.apache.stratos.manager.console/console/controllers/applications/application_requests.jag index 2e51c7bf94..5721e7c85c 100644 --- a/components/org.apache.stratos.manager.console/console/controllers/applications/application_requests.jag +++ b/components/org.apache.stratos.manager.console/console/controllers/applications/application_requests.jag @@ -46,6 +46,9 @@ try { case "forceundeployapplication": formSubmit = util.RESTCalls.forceUndeployApplication(applicationId); break; + case "signupapplication": + formSubmit = util.RESTCalls.signupApplication(applicationId, formPayload); + break; default: session.put("deploy-status", { "message": "Sorry Endpoint Error", "status": "error" }); diff --git a/components/org.apache.stratos.manager.console/console/controllers/rest/rest_calls.jag b/components/org.apache.stratos.manager.console/console/controllers/rest/rest_calls.jag index 7b020fa0cf..9876f6333b 100644 --- a/components/org.apache.stratos.manager.console/console/controllers/rest/rest_calls.jag +++ b/components/org.apache.stratos.manager.console/console/controllers/rest/rest_calls.jag @@ -140,6 +140,10 @@ RESTCalls = new function(){ return this.send("POST","/applications/"+applicationId+"/undeploy",{}); }; + this.signupApplication = function(applicationId, signupJSON){ + return this.send("POST","/applications/"+applicationId+"/signup",signupJSON); + }; + this.forceUndeployApplication = function(applicationId){ return this.send("POST","/applications/"+applicationId+"/undeploy?force=true",{}); }; diff --git a/components/org.apache.stratos.manager.console/console/themes/theme0/css/custom.css b/components/org.apache.stratos.manager.console/console/themes/theme0/css/custom.css index a8b1b3a159..bc2b889092 100644 --- a/components/org.apache.stratos.manager.console/console/themes/theme0/css/custom.css +++ b/components/org.apache.stratos.manager.console/console/themes/theme0/css/custom.css @@ -214,7 +214,7 @@ a.btn:hover { } button.hover-unsubscribe, button.hover-details, button.hover-delete,button.hover-delete-group, button.b-top, -button.hover-undeploy{ +button.hover-undeploy, button.hover-signup{ margin-top: .7em; } diff --git a/components/org.apache.stratos.manager.console/console/themes/theme0/css/custom/applications_signup.css b/components/org.apache.stratos.manager.console/console/themes/theme0/css/custom/applications_signup.css new file mode 100644 index 0000000000..c86c79e8a0 --- /dev/null +++ b/components/org.apache.stratos.manager.console/console/themes/theme0/css/custom/applications_signup.css @@ -0,0 +1,224 @@ +/* + * + * 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. + * +*/ + +.right-side{ + float: left; + width: 100%; + margin-top:20px; +} +#applicationId{ + left: 318px; + top: 33px; +} + +.stepnode { + border: 1px solid silver; + position: absolute !important; + width: 5em; + height: 5em; + padding: 0.5em; + z-index: 1; + border-radius: 0.5em; + box-shadow: 2px 2px 19px #aaa; + background: white; + word-wrap: break-word; + padding-top: 24px; + text-align: center; + cursor: pointer; +} + +.stepnode span{ + position: absolute; + width: 4em; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + margin-left: -27px; +} + +.block-cartridge { + border: 1px solid silver; + border-radius: 0.5em; + width: 80px; + height: 80px; + background-color:#CCC; + float: left; + margin: 5px; + padding: 5px; + word-wrap: break-word; + padding-top: 24px; + cursor: pointer; +} + +.block-group { + border: 1px solid silver; + border-radius: 0.5em; + width: 80px; + height: 80px; + background-color: #CCC; + float: left; + margin: 5px; + padding: 5px; + word-wrap: break-word; + padding-top: 24px; + cursor: pointer; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.app-creator { + height: 600px; + background-color: rgb(244, 244, 244); + border: 1px solid #ddd; + border-radius: 4px; + margin-left: 10px; + position: relative; +} + +#whiteboard{ + width: 100%; + height: 585px; + position: absolute; + overflow: auto; +} + +.description{ + min-height: 300px; + max-height: 400px; +} + +.component-section{ + max-height: 200px; + overflow: auto; + min-height: 200px; +} + +.description-section{ + min-height: 260px; + max-height: 400px; + overflow: auto; +} + +.app-details { + margin: 10px; +} + +.app-details-tab-content{ + border: 1px solid #ddd; + border-top: transparent; + min-height: 233px; + padding: 20px; + border-radius: 0 0 4px 4px; +} +.dragActive { + border: 2px dotted orange; + +} + +.node-disable{ + background-color: #bdc3c7; +} + + +.node circle { + fill: #fff; + stroke: steelblue; + stroke-width: 3px; +} + +.node text { font: 12px sans-serif; } + +.link { + fill: none; + stroke: rgb(0, 0, 255); + stroke-width: 0.5px; +} + +.input-false{ + background-color: #CCC; + border-color: #ddd; + border-width: 1px; +} + +#component-data>div>h3{ + display: none; +} + +#component-info-update{ + margin-top:-5px;margin-bottom: 20px; + float: right; +} + +#component-data{margin-top: 20px} +.stepnode i { + margin-top: 0px; + color: #e67e22; + margin-left: -7px; +} + +.notification { + position: absolute; + background-color: #fff; + width: 30px; + height: 30px; + border-radius: 15px; + top: 52px; + left: 52px; +} +.reposition { + float: right; + margin: 11px 20px; + padding: 5px; + background-color: white; + border-radius: 40px; + width: 40px; + z-index: 9999; + position: relative; + cursor: pointer; +} + +.reposition i{ + padding-left: 4px; + color: rgb(93, 170, 254); + padding-top: 2px; +} + +div#general>div>h3 { + display: none; +} +.highlightme{ + background-color: #6BCFFE; +} + +.signup-default i{ + color: #e67e22; +} + +.signup-default h4{ + text-align: center; + padding: 22px; + background-color: #CACACA; +} + +.signup-details { + margin-top: 2em; +} \ No newline at end of file diff --git a/components/org.apache.stratos.manager.console/console/themes/theme0/helpers/applications_signup.js b/components/org.apache.stratos.manager.console/console/themes/theme0/helpers/applications_signup.js new file mode 100644 index 0000000000..0efc5913e9 --- /dev/null +++ b/components/org.apache.stratos.manager.console/console/themes/theme0/helpers/applications_signup.js @@ -0,0 +1,29 @@ +/* + * + * 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. + * + */ + +var resources = function (page, meta) { + return { + js: ['JSONEditor-0.7.12/jsoneditor-0.7.12.js','bootstrap-switch-3.0.2/bootstrap-switch.min.js', 'custom/script.js','custom/form.js', + 'jquery.contextMenu/jquery.contextMenu.js', 'jquery.contextMenu/jquery.ui.position.js', 'jsplumb-1.7.2/dom.jsPlumb-1.7.2-min.js', + 'dagre-v0.7.0/dagre.min.js','custom/applications-signup.js'], + css: ['bootstrap-switch-3.0.2/bootstrap-switch.min.css', 'custom/style.css', 'custom/applications_signup.css'] + }; +}; diff --git a/components/org.apache.stratos.manager.console/console/themes/theme0/js/custom/applications-signup.js b/components/org.apache.stratos.manager.console/console/themes/theme0/js/custom/applications-signup.js new file mode 100644 index 0000000000..7977824592 --- /dev/null +++ b/components/org.apache.stratos.manager.console/console/themes/theme0/js/custom/applications-signup.js @@ -0,0 +1,388 @@ +/* + * + * 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. + * + */ +// repaint +function Repaint(){ + $("#whiteboard").resize(function(){ + jsPlumb.repaintEverything(); + }); +} +// drag +function DragEl(el){ + jsPlumb.draggable($(el) ,{ + containment:"#whiteboard" + }); +} + + +// JsPlumb Config +var color = "gray", + exampleColor = "#00f", + arrowCommon = { foldback:0.7, fillStyle:color, width:14 }; + +jsPlumb.importDefaults({ + Connector : [ "Bezier", { curviness:63 } ] +}); + + +var nodeDropOptions = { + activeClass:"dragActive" +}; + +var bottomConnectorOptions = { + endpoint:"Rectangle", + paintStyle:{ width:25, height:21, fillStyle:'#666' }, + isSource:true, + connectorStyle : { strokeStyle:"#666" }, + isTarget:false, + maxConnections:20 +}; + +var endpointOptions = { + isTarget:true, + endpoint:"Dot", + paintStyle:{ + fillStyle:"gray" + }, + dropOptions: nodeDropOptions, + maxConnections:1 +}; + +var groupOptions = { + isTarget:true, + endpoint:"Dot", + paintStyle:{ + fillStyle:"gray" + }, + dropOptions: nodeDropOptions, + maxConnections:1 +}; + +var generatedCartridgeEndpointOptions = { + isTarget:false, + endpoint:"Dot", + paintStyle:{ + fillStyle:"gray" + }, + dropOptions: '', + maxConnections:1 +}; + +var generatedGroupOptions = { + isTarget:false, + endpoint:"Dot", + paintStyle:{ + fillStyle:"gray" + }, + dropOptions: nodeDropOptions, + maxConnections:1 +}; + +function dagrePosition(){ + // construct dagre graph from JsPlumb graph + var g = new dagre.graphlib.Graph(); + g.setGraph({ranksep:'80'}); + g.setDefaultEdgeLabel(function() { return {}; }); + var nodes = $(".stepnode"); + + for (var i = 0; i < nodes.length; i++) { + var n = nodes[i]; + g.setNode(n.id, {width: 52, height: 52}); + } + var edges = jsPlumb.getAllConnections(); + for (var i = 0; i < edges.length; i++) { + var c = edges[i]; + g.setEdge(c.source.id,c.target.id ); + } + // calculate the layout (i.e. node positions) + dagre.layout(g); + + // Applying the calculated layout + g.nodes().forEach(function(v) { + $("#" + v).css("left", g.node(v).x + "px"); + $("#" + v).css("top", g.node(v).y + "px"); + }); + jsPlumb.repaintEverything(); +} +//add group to editor +var cartridgeCounter =0; +//add group to editor +function addJsplumbGroup(groupJSON, cartridgeCounter){ + + var divRoot = $('
').attr({'id':cartridgeCounter+'-'+groupJSON.alias,'data-type':'group','data-ctype':groupJSON.alias}) + .text(groupJSON.alias) + .addClass('input-false') + .addClass('stepnode') + .attr('data-toggle', 'tooltip') + .attr('title',groupJSON.alias ) + .appendTo('#whiteboard'); + jsPlumb.addEndpoint($(divRoot), { + anchor:"BottomCenter" + }, bottomConnectorOptions); + + DragEl($(divRoot)); + if(groupJSON['components']['cartridges']) { + genJsplumbCartridge(groupJSON['components']['cartridges'], divRoot, groupJSON.alias); + } + if(groupJSON['components']['groups']){ + genJsplumbGroups(groupJSON['components']['groups'], divRoot, groupJSON.alias); + } + + function genJsplumbCartridge(item, currentParent, parentName){ + for (var prop in item) { + var id = item[prop].type; + var divCartridge = $('
').attr({'id':cartridgeCounter+'-'+parentName+'-'+item[prop].type, 'data-type':'cartridge', + 'data-calias':item[prop]['subscribableInfo']['alias']} ) + .text(item[prop].type) + .addClass('input-false') + .addClass('stepnode') + .attr('data-toggle', 'tooltip') + .attr('title',item[prop].type ) + .appendTo('#whiteboard'); + $(divCartridge).append('
'); + jsPlumb.addEndpoint($(divCartridge), { + anchor: "TopCenter" + }, generatedCartridgeEndpointOptions); + + //add connection options + jsPlumb.connect({ + source:$(currentParent), + target:$(divCartridge), + paintStyle:{strokeStyle:"blue", lineWidth:1 }, + Connector : [ "Bezier", { curviness:63 } ], + anchors:["BottomCenter", "TopCenter"], + endpoint:"Dot" + }); + + DragEl($(divCartridge)); + } + } + + function genJsplumbGroups(item, currentParent, parentName) { + for (var prop in item) { + var divGroup = $('
').attr({'id':cartridgeCounter+'-'+parentName+'-'+item[prop]['name'],'data-type':'group','data-ctype':item[prop]['name'] }) + .text(item[prop]['name']) + .addClass('stepnode') + .attr('data-toggle', 'tooltip') + .attr('title',item[prop]['name'] ) + .addClass('input-false') + .appendTo('#whiteboard'); + //$(divGroup).append('
'); + jsPlumb.addEndpoint($(divGroup), { + anchor:"BottomCenter" + }, bottomConnectorOptions); + + jsPlumb.addEndpoint($(divGroup), { + anchor: "TopCenter" + }, generatedGroupOptions); + + //add connection options + jsPlumb.connect({ + source:$(currentParent), + target:$(divGroup), + paintStyle:{strokeStyle:"blue", lineWidth:1 }, + Connector : [ "Bezier", { curviness:63 } ], + anchors:["BottomCenter", "TopCenter"], + endpoint:"Dot" + }); + + DragEl($(divGroup)); + + if(item[prop].hasOwnProperty('cartridges')) { + genJsplumbCartridge(item[prop].cartridges, divGroup, parentName+'-'+item[prop]['name'] ); + } + if(item[prop].hasOwnProperty('groups')) { + genJsplumbGroups(item[prop].groups, divGroup, parentName+'-'+item[prop]['name']) + } + } + } + + + +} + + +jsPlumb.bind("ready", function() { + addJsplumbGroup(applicationJSON, cartridgeCounter); + //reposition after group add + dagrePosition(); +}); + + +var signupBlockTemplate = { + "$schema": "http://json-schema.org/draft-04/schema#", + "id": "root", + "type": "object", + "title": " ", + "options": { + "disable_properties": true, + "disable_collapse": true + }, + "properties": { + "alias": { + "id": "root/alias", + "title": "Cartridge Alias: ", + "type": "string" + }, + "privateRepo": { + "id": "root/privateRepo", + "title": "Is private repository: ", + "type": "boolean" + }, + "repoUrl": { + "id": "root/repoUrl", + "title": "Repository URL: ", + "type": "string" + }, + "repoUsername": { + "id": "root/repoUsername", + "title": "Repository User Name: ", + "type": "string" + }, + "repoPassword": { + "id": "root/repoPassword", + "title": "Repository Password: ", + "type": "string" + } + } +}; + +var signupBlockDefault = { + "alias": "php", + "privateRepo": false, + "repoUrl": "https://github.com/imesh/stratos-php-applications.git", + "repoUsername": "", + "repoPassword": "" +}; + + +// Document ready events +$(document).ready(function(){ + //handled Ajax base session expire issue + $(document).ajaxError(function (e, xhr, settings) { + window.location.href = '../'; + }); + + //*******************Adding JSON editor *************// + JSONEditor.defaults.theme = 'bootstrap3'; + JSONEditor.defaults.iconlib = 'fontawesome4'; + JSONEditor.defaults.show_errors = "always"; + var editor,blockId; + + $('#whiteboard').on('click', '.stepnode', function(){ + $('.signup-details').show(); + $('.signup-default').hide(); + $('.stepnode').removeClass("highlightme"); + $(this).addClass('highlightme'); + tabData($(this)); + }); + + function tabData(node){ + + blockId = node.attr('id'); + var blockType = node.attr('data-type'); + var startval; + var calias = node.attr('data-calias'); + + if(blockType == 'cartridge'){ + startval = signupBlockDefault; + startval['alias'] = calias; + } + + if(node.attr('data-generated')) { + startval = JSON.parse(decodeURIComponent(node.attr('data-generated'))); + } + $('#signup-details').html(''); + + switch (blockType){ + case 'cartridge': + generateHtmlBlock(signupBlockTemplate, startval); + break; + } + } + + function generateHtmlBlock(schema, startval){ + // Initialize the editor + editor = new JSONEditor(document.getElementById('signup-details'), { + ajax: false, + disable_edit_json: true, + schema: schema, + format: "grid", + startval: startval + }); + + if(editor.getEditor('root.alias')){ + editor.getEditor('root.alias').disable(); + } + + } + + + //get component JSON data + $('#component-info-update').on('click', function(){ + $('#'+blockId).attr('data-generated', encodeURIComponent(JSON.stringify(editor.getValue()))); + $('#'+blockId).removeClass('input-false'); + $('#'+blockId).find('div>i').removeClass('fa-exclamation-circle').addClass('fa-check-circle-o').css('color','#2ecc71'); + }); + + + $('#signup').on('click', function(){ + var btn = $(this); + var appid = btn.attr('data-appid'); + var signupJSON = {"artifactRepositories":[]}; + //generate raw data tree from connections + $.each(jsPlumb.getConnections(), function (idx, connection) { + var dataGen = $('#'+connection.targetId).attr('data-generated'); + if(dataGen!=undefined){ + var jsonContent = JSON.parse(decodeURIComponent(dataGen)); + signupJSON['artifactRepositories'].push(jsonContent); + } + + }); + + var formtype = 'signupapplication'; + btn.html(" Adding..."); + $.ajax({ + type: "POST", + url: caramel.context + "/controllers/applications/application_requests.jag", + dataType: 'json', + data: { "formPayload": JSON.stringify(signupJSON), "formtype": formtype, "applicationId": appid }, + success: function (data) { + if (data.status == 'error') { + var n = noty({text: data.message, layout: 'bottomRight', type: 'error'}); + } else if (data.status == 'warning') { + var n = noty({text: data.message, layout: 'bottomRight', type: 'warning'}); + } else { + var n = noty({text: data.message, layout: 'bottomRight', type: 'success'}); + window.setTimeout(function(){ + window.location.href = '../'; + }, 1500); + } + } + }) + .always(function () { + btn.html('Add Signup'); + }); + + }); + + + +}); \ No newline at end of file diff --git a/components/org.apache.stratos.manager.console/console/themes/theme0/partials/applications_form.hbs b/components/org.apache.stratos.manager.console/console/themes/theme0/partials/applications_form.hbs index 0c72fb93d4..d5b433cbb1 100644 --- a/components/org.apache.stratos.manager.console/console/themes/theme0/partials/applications_form.hbs +++ b/components/org.apache.stratos.manager.console/console/themes/theme0/partials/applications_form.hbs @@ -123,6 +123,14 @@ id="details_list_{{applicationId}}" data-url="{{url ""}}/applications/{{applicationId}}/" > View + {{#if multiTenant}} + {{#unless signUpsExist}} + + {{/unless}} + {{/if}}
@@ -132,7 +140,14 @@ id="details_{{applicationId}}" data-url="{{url ""}}/applications/{{applicationId}}/" > View - + {{#if multiTenant}} + {{#unless signUpsExist}} + + {{/unless}} + {{/if}}
{{else}}