Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
merge with apache master
Browse files Browse the repository at this point in the history
  • Loading branch information
asankasan committed Aug 17, 2015
2 parents 4862b29 + d45bd6e commit fe0622a
Show file tree
Hide file tree
Showing 1,624 changed files with 14,991 additions and 100,562 deletions.
2 changes: 1 addition & 1 deletion components/org.apache.stratos.autoscaler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.stratos</groupId>
<artifactId>stratos-components-parent</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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<String, String> 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();

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -236,23 +252,7 @@ public Set<ScalingDependentList> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,6 @@ public List<ApplicationChildContext> findAllChildrenOfAppContext() {
allChildrenOfAppContext);
}

public void setTerminationBehavior(TerminationBehavior terminationBehavior) {
this.terminationBehavior = terminationBehavior;
}

public boolean isTerminateDependent() {
return this.getTerminationBehavior() == TerminationBehavior.TERMINATE_DEPENDENT;
}
Expand All @@ -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() {
Expand Down Expand Up @@ -281,4 +276,8 @@ private void buildTreeStructure(ApplicationChildContext applicationChildContext,
}
}
}

public enum TerminationBehavior {
TERMINATE_ALL, TERMINATE_NONE, TERMINATE_DEPENDENT
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClusterStatus> statusLifeCycle;
private List<ApplicationChildContext> applicationChildContextList;
private ApplicationChildContext parent;

protected boolean hasStartupDependents;
protected boolean isGroupScalingEnabled;

public ApplicationChildContext(String id, boolean killDependent) {
applicationChildContextList = new ArrayList<ApplicationChildContext>();
statusLifeCycle = new Stack<ClusterStatus>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ApplicationClusterContext> applicationClusterContexts;
Expand All @@ -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,
Expand Down Expand Up @@ -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()));
}

Expand Down Expand Up @@ -235,7 +258,6 @@ private Map<String, SubscribableInfoContext> getSubscribableInformation(Applicat
return subscribableInfoContextMap;
}


/**
* Builds the Application structure
*
Expand Down Expand Up @@ -334,7 +356,6 @@ private Application buildCompositeAppStructure(ApplicationContext applicationCon
return application;
}


/**
* Parse Subscription Information
*
Expand Down Expand Up @@ -455,7 +476,7 @@ private Map<String, Map<String, ClusterDataHolder>> 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());
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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()) {
Expand Down
Loading

0 comments on commit fe0622a

Please sign in to comment.