You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2015/07/23 14:18:43 UTC
[01/18] stratos git commit: Metering Service Implementation
Repository: stratos
Updated Branches:
refs/heads/master 00ed5fa8e -> 9ceab963b
http://git-wip-us.apache.org/repos/asf/stratos/blob/2fd289b8/service-stubs/org.apache.stratos.cloud.controller.service.stub/src/main/resources/CloudControllerService.wsdl
----------------------------------------------------------------------
diff --git a/service-stubs/org.apache.stratos.cloud.controller.service.stub/src/main/resources/CloudControllerService.wsdl b/service-stubs/org.apache.stratos.cloud.controller.service.stub/src/main/resources/CloudControllerService.wsdl
index 03abeb0..5499a5f 100644
--- a/service-stubs/org.apache.stratos.cloud.controller.service.stub/src/main/resources/CloudControllerService.wsdl
+++ b/service-stubs/org.apache.stratos.cloud.controller.service.stub/src/main/resources/CloudControllerService.wsdl
@@ -1,66 +1,89 @@
-<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="http://impl.services.controller.cloud.stratos.apache.org" xmlns:ax27="http://kubernetes.domain.controller.cloud.stratos.apache.org/xsd" xmlns:ax23="http://domain.controller.cloud.stratos.apache.org/xsd" xmlns:ax24="http://common.stratos.apache.org/xsd" xmlns:ax21="http://exception.controller.cloud.stratos.apache.org/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ax212="http://topology.domain.messaging.stratos.apache.org/xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:ax210="http://domain.common.stratos.apache.org/xsd" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://impl.services.controller.cloud.stratos.apache.org">
+<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ax29="http://kubernetes.domain.controller.cloud.stratos.apache.org/xsd" xmlns:ns="http://impl.services.controller.cloud.stratos.apache.org" xmlns:ax27="http://domain.common.stratos.apache.org/xsd" xmlns:ax23="http://domain.controller.cloud.stratos.apache.org/xsd" xmlns:ax24="http://common.stratos.apache.org/xsd" xmlns:ax21="http://exception.controller.cloud.stratos.apache.org/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ax212="http://topology.domain.messaging.stratos.apache.org/xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://impl.services.controller.cloud.stratos.apache.org">
<wsdl:types>
- <xs:schema xmlns:ax29="http://kubernetes.domain.controller.cloud.stratos.apache.org/xsd" xmlns:ax213="http://topology.domain.messaging.stratos.apache.org/xsd" xmlns:ax26="http://domain.controller.cloud.stratos.apache.org/xsd" xmlns:ax22="http://exception.controller.cloud.stratos.apache.org/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://impl.services.controller.cloud.stratos.apache.org">
+ <xs:schema xmlns:ax213="http://topology.domain.messaging.stratos.apache.org/xsd" xmlns:ax26="http://domain.controller.cloud.stratos.apache.org/xsd" xmlns:ax211="http://kubernetes.domain.controller.cloud.stratos.apache.org/xsd" xmlns:ax22="http://exception.controller.cloud.stratos.apache.org/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://impl.services.controller.cloud.stratos.apache.org">
<xs:import namespace="http://exception.controller.cloud.stratos.apache.org/xsd"/>
<xs:import namespace="http://domain.controller.cloud.stratos.apache.org/xsd"/>
<xs:import namespace="http://kubernetes.domain.controller.cloud.stratos.apache.org/xsd"/>
<xs:import namespace="http://topology.domain.messaging.stratos.apache.org/xsd"/>
- <xs:element name="getIaasProviders">
+ <xs:element name="CloudControllerServiceCartridgeNotFoundException">
<xs:complexType>
- <xs:sequence/>
+ <xs:sequence>
+ <xs:element minOccurs="0" name="CartridgeNotFoundException" nillable="true" type="ax21:CartridgeNotFoundException"/>
+ </xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="getIaasProvidersResponse">
+ <xs:element name="CloudControllerServiceInvalidIaasProviderException">
<xs:complexType>
<xs:sequence>
- <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="InvalidIaasProviderException" nillable="true" type="ax21:InvalidIaasProviderException"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="getCartridges">
+ <xs:element name="CloudControllerServiceCloudControllerException">
<xs:complexType>
- <xs:sequence/>
+ <xs:sequence>
+ <xs:element minOccurs="0" name="CloudControllerException" nillable="true" type="ax21:CloudControllerException"/>
+ </xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="getCartridgesResponse">
+ <xs:element name="startInstance">
<xs:complexType>
<xs:sequence>
- <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="instanceContext" nillable="true" type="ax26:InstanceContext"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="CloudControllerServiceCartridgeNotFoundException">
+ <xs:element name="startInstanceResponse">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="CartridgeNotFoundException" nillable="true" type="ax21:CartridgeNotFoundException"/>
+ <xs:element minOccurs="0" name="return" nillable="true" type="ax26:MemberContext"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="getCartridge">
+ <xs:element name="CloudControllerServiceInvalidMemberException">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="cartridgeType" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="InvalidMemberException" nillable="true" type="ax21:InvalidMemberException"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="getCartridgeResponse">
+ <xs:element name="CloudControllerServiceInvalidCartridgeTypeException">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="return" nillable="true" type="ax26:Cartridge"/>
+ <xs:element minOccurs="0" name="InvalidCartridgeTypeException" nillable="true" type="ax21:InvalidCartridgeTypeException"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="CloudControllerServiceInvalidCartridgeDefinitionException">
+ <xs:element name="terminateInstance">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="InvalidCartridgeDefinitionException" nillable="true" type="ax21:InvalidCartridgeDefinitionException"/>
+ <xs:element minOccurs="0" name="memberId" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="CloudControllerServiceInvalidIaasProviderException">
+ <xs:element name="terminateInstanceResponse">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="InvalidIaasProviderException" nillable="true" type="ax21:InvalidIaasProviderException"/>
+ <xs:element minOccurs="0" name="return" type="xs:boolean"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="getIaasProviders">
+ <xs:complexType>
+ <xs:sequence/>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="getIaasProvidersResponse">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="CloudControllerServiceInvalidCartridgeDefinitionException">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element minOccurs="0" name="InvalidCartridgeDefinitionException" nillable="true" type="ax21:InvalidCartridgeDefinitionException"/>
</xs:sequence>
</xs:complexType>
</xs:element>
@@ -160,13 +183,6 @@
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="CloudControllerServiceInvalidCartridgeTypeException">
- <xs:complexType>
- <xs:sequence>
- <xs:element minOccurs="0" name="InvalidCartridgeTypeException" nillable="true" type="ax21:InvalidCartridgeTypeException"/>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
<xs:element name="removeCartridge">
<xs:complexType>
<xs:sequence>
@@ -265,6 +281,18 @@
</xs:sequence>
</xs:complexType>
</xs:element>
+ <xs:element name="getCartridges">
+ <xs:complexType>
+ <xs:sequence/>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="getCartridgesResponse">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
<xs:element name="CloudControllerServiceNonExistingKubernetesClusterException">
<xs:complexType>
<xs:sequence>
@@ -375,45 +403,17 @@
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="CloudControllerServiceCloudControllerException">
- <xs:complexType>
- <xs:sequence>
- <xs:element minOccurs="0" name="CloudControllerException" nillable="true" type="ax21:CloudControllerException"/>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- <xs:element name="startInstance">
- <xs:complexType>
- <xs:sequence>
- <xs:element minOccurs="0" name="instanceContext" nillable="true" type="ax26:InstanceContext"/>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- <xs:element name="startInstanceResponse">
- <xs:complexType>
- <xs:sequence>
- <xs:element minOccurs="0" name="return" nillable="true" type="ax26:MemberContext"/>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- <xs:element name="CloudControllerServiceInvalidMemberException">
- <xs:complexType>
- <xs:sequence>
- <xs:element minOccurs="0" name="InvalidMemberException" nillable="true" type="ax21:InvalidMemberException"/>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- <xs:element name="terminateInstance">
+ <xs:element name="getCartridge">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="memberId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="cartridgeType" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="terminateInstanceResponse">
+ <xs:element name="getCartridgeResponse">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="return" type="xs:boolean"/>
+ <xs:element minOccurs="0" name="return" nillable="true" type="ax26:Cartridge"/>
</xs:sequence>
</xs:complexType>
</xs:element>
@@ -480,116 +480,116 @@
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="validateDeploymentPolicyNetworkPartition">
+ <xs:element name="startInstances">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="cartridgeType" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="networkPartitionId" nillable="true" type="xs:string"/>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="instanceContexts" nillable="true" type="ax26:InstanceContext"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="validateDeploymentPolicyNetworkPartitionResponse">
+ <xs:element name="startInstancesResponse">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="return" type="xs:boolean"/>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ax26:MemberContext"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="registerService">
+ <xs:element name="terminateInstanceForcefully">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="registrant" nillable="true" type="ax26:Registrant"/>
+ <xs:element minOccurs="0" name="memberId" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="registerServiceResponse">
+ <xs:element name="terminateInstanceForcefullyResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="startInstances">
+ <xs:element name="CloudControllerServiceInvalidClusterException">
<xs:complexType>
<xs:sequence>
- <xs:element maxOccurs="unbounded" minOccurs="0" name="instanceContexts" nillable="true" type="ax26:InstanceContext"/>
+ <xs:element minOccurs="0" name="InvalidClusterException" nillable="true" type="ax21:InvalidClusterException"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="startInstancesResponse">
+ <xs:element name="terminateInstances">
<xs:complexType>
<xs:sequence>
- <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ax26:MemberContext"/>
+ <xs:element minOccurs="0" name="clusterId" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="terminateInstanceForcefully">
+ <xs:element name="terminateInstancesResponse">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="memberId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="terminateInstanceForcefullyResponse">
+ <xs:element name="registerService">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="return" type="xs:boolean"/>
+ <xs:element minOccurs="0" name="registrant" nillable="true" type="ax26:Registrant"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="CloudControllerServiceInvalidClusterException">
+ <xs:element name="registerServiceResponse">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="InvalidClusterException" nillable="true" type="ax21:InvalidClusterException"/>
+ <xs:element minOccurs="0" name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="terminateInstances">
+ <xs:element name="CloudControllerServiceUnregisteredClusterException">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="clusterId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="UnregisteredClusterException" nillable="true" type="ax21:UnregisteredClusterException"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="terminateInstancesResponse">
+ <xs:element name="unregisterService">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="return" type="xs:boolean"/>
+ <xs:element minOccurs="0" name="clusterId" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="updateClusterStatus">
+ <xs:element name="unregisterServiceResponse">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="serviceName" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="clusterId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="instanceId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="status" nillable="true" type="ax212:ClusterStatus"/>
+ <xs:element minOccurs="0" name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="updateClusterStatusResponse">
+ <xs:element name="validateDeploymentPolicyNetworkPartition">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="return" type="xs:boolean"/>
+ <xs:element minOccurs="0" name="cartridgeType" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="networkPartitionId" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="CloudControllerServiceUnregisteredClusterException">
+ <xs:element name="validateDeploymentPolicyNetworkPartitionResponse">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="UnregisteredClusterException" nillable="true" type="ax21:UnregisteredClusterException"/>
+ <xs:element minOccurs="0" name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="unregisterService">
+ <xs:element name="updateClusterStatus">
<xs:complexType>
<xs:sequence>
+ <xs:element minOccurs="0" name="serviceName" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="clusterId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="instanceId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="status" nillable="true" type="ax212:ClusterStatus"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="unregisterServiceResponse">
+ <xs:element name="updateClusterStatusResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:boolean"/>
@@ -694,42 +694,42 @@
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="updateKubernetesHost">
+ <xs:element name="CloudControllerServiceInvalidKubernetesMasterException">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="kubernetesHost" nillable="true" type="ax29:KubernetesHost"/>
+ <xs:element minOccurs="0" name="InvalidKubernetesMasterException" nillable="true" type="ax21:InvalidKubernetesMasterException"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="updateKubernetesHostResponse">
+ <xs:element name="CloudControllerServiceNonExistingKubernetesMasterException">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="return" type="xs:boolean"/>
+ <xs:element minOccurs="0" name="NonExistingKubernetesMasterException" nillable="true" type="ax21:NonExistingKubernetesMasterException"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="CloudControllerServiceInvalidKubernetesMasterException">
+ <xs:element name="updateKubernetesMaster">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="InvalidKubernetesMasterException" nillable="true" type="ax21:InvalidKubernetesMasterException"/>
+ <xs:element minOccurs="0" name="kubernetesMaster" nillable="true" type="ax29:KubernetesMaster"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="CloudControllerServiceNonExistingKubernetesMasterException">
+ <xs:element name="updateKubernetesMasterResponse">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="NonExistingKubernetesMasterException" nillable="true" type="ax21:NonExistingKubernetesMasterException"/>
+ <xs:element minOccurs="0" name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="updateKubernetesMaster">
+ <xs:element name="updateKubernetesHost">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="kubernetesMaster" nillable="true" type="ax29:KubernetesMaster"/>
+ <xs:element minOccurs="0" name="kubernetesHost" nillable="true" type="ax29:KubernetesHost"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="updateKubernetesMasterResponse">
+ <xs:element name="updateKubernetesHostResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:boolean"/>
@@ -781,12 +781,29 @@
<xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
- <xs:complexType name="InvalidCartridgeDefinitionException">
+ <xs:complexType name="InvalidIaasProviderException">
<xs:sequence>
<xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
- <xs:complexType name="InvalidIaasProviderException">
+ <xs:complexType name="CloudControllerException">
+ <xs:complexContent>
+ <xs:extension base="xs:RuntimeException">
+ <xs:sequence/>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+ <xs:complexType name="InvalidMemberException">
+ <xs:sequence>
+ <xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="InvalidCartridgeTypeException">
+ <xs:sequence>
+ <xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="InvalidCartridgeDefinitionException">
<xs:sequence>
<xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
</xs:sequence>
@@ -807,11 +824,6 @@
<xs:complexType name="NetworkPartitionNotExistsException">
<xs:sequence/>
</xs:complexType>
- <xs:complexType name="InvalidCartridgeTypeException">
- <xs:sequence>
- <xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
- </xs:sequence>
- </xs:complexType>
<xs:complexType name="CartridgeDefinitionNotExistsException">
<xs:sequence>
<xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
@@ -842,18 +854,6 @@
<xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
- <xs:complexType name="CloudControllerException">
- <xs:complexContent>
- <xs:extension base="xs:RuntimeException">
- <xs:sequence/>
- </xs:extension>
- </xs:complexContent>
- </xs:complexType>
- <xs:complexType name="InvalidMemberException">
- <xs:sequence>
- <xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
- </xs:sequence>
- </xs:complexType>
<xs:complexType name="InvalidPartitionException">
<xs:sequence>
<xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
@@ -895,31 +895,16 @@
</xs:sequence>
</xs:complexType>
</xs:schema>
- <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://domain.common.stratos.apache.org/xsd">
- <xs:complexType name="NameValuePair">
- <xs:sequence>
- <xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="value" nillable="true" type="xs:string"/>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="LoadBalancingIPType">
- <xs:complexContent>
- <xs:extension base="xs:Enum">
- <xs:sequence/>
- </xs:extension>
- </xs:complexContent>
- </xs:complexType>
- </xs:schema>
- <xs:schema xmlns:ax28="http://common.stratos.apache.org/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://kubernetes.domain.controller.cloud.stratos.apache.org/xsd">
+ <xs:schema xmlns:ax210="http://common.stratos.apache.org/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://kubernetes.domain.controller.cloud.stratos.apache.org/xsd">
<xs:import namespace="http://common.stratos.apache.org/xsd"/>
<xs:complexType name="KubernetesCluster">
<xs:sequence>
<xs:element minOccurs="0" name="clusterId" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="description" nillable="true" type="xs:string"/>
- <xs:element maxOccurs="unbounded" minOccurs="0" name="kubernetesHosts" nillable="true" type="ax27:KubernetesHost"/>
- <xs:element minOccurs="0" name="kubernetesMaster" nillable="true" type="ax27:KubernetesMaster"/>
- <xs:element minOccurs="0" name="portRange" nillable="true" type="ax27:PortRange"/>
- <xs:element minOccurs="0" name="properties" nillable="true" type="ax28:Properties"/>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="kubernetesHosts" nillable="true" type="ax29:KubernetesHost"/>
+ <xs:element minOccurs="0" name="kubernetesMaster" nillable="true" type="ax29:KubernetesMaster"/>
+ <xs:element minOccurs="0" name="portRange" nillable="true" type="ax29:PortRange"/>
+ <xs:element minOccurs="0" name="properties" nillable="true" type="ax210:Properties"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="KubernetesHost">
@@ -927,13 +912,13 @@
<xs:element minOccurs="0" name="hostId" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="hostname" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="privateIPAddress" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="properties" nillable="true" type="ax28:Properties"/>
+ <xs:element minOccurs="0" name="properties" nillable="true" type="ax210:Properties"/>
<xs:element minOccurs="0" name="publicIPAddress" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="KubernetesMaster">
<xs:complexContent>
- <xs:extension base="ax27:KubernetesHost">
+ <xs:extension base="ax29:KubernetesHost">
<xs:sequence/>
</xs:extension>
</xs:complexContent>
@@ -945,9 +930,102 @@
</xs:sequence>
</xs:complexType>
</xs:schema>
- <xs:schema xmlns:ax25="http://common.stratos.apache.org/xsd" xmlns:ax211="http://domain.common.stratos.apache.org/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://domain.controller.cloud.stratos.apache.org/xsd">
+ <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://domain.common.stratos.apache.org/xsd">
+ <xs:complexType name="NameValuePair">
+ <xs:sequence>
+ <xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="value" nillable="true" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="LoadBalancingIPType">
+ <xs:complexContent>
+ <xs:extension base="xs:Enum">
+ <xs:sequence/>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+ </xs:schema>
+ <xs:schema xmlns:ax28="http://domain.common.stratos.apache.org/xsd" xmlns:ax25="http://common.stratos.apache.org/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://domain.controller.cloud.stratos.apache.org/xsd">
<xs:import namespace="http://common.stratos.apache.org/xsd"/>
<xs:import namespace="http://domain.common.stratos.apache.org/xsd"/>
+ <xs:complexType name="InstanceContext">
+ <xs:sequence>
+ <xs:element minOccurs="0" name="cartridgeType" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="clusterId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="clusterInstanceId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="initTime" type="xs:long"/>
+ <xs:element minOccurs="0" name="networkPartitionId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="obsoleteExpiryTime" type="xs:long"/>
+ <xs:element minOccurs="0" name="partition" nillable="true" type="ax23:Partition"/>
+ <xs:element minOccurs="0" name="properties" nillable="true" type="ax25:Properties"/>
+ <xs:element minOccurs="0" name="volumeRequired" type="xs:boolean"/>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="volumes" nillable="true" type="ax23:Volume"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="Partition">
+ <xs:sequence>
+ <xs:element minOccurs="0" name="description" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="id" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="isPublic" type="xs:boolean"/>
+ <xs:element minOccurs="0" name="kubernetesClusterId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="partitionMax" type="xs:int"/>
+ <xs:element minOccurs="0" name="properties" nillable="true" type="ax25:Properties"/>
+ <xs:element minOccurs="0" name="provider" nillable="true" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="Volume">
+ <xs:sequence>
+ <xs:element minOccurs="0" name="device" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="iaasType" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="id" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="mappingPath" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="removeOntermination" type="xs:boolean"/>
+ <xs:element minOccurs="0" name="size" type="xs:int"/>
+ <xs:element minOccurs="0" name="snapshotId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="volumeId" nillable="true" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="MemberContext">
+ <xs:sequence>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="allocatedIPs" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="applicationId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="cartridgeType" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="clusterId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="clusterInstanceId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="defaultPrivateIP" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="defaultPublicIP" nillable="true" type="xs:string"/>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="dynamicPayload" nillable="true" type="ax27:NameValuePair"/>
+ <xs:element minOccurs="0" name="initTime" type="xs:long"/>
+ <xs:element minOccurs="0" name="instanceId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="instanceMetadata" nillable="true" type="ax23:InstanceMetadata"/>
+ <xs:element minOccurs="0" name="kubernetesPodId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="kubernetesPodLabel" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="lbClusterId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="loadBalancingIPType" nillable="true" type="ax27:LoadBalancingIPType"/>
+ <xs:element minOccurs="0" name="memberId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="networkPartitionId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="obsoleteExpiryTime" type="xs:long"/>
+ <xs:element minOccurs="0" name="obsoleteInitTime" type="xs:long"/>
+ <xs:element minOccurs="0" name="partition" nillable="true" type="ax23:Partition"/>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="privateIPs" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="properties" nillable="true" type="ax25:Properties"/>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="publicIPs" nillable="true" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="InstanceMetadata">
+ <xs:sequence>
+ <xs:element minOccurs="0" name="cpu" type="xs:int"/>
+ <xs:element minOccurs="0" name="hostname" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="hypervisor" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="imageId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="loginPort" type="xs:int"/>
+ <xs:element minOccurs="0" name="operatingSystem64bit" type="xs:boolean"/>
+ <xs:element minOccurs="0" name="operatingSystemArchitecture" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="operatingSystemName" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="operatingSystemVersion" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="ram" type="xs:int"/>
+ </xs:sequence>
+ </xs:complexType>
<xs:complexType name="Cartridge">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="appTypeMappings" nillable="true" type="ax23:AppType"/>
@@ -1023,22 +1101,8 @@
<xs:element maxOccurs="unbounded" minOccurs="0" name="volumes" nillable="true" type="ax23:Volume"/>
</xs:sequence>
</xs:complexType>
- <xs:complexType name="Volume">
- <xs:sequence>
- <xs:element minOccurs="0" name="device" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="iaasType" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="id" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="mappingPath" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="removeOntermination" type="xs:boolean"/>
- <xs:element minOccurs="0" name="size" type="xs:int"/>
- <xs:element minOccurs="0" name="snapshotId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="volumeId" nillable="true" type="xs:string"/>
- </xs:sequence>
- </xs:complexType>
<xs:complexType name="PortMapping">
<xs:sequence>
- <xs:element minOccurs="0" name="kubernetesServicePort" type="xs:int"/>
- <xs:element minOccurs="0" name="kubernetesServicePortMapping" type="xs:boolean"/>
<xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="port" type="xs:int"/>
<xs:element minOccurs="0" name="protocol" nillable="true" type="xs:string"/>
@@ -1055,17 +1119,6 @@
<xs:element minOccurs="0" name="provider" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
- <xs:complexType name="Partition">
- <xs:sequence>
- <xs:element minOccurs="0" name="description" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="id" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="isPublic" type="xs:boolean"/>
- <xs:element minOccurs="0" name="kubernetesClusterId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="partitionMax" type="xs:int"/>
- <xs:element minOccurs="0" name="properties" nillable="true" type="ax25:Properties"/>
- <xs:element minOccurs="0" name="provider" nillable="true" type="xs:string"/>
- </xs:sequence>
- </xs:complexType>
<xs:complexType name="ServiceGroup">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="cartridges" nillable="true" type="xs:string"/>
@@ -1096,61 +1149,6 @@
<xs:element maxOccurs="unbounded" minOccurs="0" name="volumes" nillable="true" type="ax23:Volume"/>
</xs:sequence>
</xs:complexType>
- <xs:complexType name="InstanceContext">
- <xs:sequence>
- <xs:element minOccurs="0" name="cartridgeType" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="clusterId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="clusterInstanceId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="initTime" type="xs:long"/>
- <xs:element minOccurs="0" name="networkPartitionId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="obsoleteExpiryTime" type="xs:long"/>
- <xs:element minOccurs="0" name="partition" nillable="true" type="ax23:Partition"/>
- <xs:element minOccurs="0" name="properties" nillable="true" type="ax25:Properties"/>
- <xs:element minOccurs="0" name="volumeRequired" type="xs:boolean"/>
- <xs:element maxOccurs="unbounded" minOccurs="0" name="volumes" nillable="true" type="ax23:Volume"/>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="MemberContext">
- <xs:sequence>
- <xs:element maxOccurs="unbounded" minOccurs="0" name="allocatedIPs" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="applicationId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="cartridgeType" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="clusterId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="clusterInstanceId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="defaultPrivateIP" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="defaultPublicIP" nillable="true" type="xs:string"/>
- <xs:element maxOccurs="unbounded" minOccurs="0" name="dynamicPayload" nillable="true" type="ax210:NameValuePair"/>
- <xs:element minOccurs="0" name="initTime" type="xs:long"/>
- <xs:element minOccurs="0" name="instanceId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="instanceMetadata" nillable="true" type="ax23:InstanceMetadata"/>
- <xs:element minOccurs="0" name="kubernetesPodId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="kubernetesPodLabel" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="lbClusterId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="loadBalancingIPType" nillable="true" type="ax210:LoadBalancingIPType"/>
- <xs:element minOccurs="0" name="memberId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="networkPartitionId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="obsoleteExpiryTime" type="xs:long"/>
- <xs:element minOccurs="0" name="obsoleteInitTime" type="xs:long"/>
- <xs:element minOccurs="0" name="partition" nillable="true" type="ax23:Partition"/>
- <xs:element maxOccurs="unbounded" minOccurs="0" name="privateIPs" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="properties" nillable="true" type="ax25:Properties"/>
- <xs:element maxOccurs="unbounded" minOccurs="0" name="publicIPs" nillable="true" type="xs:string"/>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="InstanceMetadata">
- <xs:sequence>
- <xs:element minOccurs="0" name="cpu" type="xs:int"/>
- <xs:element minOccurs="0" name="hostname" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="hypervisor" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="imageId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="loginPort" type="xs:int"/>
- <xs:element minOccurs="0" name="operatingSystem64bit" type="xs:boolean"/>
- <xs:element minOccurs="0" name="operatingSystemArchitecture" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="operatingSystemName" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="operatingSystemVersion" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="ram" type="xs:int"/>
- </xs:sequence>
- </xs:complexType>
<xs:complexType name="Registrant">
<xs:sequence>
<xs:element minOccurs="0" name="autoScalerPolicyName" nillable="true" type="xs:string"/>
@@ -3136,4 +3134,4 @@
<http:address location="http://localhost:8080/axis2/services/CloudControllerService"/>
</wsdl:port>
</wsdl:service>
-</wsdl:definitions>
+</wsdl:definitions>
\ No newline at end of file
[16/18] stratos git commit: Formatting the code
Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/218b5fdc/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java
----------------------------------------------------------------------
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 802dfc8..618f2f9 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
@@ -52,997 +52,997 @@ import java.util.*;
* and build the complete topology with the events received
*/
public class TopologyBuilder {
- private static final Log log = LogFactory.getLog(TopologyBuilder.class);
-
- public static void handleServiceCreated(List<Cartridge> cartridgeList) {
- Service service;
- Topology topology = TopologyManager.getTopology();
- if (cartridgeList == null) {
- log.warn(String.format("Cartridge list is empty"));
- return;
- }
-
- try {
-
- TopologyManager.acquireWriteLock();
- for (Cartridge cartridge : cartridgeList) {
- if (!topology.serviceExists(cartridge.getType())) {
- ServiceType serviceType =
- cartridge.isMultiTenant() ? ServiceType.MultiTenant : ServiceType.SingleTenant;
- service = new Service(cartridge.getType(), serviceType);
- Properties properties = new Properties();
-
- try {
- Property[] propertyArray = null;
-
- if (cartridge.getProperties() != null) {
- if (cartridge.getProperties().getProperties() != null) {
- propertyArray = cartridge.getProperties().getProperties();
- }
- }
-
- List<Property> propertyList = new ArrayList<Property>();
- if (propertyArray != null) {
- propertyList = Arrays.asList(propertyArray);
- if (propertyList != null) {
- for (Property property : propertyList) {
- properties.setProperty(property.getName(), property.getValue());
- }
- }
- }
- } catch (Exception e) {
- log.error(e);
- }
-
- service.setProperties(properties);
- if (cartridge.getPortMappings() != null) {
- List<PortMapping> portMappings = Arrays.asList(cartridge.getPortMappings());
- Port port;
- //adding ports to the event
- for (PortMapping portMapping : portMappings) {
- port = new Port(portMapping.getProtocol(), portMapping.getPort(),
- portMapping.getProxyPort());
- service.addPort(port);
- }
- }
-
- topology.addService(service);
- TopologyManager.updateTopology(topology);
- }
- }
- } finally {
- TopologyManager.releaseWriteLock();
- }
- TopologyEventPublisher.sendServiceCreateEvent(cartridgeList);
- }
-
- public static void handleServiceRemoved(List<Cartridge> cartridgeList) {
- Topology topology = TopologyManager.getTopology();
-
- for (Cartridge cartridge : cartridgeList) {
- Service service = topology.getService(cartridge.getType());
- if (service == null) {
- log.warn("Cartridge does not exist [cartidge] " + cartridge);
- return;
- }
- if (service.getClusters().size() == 0) {
- if (topology.serviceExists(cartridge.getType())) {
- try {
- TopologyManager.acquireWriteLock();
- topology.removeService(cartridge.getType());
- TopologyManager.updateTopology(topology);
- } finally {
- TopologyManager.releaseWriteLock();
- }
- TopologyEventPublisher.sendServiceRemovedEvent(cartridgeList);
- } else {
- log.warn(String.format("Service %s does not exist..", cartridge.getType()));
- }
- } else {
- log.warn("Subscription already exists. Hence not removing the service:" + cartridge.getType() +
- " from the topology");
- }
- }
- }
-
- public static void handleClusterCreated(ClusterStatusClusterCreatedEvent event) {
- TopologyManager.acquireWriteLock();
- Cluster cluster;
-
- try {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(event.getServiceName());
- if (service == null) {
- log.error("Service " + event.getServiceName() +
- " not found in Topology, unable to update the cluster status to Created");
- return;
- }
-
- if (service.clusterExists(event.getClusterId())) {
- log.warn("Cluster " + event.getClusterId() + " is already in the Topology ");
- return;
- } else {
- cluster = new Cluster(event.getServiceName(), event.getClusterId(), event.getDeploymentPolicyName(),
- event.getAutosScalePolicyName(), event.getAppId());
- //cluster.setStatus(Status.Created);
- cluster.setHostNames(event.getHostNames());
- cluster.setTenantRange(event.getTenantRange());
- service.addCluster(cluster);
- TopologyManager.updateTopology(topology);
- }
- } finally {
- TopologyManager.releaseWriteLock();
- }
-
- TopologyEventPublisher.sendClusterCreatedEvent(cluster);
- }
-
- public static void handleApplicationClustersCreated(String appId, List<Cluster> appClusters) {
-
- TopologyManager.acquireWriteLock();
-
- try {
- Topology topology = TopologyManager.getTopology();
- for (Cluster cluster : appClusters) {
- Service service = topology.getService(cluster.getServiceName());
- if (service == null) {
- log.error("Service " + cluster.getServiceName() +
- " not found in Topology, unable to create Application cluster");
- } else {
- service.addCluster(cluster);
- log.info("Application Cluster " + cluster.getClusterId() + " created in CC topology");
- }
- }
- TopologyManager.updateTopology(topology);
- } finally {
- TopologyManager.releaseWriteLock();
- }
-
- log.debug("Creating cluster port mappings: [appication-id] " + appId);
- for (Cluster cluster : appClusters) {
- String cartridgeType = cluster.getServiceName();
- Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType);
- if (cartridge == null) {
- throw new CloudControllerException("Cartridge not found: [cartridge-type] " + cartridgeType);
- }
-
- for (PortMapping portMapping : cartridge.getPortMappings()) {
- ClusterPortMapping clusterPortMapping =
- new ClusterPortMapping(appId, cluster.getClusterId(), portMapping.getName(),
- portMapping.getProtocol(), portMapping.getPort(),
- portMapping.getProxyPort());
- CloudControllerContext.getInstance().addClusterPortMapping(clusterPortMapping);
- log.debug("Cluster port mapping created: " + clusterPortMapping.toString());
- }
- }
-
- // Persist cluster port mappings
- CloudControllerContext.getInstance().persist();
-
- // Send application clusters created event
- TopologyEventPublisher.sendApplicationClustersCreated(appId, appClusters);
- }
-
- public static void handleApplicationClustersRemoved(String appId, Set<ClusterDataHolder> clusterData) {
- TopologyManager.acquireWriteLock();
-
- List<Cluster> removedClusters = new ArrayList<Cluster>();
- CloudControllerContext context = CloudControllerContext.getInstance();
- try {
- Topology topology = TopologyManager.getTopology();
-
- if (clusterData != null) {
- // remove clusters from CC topology model and remove runtime information
- for (ClusterDataHolder aClusterData : clusterData) {
- Service aService = topology.getService(aClusterData.getServiceType());
- if (aService != null) {
- removedClusters.add(aService.removeCluster(aClusterData.getClusterId()));
- } else {
- log.warn("Service " + aClusterData.getServiceType() + " not found, " +
- "unable to remove Cluster " + aClusterData.getClusterId());
- }
- // remove runtime data
- context.removeClusterContext(aClusterData.getClusterId());
-
- log.info("Removed application [ " + appId + " ]'s Cluster " +
- "[ " + aClusterData.getClusterId() + " ] from the topology");
- }
- // persist runtime data changes
- CloudControllerContext.getInstance().persist();
- } else {
- log.info("No cluster data found for application " + appId + " to remove");
- }
-
- TopologyManager.updateTopology(topology);
-
- } finally {
- TopologyManager.releaseWriteLock();
- }
-
- // Remove cluster port mappings of application
- CloudControllerContext.getInstance().removeClusterPortMappings(appId);
- CloudControllerContext.getInstance().persist();
-
- TopologyEventPublisher.sendApplicationClustersRemoved(appId, clusterData);
-
- }
-
- public static void handleClusterReset(ClusterStatusClusterResetEvent event) {
- TopologyManager.acquireWriteLock();
-
- try {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(event.getServiceName());
- if (service == null) {
- log.error("Service " + event.getServiceName() +
- " not found in Topology, unable to update the cluster status to Created");
- return;
- }
-
- Cluster cluster = service.getCluster(event.getClusterId());
- if (cluster == null) {
- log.error("Cluster " + event.getClusterId() + " not found in Topology, unable to update " +
- "status to Created");
- return;
- }
-
- ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
- if (context == null) {
- log.warn("Cluster Instance Context is not found for [cluster] " +
- event.getClusterId() + " [instance-id] " +
- event.getInstanceId());
- return;
- }
- ClusterStatus status = ClusterStatus.Created;
- if (context.isStateTransitionValid(status)) {
- context.setStatus(status);
- log.info("Cluster Created adding status started for" + cluster.getClusterId());
- TopologyManager.updateTopology(topology);
- //publishing data
- TopologyEventPublisher
- .sendClusterResetEvent(event.getAppId(), event.getServiceName(), event.getClusterId(),
- event.getInstanceId());
- } else {
- log.warn(String.format("Cluster state transition is not valid: [cluster-id] %s " +
- " [instance-id] %s [current-status] %s [status-requested] %s",
- event.getClusterId(), event.getInstanceId(), context.getStatus(), status));
- }
-
- } finally {
- TopologyManager.releaseWriteLock();
- }
-
- }
-
- public static void handleClusterInstanceCreated(String serviceType, String clusterId, String alias,
- String instanceId, String partitionId, String networkPartitionId) {
-
- TopologyManager.acquireWriteLock();
-
- try {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(serviceType);
- if (service == null) {
- log.error("Service " + serviceType +
- " not found in Topology, unable to update the cluster status to Created");
- return;
- }
-
- Cluster cluster = service.getCluster(clusterId);
- if (cluster == null) {
- log.error("Cluster " + clusterId + " not found in Topology, unable to update " +
- "status to Created");
- return;
- }
-
- if (cluster.getInstanceContexts(instanceId) != null) {
- log.warn("The Instance context for the cluster already exists for [cluster] " +
- clusterId + " [instance-id] " + instanceId);
- return;
- }
-
- ClusterInstance clusterInstance = new ClusterInstance(alias, clusterId, instanceId);
- clusterInstance.setNetworkPartitionId(networkPartitionId);
- clusterInstance.setPartitionId(partitionId);
- cluster.addInstanceContext(instanceId, clusterInstance);
- TopologyManager.updateTopology(topology);
-
- ClusterInstanceCreatedEvent clusterInstanceCreatedEvent =
- new ClusterInstanceCreatedEvent(serviceType, clusterId, clusterInstance);
- clusterInstanceCreatedEvent.setPartitionId(partitionId);
- TopologyEventPublisher.sendClusterInstanceCreatedEvent(clusterInstanceCreatedEvent);
-
- } finally {
- TopologyManager.releaseWriteLock();
- }
- }
-
- public static void handleClusterRemoved(ClusterContext ctxt) {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(ctxt.getCartridgeType());
- String deploymentPolicy;
- if (service == null) {
- log.warn(String.format("Service %s does not exist", ctxt.getCartridgeType()));
- return;
- }
-
- if (!service.clusterExists(ctxt.getClusterId())) {
- log.warn(String.format("Cluster %s does not exist for service %s", ctxt.getClusterId(),
- ctxt.getCartridgeType()));
- return;
- }
-
- try {
- TopologyManager.acquireWriteLock();
- Cluster cluster = service.removeCluster(ctxt.getClusterId());
- deploymentPolicy = cluster.getDeploymentPolicyName();
- TopologyManager.updateTopology(topology);
- } finally {
- TopologyManager.releaseWriteLock();
- }
- TopologyEventPublisher.sendClusterRemovedEvent(ctxt, deploymentPolicy);
- }
-
- /**
- * Add member object to the topology and publish member created event
- *
- * @param memberContext
- */
- public static void handleMemberCreatedEvent(MemberContext memberContext) {
- Topology topology = TopologyManager.getTopology();
-
- Service service = topology.getService(memberContext.getCartridgeType());
- String clusterId = memberContext.getClusterId();
- Cluster cluster = service.getCluster(clusterId);
- String memberId = memberContext.getMemberId();
- String clusterInstanceId = memberContext.getClusterInstanceId();
- String networkPartitionId = memberContext.getNetworkPartitionId();
- String partitionId = memberContext.getPartition().getId();
- String lbClusterId = memberContext.getLbClusterId();
- long initTime = memberContext.getInitTime();
- String autoscalingReason =
- memberContext.getProperties().getProperty(StratosConstants.SCALING_REASON).getValue();
- long scalingTime =
- Long.parseLong(memberContext.getProperties().getProperty(StratosConstants.SCALING_TIME).getValue());
-
- if (cluster.memberExists(memberId)) {
- log.warn(String.format("Member %s already exists", memberId));
- return;
- }
-
- try {
- TopologyManager.acquireWriteLock();
- Member member =
- new Member(service.getServiceName(), clusterId, memberId, clusterInstanceId, networkPartitionId,
- partitionId, memberContext.getLoadBalancingIPType(), initTime);
- member.setStatus(MemberStatus.Created);
- member.setLbClusterId(lbClusterId);
- member.setProperties(CloudControllerUtil.toJavaUtilProperties(memberContext.getProperties()));
- cluster.addMember(member);
- TopologyManager.updateTopology(topology);
- //Member created time
- Long timeStamp = System.currentTimeMillis();
- //publishing to BAM
- BAMUsageDataPublisher.publish(memberContext.getMemberId(), memberContext.getPartition().getId(),
- memberContext.getNetworkPartitionId(), memberContext.getClusterId(),
- memberContext.getClusterInstanceId(), memberContext.getCartridgeType(),
- MemberStatus.Created.toString(), timeStamp, autoscalingReason, scalingTime,
- null);
- } finally {
- TopologyManager.releaseWriteLock();
- }
-
- TopologyEventPublisher.sendMemberCreatedEvent(memberContext);
- }
-
- /**
- * Update member status to initialized and publish member initialized event
- *
- * @param memberContext
- */
- public static void handleMemberInitializedEvent(MemberContext memberContext) {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(memberContext.getCartridgeType());
- if (service == null) {
- log.warn(String.format("Service %s does not exist", memberContext.getCartridgeType()));
- return;
- }
- if (!service.clusterExists(memberContext.getClusterId())) {
- log.warn(String.format("Cluster %s does not exist in service %s", memberContext.getClusterId(),
- memberContext.getCartridgeType()));
- return;
- }
-
- Member member = service.getCluster(memberContext.getClusterId()).
- getMember(memberContext.getMemberId());
- if (member == null) {
- log.warn(String.format("Member %s does not exist", memberContext.getMemberId()));
- return;
- }
-
- try {
- TopologyManager.acquireWriteLock();
-
- // Set ip addresses
- member.setDefaultPrivateIP(memberContext.getDefaultPrivateIP());
- if (memberContext.getPrivateIPs() != null) {
- member.setMemberPrivateIPs(Arrays.asList(memberContext.getPrivateIPs()));
- }
- member.setDefaultPublicIP(memberContext.getDefaultPublicIP());
- if (memberContext.getPublicIPs() != null) {
- member.setMemberPublicIPs(Arrays.asList(memberContext.getPublicIPs()));
- }
-
- // try update lifecycle state
- if (!member.isStateTransitionValid(MemberStatus.Initialized)) {
- log.error("Invalid state transition from " + member.getStatus() + " to " +
- MemberStatus.Initialized);
- return;
- } else {
- member.setStatus(MemberStatus.Initialized);
- log.info("Member status updated to initialized");
-
- TopologyManager.updateTopology(topology);
- //member initialized time
- Long timeStamp = System.currentTimeMillis();
-
- TopologyEventPublisher.sendMemberInitializedEvent(memberContext);
- //publishing data
- BAMUsageDataPublisher.publish(memberContext.getMemberId(), memberContext.getPartition().getId(),
- memberContext.getNetworkPartitionId(), memberContext.getClusterId(),
- memberContext.getClusterInstanceId(), memberContext.getCartridgeType(),
- MemberStatus.Initialized.toString(), timeStamp, null, null, null);
- }
- } finally {
- TopologyManager.releaseWriteLock();
- }
- }
-
- private static int findKubernetesServicePort(String clusterId, List<KubernetesService> kubernetesServices,
- PortMapping portMapping) {
- for (KubernetesService kubernetesService : kubernetesServices) {
- if (kubernetesService.getProtocol().equals(portMapping.getProtocol())) {
- return kubernetesService.getPort();
- }
- }
- throw new RuntimeException(
- "Kubernetes service port not found: [cluster-id] " + clusterId + " [port] " + portMapping.getPort());
- }
-
- public static void handleMemberStarted(InstanceStartedEvent instanceStartedEvent) {
- try {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(instanceStartedEvent.getServiceName());
- if (service == null) {
- log.warn(String.format("Service %s does not exist", instanceStartedEvent.getServiceName()));
- return;
- }
- if (!service.clusterExists(instanceStartedEvent.getClusterId())) {
- log.warn(String.format("Cluster %s does not exist in service %s", instanceStartedEvent.getClusterId(),
- instanceStartedEvent.getServiceName()));
- return;
- }
-
- Cluster cluster = service.getCluster(instanceStartedEvent.getClusterId());
- Member member = cluster.getMember(instanceStartedEvent.getMemberId());
- if (member == null) {
- log.warn(String.format("Member %s does not exist", instanceStartedEvent.getMemberId()));
- return;
- }
-
- try {
- TopologyManager.acquireWriteLock();
- // try update lifecycle state
- if (!member.isStateTransitionValid(MemberStatus.Starting)) {
- log.error("Invalid State Transition from " + member.getStatus() + " to " +
- MemberStatus.Starting);
- return;
- } else {
- member.setStatus(MemberStatus.Starting);
- log.info("member started event adding status started");
-
- TopologyManager.updateTopology(topology);
- //member starting time
- Long timeStamp = System.currentTimeMillis();
- //memberStartedEvent.
- TopologyEventPublisher.sendMemberStartedEvent(instanceStartedEvent);
- //publishing data
- BAMUsageDataPublisher
- .publish(instanceStartedEvent.getMemberId(), instanceStartedEvent.getPartitionId(),
- instanceStartedEvent.getNetworkPartitionId(), instanceStartedEvent.getClusterId(),
- instanceStartedEvent.getClusterInstanceId(), instanceStartedEvent.getServiceName(),
- MemberStatus.Starting.toString(), timeStamp, null, null, null);
- }
- } finally {
- TopologyManager.releaseWriteLock();
- }
- } catch (Exception e) {
- String message = String.format(
- "Could not handle member started event: [application-id] %s " + "[service-name] %s [member-id] %s",
- instanceStartedEvent.getApplicationId(), instanceStartedEvent.getServiceName(),
- instanceStartedEvent.getMemberId());
- log.warn(message, e);
- }
- }
-
- public static void handleMemberActivated(InstanceActivatedEvent instanceActivatedEvent) {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(instanceActivatedEvent.getServiceName());
- if (service == null) {
- log.warn(String.format("Service %s does not exist", instanceActivatedEvent.getServiceName()));
- return;
- }
-
- Cluster cluster = service.getCluster(instanceActivatedEvent.getClusterId());
- if (cluster == null) {
- log.warn(String.format("Cluster %s does not exist", instanceActivatedEvent.getClusterId()));
- return;
- }
-
- Member member = cluster.getMember(instanceActivatedEvent.getMemberId());
- if (member == null) {
- log.warn(String.format("Member %s does not exist", instanceActivatedEvent.getMemberId()));
- return;
- }
-
- MemberActivatedEvent memberActivatedEvent =
- new MemberActivatedEvent(instanceActivatedEvent.getServiceName(), instanceActivatedEvent.getClusterId(),
- instanceActivatedEvent.getClusterInstanceId(),
- instanceActivatedEvent.getMemberId(),
- instanceActivatedEvent.getNetworkPartitionId(),
- instanceActivatedEvent.getPartitionId());
-
- // grouping - set grouid
- //TODO
- memberActivatedEvent.setApplicationId(null);
- try {
- TopologyManager.acquireWriteLock();
- // try update lifecycle state
- if (!member.isStateTransitionValid(MemberStatus.Active)) {
- log.error(
- "Invalid state transition from [" + member.getStatus() + "] to [" + MemberStatus.Active + "]");
- return;
- } else {
- member.setStatus(MemberStatus.Active);
-
- // Set member ports
- try {
- Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(service.getServiceName());
- if (cartridge == null) {
- throw new RuntimeException(
- String.format("Cartridge not found: [cartridge-type] %s", service.getServiceName()));
- }
-
- Port port;
- int portValue;
- List<PortMapping> portMappings = Arrays.asList(cartridge.getPortMappings());
- String clusterId = cluster.getClusterId();
- ClusterContext clusterContext = CloudControllerContext.getInstance().getClusterContext(clusterId);
- List<KubernetesService> kubernetesServices = clusterContext.getKubernetesServices();
-
- for (PortMapping portMapping : portMappings) {
- if (kubernetesServices != null) {
- portValue = findKubernetesServicePort(clusterId, kubernetesServices, portMapping);
- } else {
- portValue = portMapping.getPort();
- }
- port = new Port(portMapping.getProtocol(), portValue, portMapping.getProxyPort());
- member.addPort(port);
- memberActivatedEvent.addPort(port);
- }
- } catch (Exception e) {
- String message = String.format("Could not add member ports: [service-name] %s [member-id] %s",
- memberActivatedEvent.getServiceName(),
- memberActivatedEvent.getMemberId());
- log.error(message, e);
- }
-
- // Set member ip addresses
- memberActivatedEvent.setDefaultPrivateIP(member.getDefaultPrivateIP());
- memberActivatedEvent.setMemberPrivateIPs(member.getMemberPrivateIPs());
- memberActivatedEvent.setDefaultPublicIP(member.getDefaultPublicIP());
- memberActivatedEvent.setMemberPublicIPs(member.getMemberPublicIPs());
- TopologyManager.updateTopology(topology);
-
- //member activated time
- Long timeStamp = System.currentTimeMillis();
-
- // Publish member activated event
- TopologyEventPublisher.sendMemberActivatedEvent(memberActivatedEvent);
-
- // Publish statistics data
- BAMUsageDataPublisher.publish(memberActivatedEvent.getMemberId(), memberActivatedEvent.getPartitionId(),
- memberActivatedEvent.getNetworkPartitionId(),
- memberActivatedEvent.getClusterId(),
- memberActivatedEvent.getClusterInstanceId(),
- memberActivatedEvent.getServiceName(), MemberStatus.Active.toString(),
- timeStamp, null, null, null);
- }
- } finally {
- TopologyManager.releaseWriteLock();
- }
- }
-
- public static void handleMemberReadyToShutdown(InstanceReadyToShutdownEvent instanceReadyToShutdownEvent)
- throws InvalidMemberException, InvalidCartridgeTypeException {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(instanceReadyToShutdownEvent.getServiceName());
- //update the status of the member
- if (service == null) {
- log.warn(String.format("Service %s does not exist", instanceReadyToShutdownEvent.getServiceName()));
- return;
- }
-
- Cluster cluster = service.getCluster(instanceReadyToShutdownEvent.getClusterId());
- if (cluster == null) {
- log.warn(String.format("Cluster %s does not exist", instanceReadyToShutdownEvent.getClusterId()));
- return;
- }
-
- Member member = cluster.getMember(instanceReadyToShutdownEvent.getMemberId());
- if (member == null) {
- log.warn(String.format("Member %s does not exist", instanceReadyToShutdownEvent.getMemberId()));
- return;
- }
- MemberReadyToShutdownEvent memberReadyToShutdownEvent =
- new MemberReadyToShutdownEvent(instanceReadyToShutdownEvent.getServiceName(),
- instanceReadyToShutdownEvent.getClusterId(),
- instanceReadyToShutdownEvent.getClusterInstanceId(),
- instanceReadyToShutdownEvent.getMemberId(),
- instanceReadyToShutdownEvent.getNetworkPartitionId(),
- instanceReadyToShutdownEvent.getPartitionId());
- //get the time of ReadyToShutdown state change
- Long timeStamp = null;
- try {
- TopologyManager.acquireWriteLock();
-
- if (!member.isStateTransitionValid(MemberStatus.ReadyToShutDown)) {
- log.error("Invalid State Transition from " + member.getStatus() + " to " +
- MemberStatus.ReadyToShutDown);
- return;
- }
- member.setStatus(MemberStatus.ReadyToShutDown);
- log.info("Member Ready to shut down event adding status started");
-
- TopologyManager.updateTopology(topology);
-
- timeStamp = System.currentTimeMillis();
- } finally {
- TopologyManager.releaseWriteLock();
- }
- TopologyEventPublisher.sendMemberReadyToShutdownEvent(memberReadyToShutdownEvent);
- //publishing data
- BAMUsageDataPublisher
- .publish(instanceReadyToShutdownEvent.getMemberId(), instanceReadyToShutdownEvent.getPartitionId(),
- instanceReadyToShutdownEvent.getNetworkPartitionId(),
- instanceReadyToShutdownEvent.getClusterId(),
- instanceReadyToShutdownEvent.getClusterInstanceId(),
- instanceReadyToShutdownEvent.getServiceName(), MemberStatus.ReadyToShutDown.toString(),
- timeStamp, null, null, null);
- //termination of particular instance will be handled by autoscaler
- }
-
- public static void handleMemberMaintenance(InstanceMaintenanceModeEvent instanceMaintenanceModeEvent)
- throws InvalidMemberException, InvalidCartridgeTypeException {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(instanceMaintenanceModeEvent.getServiceName());
- //update the status of the member
- if (service == null) {
- log.warn(String.format("Service %s does not exist", instanceMaintenanceModeEvent.getServiceName()));
- return;
- }
-
- Cluster cluster = service.getCluster(instanceMaintenanceModeEvent.getClusterId());
- if (cluster == null) {
- log.warn(String.format("Cluster %s does not exist", instanceMaintenanceModeEvent.getClusterId()));
- return;
- }
-
- Member member = cluster.getMember(instanceMaintenanceModeEvent.getMemberId());
- if (member == null) {
- log.warn(String.format("Member %s does not exist", instanceMaintenanceModeEvent.getMemberId()));
- return;
- }
-
- MemberMaintenanceModeEvent memberMaintenanceModeEvent =
- new MemberMaintenanceModeEvent(instanceMaintenanceModeEvent.getServiceName(),
- instanceMaintenanceModeEvent.getClusterId(),
- instanceMaintenanceModeEvent.getClusterInstanceId(),
- instanceMaintenanceModeEvent.getMemberId(),
- instanceMaintenanceModeEvent.getNetworkPartitionId(),
- instanceMaintenanceModeEvent.getPartitionId());
- try {
- TopologyManager.acquireWriteLock();
- // try update lifecycle state
- if (!member.isStateTransitionValid(MemberStatus.In_Maintenance)) {
- log.error("Invalid State Transition from " + member.getStatus() + " to " + MemberStatus.In_Maintenance);
- return;
- }
- member.setStatus(MemberStatus.In_Maintenance);
- log.info("member maintenance mode event adding status started");
-
- TopologyManager.updateTopology(topology);
- } finally {
- TopologyManager.releaseWriteLock();
- }
- //publishing data
- TopologyEventPublisher.sendMemberMaintenanceModeEvent(memberMaintenanceModeEvent);
-
- }
-
- /**
- * Remove member from topology and send member terminated event.
- *
- * @param serviceName
- * @param clusterId
- * @param networkPartitionId
- * @param partitionId
- * @param memberId
- */
- public static void handleMemberTerminated(String serviceName, String clusterId, String networkPartitionId,
- String partitionId, String memberId) {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(serviceName);
- Properties properties;
- if (service == null) {
- log.warn(String.format("Service %s does not exist", serviceName));
- return;
- }
- Cluster cluster = service.getCluster(clusterId);
- if (cluster == null) {
- log.warn(String.format("Cluster %s does not exist", clusterId));
- return;
- }
-
- Member member = cluster.getMember(memberId);
- if (member == null) {
- log.warn(String.format("Member %s does not exist", memberId));
- return;
- }
-
- String clusterInstanceId = member.getClusterInstanceId();
-
- try {
- TopologyManager.acquireWriteLock();
- properties = member.getProperties();
- cluster.removeMember(member);
- TopologyManager.updateTopology(topology);
- } finally {
- TopologyManager.releaseWriteLock();
- }
- /* @TODO leftover from grouping_poc*/
- String groupAlias = null;
- TopologyEventPublisher
- .sendMemberTerminatedEvent(serviceName, clusterId, memberId, clusterInstanceId, networkPartitionId,
- partitionId, properties, groupAlias);
- }
-
- public static void handleMemberSuspended() {
- //TODO
- try {
- TopologyManager.acquireWriteLock();
- } finally {
- TopologyManager.releaseWriteLock();
- }
- }
-
- public static void handleClusterActivatedEvent(
- ClusterStatusClusterActivatedEvent clusterStatusClusterActivatedEvent) {
-
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(clusterStatusClusterActivatedEvent.getServiceName());
- //update the status of the cluster
- if (service == null) {
- log.warn(String.format("Service %s does not exist", clusterStatusClusterActivatedEvent.getServiceName()));
- return;
- }
-
- Cluster cluster = service.getCluster(clusterStatusClusterActivatedEvent.getClusterId());
- if (cluster == null) {
- log.warn(String.format("Cluster %s does not exist", clusterStatusClusterActivatedEvent.getClusterId()));
- return;
- }
-
- String clusterId = cluster.getClusterId();
- ClusterContext clusterContext = CloudControllerContext.getInstance().getClusterContext(clusterId);
- if (clusterContext == null) {
- log.warn("Cluster context not found: [cluster-id] " + clusterId);
- return;
- }
-
- ClusterInstanceActivatedEvent clusterInstanceActivatedEvent =
- new ClusterInstanceActivatedEvent(clusterStatusClusterActivatedEvent.getAppId(),
- clusterStatusClusterActivatedEvent.getServiceName(),
- clusterStatusClusterActivatedEvent.getClusterId(),
- clusterStatusClusterActivatedEvent.getInstanceId());
- try {
- TopologyManager.acquireWriteLock();
- List<KubernetesService> kubernetesServices = clusterContext.getKubernetesServices();
- cluster.setKubernetesServices(kubernetesServices);
- clusterInstanceActivatedEvent.setKubernetesServices(kubernetesServices);
-
- ClusterInstance context = cluster.getInstanceContexts(clusterStatusClusterActivatedEvent.getInstanceId());
- if (context == null) {
- log.warn("Cluster instance context is not found for [cluster] " +
- clusterStatusClusterActivatedEvent.getClusterId() + " [instance-id] " +
- clusterStatusClusterActivatedEvent.getInstanceId());
- return;
- }
- ClusterStatus status = ClusterStatus.Active;
- if (context.isStateTransitionValid(status)) {
- context.setStatus(status);
- log.info("Cluster activated adding status started for " + cluster.getClusterId());
- TopologyManager.updateTopology(topology);
- // publish event
- TopologyEventPublisher.sendClusterActivatedEvent(clusterInstanceActivatedEvent);
- } else {
- log.error(String.format("Cluster state transition is not valid: [cluster-id] %s " +
- " [instance-id] %s [current-status] %s [status-requested] %s",
- clusterStatusClusterActivatedEvent.getClusterId(),
- clusterStatusClusterActivatedEvent.getInstanceId(), context.getStatus(),
- status));
- return;
- }
- } finally {
- TopologyManager.releaseWriteLock();
- }
-
- }
-
- public static void handleClusterInactivateEvent(ClusterStatusClusterInactivateEvent clusterInactivateEvent) {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(clusterInactivateEvent.getServiceName());
- //update the status of the cluster
- if (service == null) {
- log.warn(String.format("Service %s does not exist", clusterInactivateEvent.getServiceName()));
- return;
- }
-
- Cluster cluster = service.getCluster(clusterInactivateEvent.getClusterId());
- if (cluster == null) {
- log.warn(String.format("Cluster %s does not exist", clusterInactivateEvent.getClusterId()));
- return;
- }
-
- ClusterInstanceInactivateEvent clusterInactivatedEvent1 =
- new ClusterInstanceInactivateEvent(clusterInactivateEvent.getAppId(),
- clusterInactivateEvent.getServiceName(),
- clusterInactivateEvent.getClusterId(),
- clusterInactivateEvent.getInstanceId());
- try {
- TopologyManager.acquireWriteLock();
- ClusterInstance context = cluster.getInstanceContexts(clusterInactivateEvent.getInstanceId());
- if (context == null) {
- log.warn("Cluster Instance Context is not found for [cluster] " +
- clusterInactivateEvent.getClusterId() + " [instance-id] " +
- clusterInactivateEvent.getInstanceId());
- return;
- }
- ClusterStatus status = ClusterStatus.Inactive;
- if (context.isStateTransitionValid(status)) {
- context.setStatus(status);
- log.info("Cluster Inactive adding status started for" + cluster.getClusterId());
- TopologyManager.updateTopology(topology);
- //publishing data
- TopologyEventPublisher.sendClusterInactivateEvent(clusterInactivatedEvent1);
- } else {
- log.error(String.format("Cluster state transition is not valid: [cluster-id] %s " +
- " [instance-id] %s [current-status] %s [status-requested] %s",
- clusterInactivateEvent.getClusterId(), clusterInactivateEvent.getInstanceId(),
- context.getStatus(), status));
- return;
- }
- } finally {
- TopologyManager.releaseWriteLock();
- }
- }
-
- private static void deleteAppResourcesFromMetadataService(ApplicationInstanceTerminatedEvent event) {
- try {
- MetaDataServiceClient metadataClient = new DefaultMetaDataServiceClient();
- metadataClient.deleteApplicationProperties(event.getAppId());
- } catch (Exception e) {
- log.error("Error occurred while deleting the application resources frm metadata service ", e);
- }
- }
-
- public static void handleClusterTerminatedEvent(ClusterStatusClusterTerminatedEvent event) {
-
- TopologyManager.acquireWriteLock();
-
- try {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(event.getServiceName());
-
- //update the status of the cluster
- if (service == null) {
- log.warn(String.format("Service %s does not exist", event.getServiceName()));
- return;
- }
-
- Cluster cluster = service.getCluster(event.getClusterId());
- if (cluster == null) {
- log.warn(String.format("Cluster %s does not exist", event.getClusterId()));
- return;
- }
-
- ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
- if (context == null) {
- log.warn("Cluster Instance Context is not found for [cluster] " +
- event.getClusterId() + " [instance-id] " +
- event.getInstanceId());
- return;
- }
- ClusterStatus status = ClusterStatus.Terminated;
- if (context.isStateTransitionValid(status)) {
- context.setStatus(status);
- log.info("Cluster Terminated adding status started for and removing the cluster instance" +
- cluster.getClusterId());
- cluster.removeInstanceContext(event.getInstanceId());
- TopologyManager.updateTopology(topology);
- //publishing data
- ClusterInstanceTerminatedEvent clusterTerminatedEvent =
- new ClusterInstanceTerminatedEvent(event.getAppId(), event.getServiceName(),
- event.getClusterId(), event.getInstanceId());
-
- TopologyEventPublisher.sendClusterTerminatedEvent(clusterTerminatedEvent);
- } else {
- log.error(String.format("Cluster state transition is not valid: [cluster-id] %s " +
- " [instance-id] %s [current-status] %s [status-requested] %s",
- event.getClusterId(), event.getInstanceId(), context.getStatus(), status));
- return;
- }
- } finally {
- TopologyManager.releaseWriteLock();
- }
-
- }
-
- public static void handleClusterTerminatingEvent(ClusterStatusClusterTerminatingEvent event) {
-
- TopologyManager.acquireWriteLock();
-
- try {
- Topology topology = TopologyManager.getTopology();
- Cluster cluster = topology.getService(event.getServiceName()).
- getCluster(event.getClusterId());
-
- if (!cluster.isStateTransitionValid(ClusterStatus.Terminating, event.getInstanceId())) {
- log.error("Invalid state transfer from " + cluster.getStatus(event.getInstanceId()) + " to " +
- ClusterStatus.Terminating);
- }
- ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
- if (context == null) {
- log.warn("Cluster Instance Context is not found for [cluster] " +
- event.getClusterId() + " [instance-id] " +
- event.getInstanceId());
- return;
- }
- ClusterStatus status = ClusterStatus.Terminating;
- if (context.isStateTransitionValid(status)) {
- context.setStatus(status);
- log.info("Cluster Terminating started for " + cluster.getClusterId());
- TopologyManager.updateTopology(topology);
- //publishing data
- ClusterInstanceTerminatingEvent clusterTerminaingEvent =
- new ClusterInstanceTerminatingEvent(event.getAppId(), event.getServiceName(),
- event.getClusterId(), event.getInstanceId());
-
- TopologyEventPublisher.sendClusterTerminatingEvent(clusterTerminaingEvent);
-
- // Remove kubernetes services if available
- ClusterContext clusterContext =
- CloudControllerContext.getInstance().getClusterContext(event.getClusterId());
- if (StringUtils.isNotBlank(clusterContext.getKubernetesClusterId())) {
- KubernetesIaas.removeKubernetesServices(event.getAppId(), event.getClusterId());
- }
- } else {
- log.error(String.format("Cluster state transition is not valid: [cluster-id] %s " +
- " [instance-id] %s [current-status] %s [status-requested] %s",
- event.getClusterId(), event.getInstanceId(), context.getStatus(), status));
- }
- } finally {
- TopologyManager.releaseWriteLock();
- }
- }
+ private static final Log log = LogFactory.getLog(TopologyBuilder.class);
+
+ public static void handleServiceCreated(List<Cartridge> cartridgeList) {
+ Service service;
+ Topology topology = TopologyManager.getTopology();
+ if (cartridgeList == null) {
+ log.warn(String.format("Cartridge list is empty"));
+ return;
+ }
+
+ try {
+
+ TopologyManager.acquireWriteLock();
+ for (Cartridge cartridge : cartridgeList) {
+ if (!topology.serviceExists(cartridge.getType())) {
+ ServiceType serviceType =
+ cartridge.isMultiTenant() ? ServiceType.MultiTenant : ServiceType.SingleTenant;
+ service = new Service(cartridge.getType(), serviceType);
+ Properties properties = new Properties();
+
+ try {
+ Property[] propertyArray = null;
+
+ if (cartridge.getProperties() != null) {
+ if (cartridge.getProperties().getProperties() != null) {
+ propertyArray = cartridge.getProperties().getProperties();
+ }
+ }
+
+ List<Property> propertyList = new ArrayList<Property>();
+ if (propertyArray != null) {
+ propertyList = Arrays.asList(propertyArray);
+ if (propertyList != null) {
+ for (Property property : propertyList) {
+ properties.setProperty(property.getName(), property.getValue());
+ }
+ }
+ }
+ } catch (Exception e) {
+ log.error(e);
+ }
+
+ service.setProperties(properties);
+ if (cartridge.getPortMappings() != null) {
+ List<PortMapping> portMappings = Arrays.asList(cartridge.getPortMappings());
+ Port port;
+ //adding ports to the event
+ for (PortMapping portMapping : portMappings) {
+ port = new Port(portMapping.getProtocol(), portMapping.getPort(),
+ portMapping.getProxyPort());
+ service.addPort(port);
+ }
+ }
+
+ topology.addService(service);
+ TopologyManager.updateTopology(topology);
+ }
+ }
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ TopologyEventPublisher.sendServiceCreateEvent(cartridgeList);
+ }
+
+ public static void handleServiceRemoved(List<Cartridge> cartridgeList) {
+ Topology topology = TopologyManager.getTopology();
+
+ for (Cartridge cartridge : cartridgeList) {
+ Service service = topology.getService(cartridge.getType());
+ if (service == null) {
+ log.warn("Cartridge does not exist [cartidge] " + cartridge);
+ return;
+ }
+ if (service.getClusters().size() == 0) {
+ if (topology.serviceExists(cartridge.getType())) {
+ try {
+ TopologyManager.acquireWriteLock();
+ topology.removeService(cartridge.getType());
+ TopologyManager.updateTopology(topology);
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ TopologyEventPublisher.sendServiceRemovedEvent(cartridgeList);
+ } else {
+ log.warn(String.format("Service %s does not exist..", cartridge.getType()));
+ }
+ } else {
+ log.warn("Subscription already exists. Hence not removing the service:" + cartridge.getType() +
+ " from the topology");
+ }
+ }
+ }
+
+ public static void handleClusterCreated(ClusterStatusClusterCreatedEvent event) {
+ TopologyManager.acquireWriteLock();
+ Cluster cluster;
+
+ try {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(event.getServiceName());
+ if (service == null) {
+ log.error("Service " + event.getServiceName() +
+ " not found in Topology, unable to update the cluster status to Created");
+ return;
+ }
+
+ if (service.clusterExists(event.getClusterId())) {
+ log.warn("Cluster " + event.getClusterId() + " is already in the Topology ");
+ return;
+ } else {
+ cluster = new Cluster(event.getServiceName(), event.getClusterId(), event.getDeploymentPolicyName(),
+ event.getAutosScalePolicyName(), event.getAppId());
+ //cluster.setStatus(Status.Created);
+ cluster.setHostNames(event.getHostNames());
+ cluster.setTenantRange(event.getTenantRange());
+ service.addCluster(cluster);
+ TopologyManager.updateTopology(topology);
+ }
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+
+ TopologyEventPublisher.sendClusterCreatedEvent(cluster);
+ }
+
+ public static void handleApplicationClustersCreated(String appId, List<Cluster> appClusters) {
+
+ TopologyManager.acquireWriteLock();
+
+ try {
+ Topology topology = TopologyManager.getTopology();
+ for (Cluster cluster : appClusters) {
+ Service service = topology.getService(cluster.getServiceName());
+ if (service == null) {
+ log.error("Service " + cluster.getServiceName() +
+ " not found in Topology, unable to create Application cluster");
+ } else {
+ service.addCluster(cluster);
+ log.info("Application Cluster " + cluster.getClusterId() + " created in CC topology");
+ }
+ }
+ TopologyManager.updateTopology(topology);
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+
+ log.debug("Creating cluster port mappings: [appication-id] " + appId);
+ for (Cluster cluster : appClusters) {
+ String cartridgeType = cluster.getServiceName();
+ Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType);
+ if (cartridge == null) {
+ throw new CloudControllerException("Cartridge not found: [cartridge-type] " + cartridgeType);
+ }
+
+ for (PortMapping portMapping : cartridge.getPortMappings()) {
+ ClusterPortMapping clusterPortMapping =
+ new ClusterPortMapping(appId, cluster.getClusterId(), portMapping.getName(),
+ portMapping.getProtocol(), portMapping.getPort(),
+ portMapping.getProxyPort());
+ CloudControllerContext.getInstance().addClusterPortMapping(clusterPortMapping);
+ log.debug("Cluster port mapping created: " + clusterPortMapping.toString());
+ }
+ }
+
+ // Persist cluster port mappings
+ CloudControllerContext.getInstance().persist();
+
+ // Send application clusters created event
+ TopologyEventPublisher.sendApplicationClustersCreated(appId, appClusters);
+ }
+
+ public static void handleApplicationClustersRemoved(String appId, Set<ClusterDataHolder> clusterData) {
+ TopologyManager.acquireWriteLock();
+
+ List<Cluster> removedClusters = new ArrayList<Cluster>();
+ CloudControllerContext context = CloudControllerContext.getInstance();
+ try {
+ Topology topology = TopologyManager.getTopology();
+
+ if (clusterData != null) {
+ // remove clusters from CC topology model and remove runtime information
+ for (ClusterDataHolder aClusterData : clusterData) {
+ Service aService = topology.getService(aClusterData.getServiceType());
+ if (aService != null) {
+ removedClusters.add(aService.removeCluster(aClusterData.getClusterId()));
+ } else {
+ log.warn("Service " + aClusterData.getServiceType() + " not found, " +
+ "unable to remove Cluster " + aClusterData.getClusterId());
+ }
+ // remove runtime data
+ context.removeClusterContext(aClusterData.getClusterId());
+
+ log.info("Removed application [ " + appId + " ]'s Cluster " +
+ "[ " + aClusterData.getClusterId() + " ] from the topology");
+ }
+ // persist runtime data changes
+ CloudControllerContext.getInstance().persist();
+ } else {
+ log.info("No cluster data found for application " + appId + " to remove");
+ }
+
+ TopologyManager.updateTopology(topology);
+
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+
+ // Remove cluster port mappings of application
+ CloudControllerContext.getInstance().removeClusterPortMappings(appId);
+ CloudControllerContext.getInstance().persist();
+
+ TopologyEventPublisher.sendApplicationClustersRemoved(appId, clusterData);
+
+ }
+
+ public static void handleClusterReset(ClusterStatusClusterResetEvent event) {
+ TopologyManager.acquireWriteLock();
+
+ try {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(event.getServiceName());
+ if (service == null) {
+ log.error("Service " + event.getServiceName() +
+ " not found in Topology, unable to update the cluster status to Created");
+ return;
+ }
+
+ Cluster cluster = service.getCluster(event.getClusterId());
+ if (cluster == null) {
+ log.error("Cluster " + event.getClusterId() + " not found in Topology, unable to update " +
+ "status to Created");
+ return;
+ }
+
+ ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
+ if (context == null) {
+ log.warn("Cluster Instance Context is not found for [cluster] " +
+ event.getClusterId() + " [instance-id] " +
+ event.getInstanceId());
+ return;
+ }
+ ClusterStatus status = ClusterStatus.Created;
+ if (context.isStateTransitionValid(status)) {
+ context.setStatus(status);
+ log.info("Cluster Created adding status started for" + cluster.getClusterId());
+ TopologyManager.updateTopology(topology);
+ //publishing data
+ TopologyEventPublisher
+ .sendClusterResetEvent(event.getAppId(), event.getServiceName(), event.getClusterId(),
+ event.getInstanceId());
+ } else {
+ log.warn(String.format("Cluster state transition is not valid: [cluster-id] %s " +
+ " [instance-id] %s [current-status] %s [status-requested] %s",
+ event.getClusterId(), event.getInstanceId(), context.getStatus(), status));
+ }
+
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+
+ }
+
+ public static void handleClusterInstanceCreated(String serviceType, String clusterId, String alias,
+ String instanceId, String partitionId, String networkPartitionId) {
+
+ TopologyManager.acquireWriteLock();
+
+ try {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(serviceType);
+ if (service == null) {
+ log.error("Service " + serviceType +
+ " not found in Topology, unable to update the cluster status to Created");
+ return;
+ }
+
+ Cluster cluster = service.getCluster(clusterId);
+ if (cluster == null) {
+ log.error("Cluster " + clusterId + " not found in Topology, unable to update " +
+ "status to Created");
+ return;
+ }
+
+ if (cluster.getInstanceContexts(instanceId) != null) {
+ log.warn("The Instance context for the cluster already exists for [cluster] " +
+ clusterId + " [instance-id] " + instanceId);
+ return;
+ }
+
+ ClusterInstance clusterInstance = new ClusterInstance(alias, clusterId, instanceId);
+ clusterInstance.setNetworkPartitionId(networkPartitionId);
+ clusterInstance.setPartitionId(partitionId);
+ cluster.addInstanceContext(instanceId, clusterInstance);
+ TopologyManager.updateTopology(topology);
+
+ ClusterInstanceCreatedEvent clusterInstanceCreatedEvent =
+ new ClusterInstanceCreatedEvent(serviceType, clusterId, clusterInstance);
+ clusterInstanceCreatedEvent.setPartitionId(partitionId);
+ TopologyEventPublisher.sendClusterInstanceCreatedEvent(clusterInstanceCreatedEvent);
+
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ }
+
+ public static void handleClusterRemoved(ClusterContext ctxt) {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(ctxt.getCartridgeType());
+ String deploymentPolicy;
+ if (service == null) {
+ log.warn(String.format("Service %s does not exist", ctxt.getCartridgeType()));
+ return;
+ }
+
+ if (!service.clusterExists(ctxt.getClusterId())) {
+ log.warn(String.format("Cluster %s does not exist for service %s", ctxt.getClusterId(),
+ ctxt.getCartridgeType()));
+ return;
+ }
+
+ try {
+ TopologyManager.acquireWriteLock();
+ Cluster cluster = service.removeCluster(ctxt.getClusterId());
+ deploymentPolicy = cluster.getDeploymentPolicyName();
+ TopologyManager.updateTopology(topology);
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ TopologyEventPublisher.sendClusterRemovedEvent(ctxt, deploymentPolicy);
+ }
+
+ /**
+ * Add member object to the topology and publish member created event
+ *
+ * @param memberContext
+ */
+ public static void handleMemberCreatedEvent(MemberContext memberContext) {
+ Topology topology = TopologyManager.getTopology();
+
+ Service service = topology.getService(memberContext.getCartridgeType());
+ String clusterId = memberContext.getClusterId();
+ Cluster cluster = service.getCluster(clusterId);
+ String memberId = memberContext.getMemberId();
+ String clusterInstanceId = memberContext.getClusterInstanceId();
+ String networkPartitionId = memberContext.getNetworkPartitionId();
+ String partitionId = memberContext.getPartition().getId();
+ String lbClusterId = memberContext.getLbClusterId();
+ long initTime = memberContext.getInitTime();
+ String autoscalingReason =
+ memberContext.getProperties().getProperty(StratosConstants.SCALING_REASON).getValue();
+ long scalingTime =
+ Long.parseLong(memberContext.getProperties().getProperty(StratosConstants.SCALING_TIME).getValue());
+
+ if (cluster.memberExists(memberId)) {
+ log.warn(String.format("Member %s already exists", memberId));
+ return;
+ }
+
+ try {
+ TopologyManager.acquireWriteLock();
+ Member member =
+ new Member(service.getServiceName(), clusterId, memberId, clusterInstanceId, networkPartitionId,
+ partitionId, memberContext.getLoadBalancingIPType(), initTime);
+ member.setStatus(MemberStatus.Created);
+ member.setLbClusterId(lbClusterId);
+ member.setProperties(CloudControllerUtil.toJavaUtilProperties(memberContext.getProperties()));
+ cluster.addMember(member);
+ TopologyManager.updateTopology(topology);
+ //Member created time
+ Long timeStamp = System.currentTimeMillis();
+ //publishing to BAM
+ BAMUsageDataPublisher.publish(memberContext.getMemberId(), memberContext.getPartition().getId(),
+ memberContext.getNetworkPartitionId(), memberContext.getClusterId(),
+ memberContext.getClusterInstanceId(), memberContext.getCartridgeType(),
+ MemberStatus.Created.toString(), timeStamp, autoscalingReason, scalingTime,
+ null);
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+
+ TopologyEventPublisher.sendMemberCreatedEvent(memberContext);
+ }
+
+ /**
+ * Update member status to initialized and publish member initialized event
+ *
+ * @param memberContext
+ */
+ public static void handleMemberInitializedEvent(MemberContext memberContext) {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(memberContext.getCartridgeType());
+ if (service == null) {
+ log.warn(String.format("Service %s does not exist", memberContext.getCartridgeType()));
+ return;
+ }
+ if (!service.clusterExists(memberContext.getClusterId())) {
+ log.warn(String.format("Cluster %s does not exist in service %s", memberContext.getClusterId(),
+ memberContext.getCartridgeType()));
+ return;
+ }
+
+ Member member = service.getCluster(memberContext.getClusterId()).
+ getMember(memberContext.getMemberId());
+ if (member == null) {
+ log.warn(String.format("Member %s does not exist", memberContext.getMemberId()));
+ return;
+ }
+
+ try {
+ TopologyManager.acquireWriteLock();
+
+ // Set ip addresses
+ member.setDefaultPrivateIP(memberContext.getDefaultPrivateIP());
+ if (memberContext.getPrivateIPs() != null) {
+ member.setMemberPrivateIPs(Arrays.asList(memberContext.getPrivateIPs()));
+ }
+ member.setDefaultPublicIP(memberContext.getDefaultPublicIP());
+ if (memberContext.getPublicIPs() != null) {
+ member.setMemberPublicIPs(Arrays.asList(memberContext.getPublicIPs()));
+ }
+
+ // try update lifecycle state
+ if (!member.isStateTransitionValid(MemberStatus.Initialized)) {
+ log.error("Invalid state transition from " + member.getStatus() + " to " +
+ MemberStatus.Initialized);
+ return;
+ } else {
+ member.setStatus(MemberStatus.Initialized);
+ log.info("Member status updated to initialized");
+
+ TopologyManager.updateTopology(topology);
+ //member initialized time
+ Long timeStamp = System.currentTimeMillis();
+
+ TopologyEventPublisher.sendMemberInitializedEvent(memberContext);
+ //publishing data
+ BAMUsageDataPublisher.publish(memberContext.getMemberId(), memberContext.getPartition().getId(),
+ memberContext.getNetworkPartitionId(), memberContext.getClusterId(),
+ memberContext.getClusterInstanceId(), memberContext.getCartridgeType(),
+ MemberStatus.Initialized.toString(), timeStamp, null, null, null);
+ }
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ }
+
+ private static int findKubernetesServicePort(String clusterId, List<KubernetesService> kubernetesServices,
+ PortMapping portMapping) {
+ for (KubernetesService kubernetesService : kubernetesServices) {
+ if (kubernetesService.getProtocol().equals(portMapping.getProtocol())) {
+ return kubernetesService.getPort();
+ }
+ }
+ throw new RuntimeException(
+ "Kubernetes service port not found: [cluster-id] " + clusterId + " [port] " + portMapping.getPort());
+ }
+
+ public static void handleMemberStarted(InstanceStartedEvent instanceStartedEvent) {
+ try {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(instanceStartedEvent.getServiceName());
+ if (service == null) {
+ log.warn(String.format("Service %s does not exist", instanceStartedEvent.getServiceName()));
+ return;
+ }
+ if (!service.clusterExists(instanceStartedEvent.getClusterId())) {
+ log.warn(String.format("Cluster %s does not exist in service %s", instanceStartedEvent.getClusterId(),
+ instanceStartedEvent.getServiceName()));
+ return;
+ }
+
+ Cluster cluster = service.getCluster(instanceStartedEvent.getClusterId());
+ Member member = cluster.getMember(instanceStartedEvent.getMemberId());
+ if (member == null) {
+ log.warn(String.format("Member %s does not exist", instanceStartedEvent.getMemberId()));
+ return;
+ }
+
+ try {
+ TopologyManager.acquireWriteLock();
+ // try update lifecycle state
+ if (!member.isStateTransitionValid(MemberStatus.Starting)) {
+ log.error("Invalid State Transition from " + member.getStatus() + " to " +
+ MemberStatus.Starting);
+ return;
+ } else {
+ member.setStatus(MemberStatus.Starting);
+ log.info("member started event adding status started");
+
+ TopologyManager.updateTopology(topology);
+ //member starting time
+ Long timeStamp = System.currentTimeMillis();
+ //memberStartedEvent.
+ TopologyEventPublisher.sendMemberStartedEvent(instanceStartedEvent);
+ //publishing data
+ BAMUsageDataPublisher
+ .publish(instanceStartedEvent.getMemberId(), instanceStartedEvent.getPartitionId(),
+ instanceStartedEvent.getNetworkPartitionId(), instanceStartedEvent.getClusterId(),
+ instanceStartedEvent.getClusterInstanceId(), instanceStartedEvent.getServiceName(),
+ MemberStatus.Starting.toString(), timeStamp, null, null, null);
+ }
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ } catch (Exception e) {
+ String message = String.format(
+ "Could not handle member started event: [application-id] %s " + "[service-name] %s [member-id] %s",
+ instanceStartedEvent.getApplicationId(), instanceStartedEvent.getServiceName(),
+ instanceStartedEvent.getMemberId());
+ log.warn(message, e);
+ }
+ }
+
+ public static void handleMemberActivated(InstanceActivatedEvent instanceActivatedEvent) {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(instanceActivatedEvent.getServiceName());
+ if (service == null) {
+ log.warn(String.format("Service %s does not exist", instanceActivatedEvent.getServiceName()));
+ return;
+ }
+
+ Cluster cluster = service.getCluster(instanceActivatedEvent.getClusterId());
+ if (cluster == null) {
+ log.warn(String.format("Cluster %s does not exist", instanceActivatedEvent.getClusterId()));
+ return;
+ }
+
+ Member member = cluster.getMember(instanceActivatedEvent.getMemberId());
+ if (member == null) {
+ log.warn(String.format("Member %s does not exist", instanceActivatedEvent.getMemberId()));
+ return;
+ }
+
+ MemberActivatedEvent memberActivatedEvent =
+ new MemberActivatedEvent(instanceActivatedEvent.getServiceName(), instanceActivatedEvent.getClusterId(),
+ instanceActivatedEvent.getClusterInstanceId(),
+ instanceActivatedEvent.getMemberId(),
+ instanceActivatedEvent.getNetworkPartitionId(),
+ instanceActivatedEvent.getPartitionId());
+
+ // grouping - set grouid
+ //TODO
+ memberActivatedEvent.setApplicationId(null);
+ try {
+ TopologyManager.acquireWriteLock();
+ // try update lifecycle state
+ if (!member.isStateTransitionValid(MemberStatus.Active)) {
+ log.error(
+ "Invalid state transition from [" + member.getStatus() + "] to [" + MemberStatus.Active + "]");
+ return;
+ } else {
+ member.setStatus(MemberStatus.Active);
+
+ // Set member ports
+ try {
+ Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(service.getServiceName());
+ if (cartridge == null) {
+ throw new RuntimeException(
+ String.format("Cartridge not found: [cartridge-type] %s", service.getServiceName()));
+ }
+
+ Port port;
+ int portValue;
+ List<PortMapping> portMappings = Arrays.asList(cartridge.getPortMappings());
+ String clusterId = cluster.getClusterId();
+ ClusterContext clusterContext = CloudControllerContext.getInstance().getClusterContext(clusterId);
+ List<KubernetesService> kubernetesServices = clusterContext.getKubernetesServices();
+
+ for (PortMapping portMapping : portMappings) {
+ if (kubernetesServices != null) {
+ portValue = findKubernetesServicePort(clusterId, kubernetesServices, portMapping);
+ } else {
+ portValue = portMapping.getPort();
+ }
+ port = new Port(portMapping.getProtocol(), portValue, portMapping.getProxyPort());
+ member.addPort(port);
+ memberActivatedEvent.addPort(port);
+ }
+ } catch (Exception e) {
+ String message = String.format("Could not add member ports: [service-name] %s [member-id] %s",
+ memberActivatedEvent.getServiceName(),
+ memberActivatedEvent.getMemberId());
+ log.error(message, e);
+ }
+
+ // Set member ip addresses
+ memberActivatedEvent.setDefaultPrivateIP(member.getDefaultPrivateIP());
+ memberActivatedEvent.setMemberPrivateIPs(member.getMemberPrivateIPs());
+ memberActivatedEvent.setDefaultPublicIP(member.getDefaultPublicIP());
+ memberActivatedEvent.setMemberPublicIPs(member.getMemberPublicIPs());
+ TopologyManager.updateTopology(topology);
+
+ //member activated time
+ Long timeStamp = System.currentTimeMillis();
+
+ // Publish member activated event
+ TopologyEventPublisher.sendMemberActivatedEvent(memberActivatedEvent);
+
+ // Publish statistics data
+ BAMUsageDataPublisher.publish(memberActivatedEvent.getMemberId(), memberActivatedEvent.getPartitionId(),
+ memberActivatedEvent.getNetworkPartitionId(),
+ memberActivatedEvent.getClusterId(),
+ memberActivatedEvent.getClusterInstanceId(),
+ memberActivatedEvent.getServiceName(), MemberStatus.Active.toString(),
+ timeStamp, null, null, null);
+ }
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ }
+
+ public static void handleMemberReadyToShutdown(InstanceReadyToShutdownEvent instanceReadyToShutdownEvent)
+ throws InvalidMemberException, InvalidCartridgeTypeException {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(instanceReadyToShutdownEvent.getServiceName());
+ //update the status of the member
+ if (service == null) {
+ log.warn(String.format("Service %s does not exist", instanceReadyToShutdownEvent.getServiceName()));
+ return;
+ }
+
+ Cluster cluster = service.getCluster(instanceReadyToShutdownEvent.getClusterId());
+ if (cluster == null) {
+ log.warn(String.format("Cluster %s does not exist", instanceReadyToShutdownEvent.getClusterId()));
+ return;
+ }
+
+ Member member = cluster.getMember(instanceReadyToShutdownEvent.getMemberId());
+ if (member == null) {
+ log.warn(String.format("Member %s does not exist", instanceReadyToShutdownEvent.getMemberId()));
+ return;
+ }
+ MemberReadyToShutdownEvent memberReadyToShutdownEvent =
+ new MemberReadyToShutdownEvent(instanceReadyToShutdownEvent.getServiceName(),
+ instanceReadyToShutdownEvent.getClusterId(),
+ instanceReadyToShutdownEvent.getClusterInstanceId(),
+ instanceReadyToShutdownEvent.getMemberId(),
+ instanceReadyToShutdownEvent.getNetworkPartitionId(),
+ instanceReadyToShutdownEvent.getPartitionId());
+ //get the time of ReadyToShutdown state change
+ Long timeStamp = null;
+ try {
+ TopologyManager.acquireWriteLock();
+
+ if (!member.isStateTransitionValid(MemberStatus.ReadyToShutDown)) {
+ log.error("Invalid State Transition from " + member.getStatus() + " to " +
+ MemberStatus.ReadyToShutDown);
+ return;
+ }
+ member.setStatus(MemberStatus.ReadyToShutDown);
+ log.info("Member Ready to shut down event adding status started");
+
+ TopologyManager.updateTopology(topology);
+
+ timeStamp = System.currentTimeMillis();
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ TopologyEventPublisher.sendMemberReadyToShutdownEvent(memberReadyToShutdownEvent);
+ //publishing data
+ BAMUsageDataPublisher
+ .publish(instanceReadyToShutdownEvent.getMemberId(), instanceReadyToShutdownEvent.getPartitionId(),
+ instanceReadyToShutdownEvent.getNetworkPartitionId(),
+ instanceReadyToShutdownEvent.getClusterId(),
+ instanceReadyToShutdownEvent.getClusterInstanceId(),
+ instanceReadyToShutdownEvent.getServiceName(), MemberStatus.ReadyToShutDown.toString(),
+ timeStamp, null, null, null);
+ //termination of particular instance will be handled by autoscaler
+ }
+
+ public static void handleMemberMaintenance(InstanceMaintenanceModeEvent instanceMaintenanceModeEvent)
+ throws InvalidMemberException, InvalidCartridgeTypeException {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(instanceMaintenanceModeEvent.getServiceName());
+ //update the status of the member
+ if (service == null) {
+ log.warn(String.format("Service %s does not exist", instanceMaintenanceModeEvent.getServiceName()));
+ return;
+ }
+
+ Cluster cluster = service.getCluster(instanceMaintenanceModeEvent.getClusterId());
+ if (cluster == null) {
+ log.warn(String.format("Cluster %s does not exist", instanceMaintenanceModeEvent.getClusterId()));
+ return;
+ }
+
+ Member member = cluster.getMember(instanceMaintenanceModeEvent.getMemberId());
+ if (member == null) {
+ log.warn(String.format("Member %s does not exist", instanceMaintenanceModeEvent.getMemberId()));
+ return;
+ }
+
+ MemberMaintenanceModeEvent memberMaintenanceModeEvent =
+ new MemberMaintenanceModeEvent(instanceMaintenanceModeEvent.getServiceName(),
+ instanceMaintenanceModeEvent.getClusterId(),
+ instanceMaintenanceModeEvent.getClusterInstanceId(),
+ instanceMaintenanceModeEvent.getMemberId(),
+ instanceMaintenanceModeEvent.getNetworkPartitionId(),
+ instanceMaintenanceModeEvent.getPartitionId());
+ try {
+ TopologyManager.acquireWriteLock();
+ // try update lifecycle state
+ if (!member.isStateTransitionValid(MemberStatus.In_Maintenance)) {
+ log.error("Invalid State Transition from " + member.getStatus() + " to " + MemberStatus.In_Maintenance);
+ return;
+ }
+ member.setStatus(MemberStatus.In_Maintenance);
+ log.info("member maintenance mode event adding status started");
+
+ TopologyManager.updateTopology(topology);
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ //publishing data
+ TopologyEventPublisher.sendMemberMaintenanceModeEvent(memberMaintenanceModeEvent);
+
+ }
+
+ /**
+ * Remove member from topology and send member terminated event.
+ *
+ * @param serviceName
+ * @param clusterId
+ * @param networkPartitionId
+ * @param partitionId
+ * @param memberId
+ */
+ public static void handleMemberTerminated(String serviceName, String clusterId, String networkPartitionId,
+ String partitionId, String memberId) {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(serviceName);
+ Properties properties;
+ if (service == null) {
+ log.warn(String.format("Service %s does not exist", serviceName));
+ return;
+ }
+ Cluster cluster = service.getCluster(clusterId);
+ if (cluster == null) {
+ log.warn(String.format("Cluster %s does not exist", clusterId));
+ return;
+ }
+
+ Member member = cluster.getMember(memberId);
+ if (member == null) {
+ log.warn(String.format("Member %s does not exist", memberId));
+ return;
+ }
+
+ String clusterInstanceId = member.getClusterInstanceId();
+
+ try {
+ TopologyManager.acquireWriteLock();
+ properties = member.getProperties();
+ cluster.removeMember(member);
+ TopologyManager.updateTopology(topology);
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ /* @TODO leftover from grouping_poc*/
+ String groupAlias = null;
+ TopologyEventPublisher
+ .sendMemberTerminatedEvent(serviceName, clusterId, memberId, clusterInstanceId, networkPartitionId,
+ partitionId, properties, groupAlias);
+ }
+
+ public static void handleMemberSuspended() {
+ //TODO
+ try {
+ TopologyManager.acquireWriteLock();
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ }
+
+ public static void handleClusterActivatedEvent(
+ ClusterStatusClusterActivatedEvent clusterStatusClusterActivatedEvent) {
+
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(clusterStatusClusterActivatedEvent.getServiceName());
+ //update the status of the cluster
+ if (service == null) {
+ log.warn(String.format("Service %s does not exist", clusterStatusClusterActivatedEvent.getServiceName()));
+ return;
+ }
+
+ Cluster cluster = service.getCluster(clusterStatusClusterActivatedEvent.getClusterId());
+ if (cluster == null) {
+ log.warn(String.format("Cluster %s does not exist", clusterStatusClusterActivatedEvent.getClusterId()));
+ return;
+ }
+
+ String clusterId = cluster.getClusterId();
+ ClusterContext clusterContext = CloudControllerContext.getInstance().getClusterContext(clusterId);
+ if (clusterContext == null) {
+ log.warn("Cluster context not found: [cluster-id] " + clusterId);
+ return;
+ }
+
+ ClusterInstanceActivatedEvent clusterInstanceActivatedEvent =
+ new ClusterInstanceActivatedEvent(clusterStatusClusterActivatedEvent.getAppId(),
+ clusterStatusClusterActivatedEvent.getServiceName(),
+ clusterStatusClusterActivatedEvent.getClusterId(),
+ clusterStatusClusterActivatedEvent.getInstanceId());
+ try {
+ TopologyManager.acquireWriteLock();
+ List<KubernetesService> kubernetesServices = clusterContext.getKubernetesServices();
+ cluster.setKubernetesServices(kubernetesServices);
+ clusterInstanceActivatedEvent.setKubernetesServices(kubernetesServices);
+
+ ClusterInstance context = cluster.getInstanceContexts(clusterStatusClusterActivatedEvent.getInstanceId());
+ if (context == null) {
+ log.warn("Cluster instance context is not found for [cluster] " +
+ clusterStatusClusterActivatedEvent.getClusterId() + " [instance-id] " +
+ clusterStatusClusterActivatedEvent.getInstanceId());
+ return;
+ }
+ ClusterStatus status = ClusterStatus.Active;
+ if (context.isStateTransitionValid(status)) {
+ context.setStatus(status);
+ log.info("Cluster activated adding status started for " + cluster.getClusterId());
+ TopologyManager.updateTopology(topology);
+ // publish event
+ TopologyEventPublisher.sendClusterActivatedEvent(clusterInstanceActivatedEvent);
+ } else {
+ log.error(String.format("Cluster state transition is not valid: [cluster-id] %s " +
+ " [instance-id] %s [current-status] %s [status-requested] %s",
+ clusterStatusClusterActivatedEvent.getClusterId(),
+ clusterStatusClusterActivatedEvent.getInstanceId(), context.getStatus(),
+ status));
+ return;
+ }
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+
+ }
+
+ public static void handleClusterInactivateEvent(ClusterStatusClusterInactivateEvent clusterInactivateEvent) {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(clusterInactivateEvent.getServiceName());
+ //update the status of the cluster
+ if (service == null) {
+ log.warn(String.format("Service %s does not exist", clusterInactivateEvent.getServiceName()));
+ return;
+ }
+
+ Cluster cluster = service.getCluster(clusterInactivateEvent.getClusterId());
+ if (cluster == null) {
+ log.warn(String.format("Cluster %s does not exist", clusterInactivateEvent.getClusterId()));
+ return;
+ }
+
+ ClusterInstanceInactivateEvent clusterInactivatedEvent1 =
+ new ClusterInstanceInactivateEvent(clusterInactivateEvent.getAppId(),
+ clusterInactivateEvent.getServiceName(),
+ clusterInactivateEvent.getClusterId(),
+ clusterInactivateEvent.getInstanceId());
+ try {
+ TopologyManager.acquireWriteLock();
+ ClusterInstance context = cluster.getInstanceContexts(clusterInactivateEvent.getInstanceId());
+ if (context == null) {
+ log.warn("Cluster Instance Context is not found for [cluster] " +
+ clusterInactivateEvent.getClusterId() + " [instance-id] " +
+ clusterInactivateEvent.getInstanceId());
+ return;
+ }
+ ClusterStatus status = ClusterStatus.Inactive;
+ if (context.isStateTransitionValid(status)) {
+ context.setStatus(status);
+ log.info("Cluster Inactive adding status started for" + cluster.getClusterId());
+ TopologyManager.updateTopology(topology);
+ //publishing data
+ TopologyEventPublisher.sendClusterInactivateEvent(clusterInactivatedEvent1);
+ } else {
+ log.error(String.format("Cluster state transition is not valid: [cluster-id] %s " +
+ " [instance-id] %s [current-status] %s [status-requested] %s",
+ clusterInactivateEvent.getClusterId(), clusterInactivateEvent.getInstanceId(),
+ context.getStatus(), status));
+ return;
+ }
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ }
+
+ private static void deleteAppResourcesFromMetadataService(ApplicationInstanceTerminatedEvent event) {
+ try {
+ MetaDataServiceClient metadataClient = new DefaultMetaDataServiceClient();
+ metadataClient.deleteApplicationProperties(event.getAppId());
+ } catch (Exception e) {
+ log.error("Error occurred while deleting the application resources frm metadata service ", e);
+ }
+ }
+
+ public static void handleClusterTerminatedEvent(ClusterStatusClusterTerminatedEvent event) {
+
+ TopologyManager.acquireWriteLock();
+
+ try {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(event.getServiceName());
+
+ //update the status of the cluster
+ if (service == null) {
+ log.warn(String.format("Service %s does not exist", event.getServiceName()));
+ return;
+ }
+
+ Cluster cluster = service.getCluster(event.getClusterId());
+ if (cluster == null) {
+ log.warn(String.format("Cluster %s does not exist", event.getClusterId()));
+ return;
+ }
+
+ ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
+ if (context == null) {
+ log.warn("Cluster Instance Context is not found for [cluster] " +
+ event.getClusterId() + " [instance-id] " +
+ event.getInstanceId());
+ return;
+ }
+ ClusterStatus status = ClusterStatus.Terminated;
+ if (context.isStateTransitionValid(status)) {
+ context.setStatus(status);
+ log.info("Cluster Terminated adding status started for and removing the cluster instance" +
+ cluster.getClusterId());
+ cluster.removeInstanceContext(event.getInstanceId());
+ TopologyManager.updateTopology(topology);
+ //publishing data
+ ClusterInstanceTerminatedEvent clusterTerminatedEvent =
+ new ClusterInstanceTerminatedEvent(event.getAppId(), event.getServiceName(),
+ event.getClusterId(), event.getInstanceId());
+
+ TopologyEventPublisher.sendClusterTerminatedEvent(clusterTerminatedEvent);
+ } else {
+ log.error(String.format("Cluster state transition is not valid: [cluster-id] %s " +
+ " [instance-id] %s [current-status] %s [status-requested] %s",
+ event.getClusterId(), event.getInstanceId(), context.getStatus(), status));
+ return;
+ }
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+
+ }
+
+ public static void handleClusterTerminatingEvent(ClusterStatusClusterTerminatingEvent event) {
+
+ TopologyManager.acquireWriteLock();
+
+ try {
+ Topology topology = TopologyManager.getTopology();
+ Cluster cluster = topology.getService(event.getServiceName()).
+ getCluster(event.getClusterId());
+
+ if (!cluster.isStateTransitionValid(ClusterStatus.Terminating, event.getInstanceId())) {
+ log.error("Invalid state transfer from " + cluster.getStatus(event.getInstanceId()) + " to " +
+ ClusterStatus.Terminating);
+ }
+ ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
+ if (context == null) {
+ log.warn("Cluster Instance Context is not found for [cluster] " +
+ event.getClusterId() + " [instance-id] " +
+ event.getInstanceId());
+ return;
+ }
+ ClusterStatus status = ClusterStatus.Terminating;
+ if (context.isStateTransitionValid(status)) {
+ context.setStatus(status);
+ log.info("Cluster Terminating started for " + cluster.getClusterId());
+ TopologyManager.updateTopology(topology);
+ //publishing data
+ ClusterInstanceTerminatingEvent clusterTerminaingEvent =
+ new ClusterInstanceTerminatingEvent(event.getAppId(), event.getServiceName(),
+ event.getClusterId(), event.getInstanceId());
+
+ TopologyEventPublisher.sendClusterTerminatingEvent(clusterTerminaingEvent);
+
+ // Remove kubernetes services if available
+ ClusterContext clusterContext =
+ CloudControllerContext.getInstance().getClusterContext(event.getClusterId());
+ if (StringUtils.isNotBlank(clusterContext.getKubernetesClusterId())) {
+ KubernetesIaas.removeKubernetesServices(event.getAppId(
<TRUNCATED>
[09/18] stratos git commit: Publishing events for Metering Service
Implementation
Posted by im...@apache.org.
Publishing events for Metering Service Implementation
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/07e86193
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/07e86193
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/07e86193
Branch: refs/heads/master
Commit: 07e861937818e3dfae5ee40ce5b5cb7b31668a4b
Parents: 76c7724
Author: Thanuja <th...@wso2.com>
Authored: Wed Jul 22 17:55:51 2015 +0530
Committer: Thanuja <th...@wso2.com>
Committed: Wed Jul 22 17:55:51 2015 +0530
----------------------------------------------------------------------
.../messaging/topology/TopologyBuilder.java | 17 +-
.../impl/CloudControllerServiceUtil.java | 5 +-
.../modules/healthstatspublisher/healthstats.py | 6 +-
.../streamdefinitions/stream-manager-config.xml | 486 ++++++++++---------
.../src/main/conf/drools/mincheck.drl | 4 +-
.../src/main/conf/drools/scaling.drl | 10 +-
.../main/resources/CloudControllerService.wsdl | 450 +++++++++--------
7 files changed, 493 insertions(+), 485 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/07e86193/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java
----------------------------------------------------------------------
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 dba9670..802dfc8 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
@@ -490,8 +490,8 @@ public class TopologyBuilder {
//publishing data
BAMUsageDataPublisher.publish(memberContext.getMemberId(), memberContext.getPartition().getId(),
memberContext.getNetworkPartitionId(), memberContext.getClusterId(),
- memberContext.getCartridgeType(), MemberStatus.Initialized.toString(),
- timeStamp, null, null, null);
+ memberContext.getClusterInstanceId(), memberContext.getCartridgeType(),
+ MemberStatus.Initialized.toString(), timeStamp, null, null, null);
}
} finally {
TopologyManager.releaseWriteLock();
@@ -550,8 +550,8 @@ public class TopologyBuilder {
BAMUsageDataPublisher
.publish(instanceStartedEvent.getMemberId(), instanceStartedEvent.getPartitionId(),
instanceStartedEvent.getNetworkPartitionId(), instanceStartedEvent.getClusterId(),
- instanceStartedEvent.getServiceName(), MemberStatus.Starting.toString(), null,
- null, null);
+ instanceStartedEvent.getClusterInstanceId(), instanceStartedEvent.getServiceName(),
+ MemberStatus.Starting.toString(), timeStamp, null, null, null);
}
} finally {
TopologyManager.releaseWriteLock();
@@ -654,8 +654,9 @@ public class TopologyBuilder {
BAMUsageDataPublisher.publish(memberActivatedEvent.getMemberId(), memberActivatedEvent.getPartitionId(),
memberActivatedEvent.getNetworkPartitionId(),
memberActivatedEvent.getClusterId(),
+ memberActivatedEvent.getClusterInstanceId(),
memberActivatedEvent.getServiceName(), MemberStatus.Active.toString(),
- null, null, null);
+ timeStamp, null, null, null);
}
} finally {
TopologyManager.releaseWriteLock();
@@ -714,8 +715,10 @@ public class TopologyBuilder {
BAMUsageDataPublisher
.publish(instanceReadyToShutdownEvent.getMemberId(), instanceReadyToShutdownEvent.getPartitionId(),
instanceReadyToShutdownEvent.getNetworkPartitionId(),
- instanceReadyToShutdownEvent.getClusterId(), instanceReadyToShutdownEvent.getServiceName(),
- MemberStatus.ReadyToShutDown.toString(), null, null, null);
+ instanceReadyToShutdownEvent.getClusterId(),
+ instanceReadyToShutdownEvent.getClusterInstanceId(),
+ instanceReadyToShutdownEvent.getServiceName(), MemberStatus.ReadyToShutDown.toString(),
+ timeStamp, null, null, null);
//termination of particular instance will be handled by autoscaler
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/07e86193/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java
index 571ba9a..64c264a 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java
@@ -69,8 +69,9 @@ public class CloudControllerServiceUtil {
Long timeStamp = System.currentTimeMillis();
// Publish statistics to BAM
BAMUsageDataPublisher.publish(memberContext.getMemberId(), partitionId, memberContext.getNetworkPartitionId(),
- memberContext.getClusterId(), memberContext.getCartridgeType(),
- MemberStatus.Terminated.toString(), timeStamp, null, null, null);
+ memberContext.getClusterId(), memberContext.getClusterInstanceId(),
+ memberContext.getCartridgeType(), MemberStatus.Terminated.toString(), timeStamp,
+ null, null, null);
// Remove member context
CloudControllerContext.getInstance()
http://git-wip-us.apache.org/repos/asf/stratos/blob/07e86193/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/healthstatspublisher/healthstats.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/healthstatspublisher/healthstats.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/healthstatspublisher/healthstats.py
index 9753c3e..711fe43 100644
--- a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/healthstatspublisher/healthstats.py
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/healthstatspublisher/healthstats.py
@@ -17,7 +17,7 @@
from threading import Thread
import multiprocessing
-
+import time
import psutil
from abstracthealthstatisticspublisher import *
@@ -124,6 +124,8 @@ class HealthStatisticsPublisher:
stream_def.description = HealthStatisticsPublisherManager.STREAM_DESCRIPTION
# stream_def.add_payloaddata_attribute()
+
+ #stream_def.add_payloaddata_attribute("time_stamp", StreamDefinition.LONG)
stream_def.add_payloaddata_attribute("cluster_id", StreamDefinition.STRING)
stream_def.add_payloaddata_attribute("cluster_instance_id", StreamDefinition.STRING)
stream_def.add_payloaddata_attribute("network_partition_id", StreamDefinition.STRING)
@@ -141,6 +143,7 @@ class HealthStatisticsPublisher:
"""
event = ThriftEvent()
+ #event.payloadData.append(int(round(time.time() * 1000)))
event.payloadData.append(self.cartridge_agent_config.cluster_id)
event.payloadData.append(self.cartridge_agent_config.cluster_instance_id)
event.payloadData.append(self.cartridge_agent_config.network_partition_id)
@@ -159,6 +162,7 @@ class HealthStatisticsPublisher:
"""
event = ThriftEvent()
+ #Sevent.payloadData.append(int(round(time.time() * 1000)))
event.payloadData.append(self.cartridge_agent_config.cluster_id)
event.payloadData.append(self.cartridge_agent_config.cluster_instance_id)
event.payloadData.append(self.cartridge_agent_config.network_partition_id)
http://git-wip-us.apache.org/repos/asf/stratos/blob/07e86193/extensions/cep/artifacts/streamdefinitions/stream-manager-config.xml
----------------------------------------------------------------------
diff --git a/extensions/cep/artifacts/streamdefinitions/stream-manager-config.xml b/extensions/cep/artifacts/streamdefinitions/stream-manager-config.xml
index 4c4c7e0..39fc4f3 100644
--- a/extensions/cep/artifacts/streamdefinitions/stream-manager-config.xml
+++ b/extensions/cep/artifacts/streamdefinitions/stream-manager-config.xml
@@ -23,287 +23,289 @@
<streamManagerConfiguration xmlns="http://wso2.org/carbon/streammanager">
<!-- in-flight requests stream definitions start -->
<streamDefinition name="in_flight_requests" version="1.0.0">
- <description>in-flight request count</description>
- <nickName>in-flight requests</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String"/>
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="in_flight_request_count" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>in-flight request count</description>
+ <nickName>in-flight requests</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <!-- <property name="time_stamp" type="long"/>-->
+ <property name="cluster_id" type="String"/>
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="in_flight_request_count" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="gradient_in_flight_requests" version="1.0.0">
- <description>gradient of in flight request count</description>
- <nickName>gradient in flight requests</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String"/>
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="count" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>gradient of in flight request count</description>
+ <nickName>gradient in flight requests</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="cluster_id" type="String"/>
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="count" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="average_in_flight_requests" version="1.0.0">
- <description>average of in-flight request count</description>
- <nickName>average in-flight requests</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String"/>
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="count" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>average of in-flight request count</description>
+ <nickName>average in-flight requests</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="cluster_id" type="String"/>
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="count" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="second_derivative_in_flight_requests" version="1.0.0">
- <description>second derivative of in-flight request count</description>
- <nickName>second derivative in-flight requests</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String"/>
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="count" type="double"/>
- </payloadData>
+ <description>second derivative of in-flight request count</description>
+ <nickName>second derivative in-flight requests</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="cluster_id" type="String"/>
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="count" type="double"/>
+ </payloadData>
</streamDefinition>
<!-- in-flight requests stream definitions end -->
<!-- cartridge agent health stats stream definitions start -->
<streamDefinition name="cartridge_agent_health_stats" version="1.0.0">
- <description>agent health stats</description>
- <nickName>agent health stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="member_id" type="String" />
- <property name="partition_id" type="String" />
- <property name="health_description" type="String"/>
- <property name="value" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>agent health stats</description>
+ <nickName>agent health stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <!--<property name="time_stamp" type="long"/>-->
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="member_id" type="String" />
+ <property name="partition_id" type="String" />
+ <property name="health_description" type="String"/>
+ <property name="value" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="average_load_average_stats" version="1.0.0">
- <description>average load average stats</description>
- <nickName>average load average stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="average_load_average" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>average load average stats</description>
+ <nickName>average load average stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="average_load_average" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="average_memory_consumption_stats" version="1.0.0">
- <description>average memory consumption stats</description>
- <nickName>average memory consumption stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String"/>
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="average_memory_consumption" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>average memory consumption stats</description>
+ <nickName>average memory consumption stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="cluster_id" type="String"/>
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="average_memory_consumption" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="gradient_load_average_stats" version="1.0.0">
- <description>gradient load average stats</description>
- <nickName>gradient load average stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="gradient_load_average" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>gradient load average stats</description>
+ <nickName>gradient load average stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="gradient_load_average" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="gradient_memory_consumption_stats" version="1.0.0">
- <description>gradient memoryconsumption stats</description>
- <nickName>gradient memoryconsumption stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="gradient_memory_consumption" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>gradient memoryconsumption stats</description>
+ <nickName>gradient memoryconsumption stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="gradient_memory_consumption" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="second_derivative_memory_consumption_stats" version="1.0.0">
- <description>second derivative memory consumption stats</description>
- <nickName>second derivative memory consumption stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="second_derivative_memory_consumption" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>second derivative memory consumption stats</description>
+ <nickName>second derivative memory consumption stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="second_derivative_memory_consumption" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="second_derivative_load_average_stats" version="1.0.0">
- <description>second derivative load average stats</description>
- <nickName>second derivative load average stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="second_derivative_load_average" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>second derivative load average stats</description>
+ <nickName>second derivative load average stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="second_derivative_load_average" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="fault_message" version="1.0.0">
- <description>fault message</description>
- <nickName>fault message</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String"/>
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="member_id" type="String"/>
- <property name="partition_id" type="String"/>
- </payloadData>
+ <description>fault message</description>
+ <nickName>fault message</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="cluster_id" type="String"/>
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="member_id" type="String"/>
+ <property name="partition_id" type="String"/>
+ </payloadData>
</streamDefinition>
<!-- cartridge agent health stats stream definitions end -->
<!-- This is for member_id wise grouping-->
<streamDefinition name="member_average_load_average_stats" version="1.0.0">
- <description>average load average stats</description>
- <nickName>average load average stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="member_id" type="String" />
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="member_average_load_average" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>average load average stats</description>
+ <nickName>average load average stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="member_id" type="String" />
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="member_average_load_average" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="member_average_memory_consumption_stats" version="1.0.0">
- <description>average memory consumption stats</description>
- <nickName>average memory consumption stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="member_id" type="String"/>
- <property name="cluster_id" type="String"/>
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="member_average_memory_consumption" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>average memory consumption stats</description>
+ <nickName>average memory consumption stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="member_id" type="String"/>
+ <property name="cluster_id" type="String"/>
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="member_average_memory_consumption" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="member_gradient_load_average_stats" version="1.0.0">
- <description>gradient load average stats</description>
- <nickName>gradient load average stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="member_id" type="String" />
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="member_gradient_load_average" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>gradient load average stats</description>
+ <nickName>gradient load average stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="member_id" type="String" />
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="member_gradient_load_average" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="member_gradient_memory_consumption_stats" version="1.0.0">
- <description>gradient memoryconsumption stats</description>
- <nickName>gradient memoryconsumption stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="member_id" type="String" />
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="member_gradient_memory_consumption" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>gradient memoryconsumption stats</description>
+ <nickName>gradient memoryconsumption stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="member_id" type="String" />
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="member_gradient_memory_consumption" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="member_second_derivative_memory_consumption_stats" version="1.0.0">
- <description>second derivative memory consumption stats</description>
- <nickName>second derivative memory consumption stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="member_id" type="String" />
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="member_second_derivative_memory_consumption" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>second derivative memory consumption stats</description>
+ <nickName>second derivative memory consumption stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="member_id" type="String" />
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="member_second_derivative_memory_consumption" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="member_second_derivative_load_average_stats" version="1.0.0">
- <description>second derivative load average stats</description>
- <nickName>second derivative load average stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="member_id" type="String" />
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="member_second_derivative_load_average" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>second derivative load average stats</description>
+ <nickName>second derivative load average stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="member_id" type="String" />
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="member_second_derivative_load_average" type="double"/>
+ </payloadData>
+ </streamDefinition>
</streamManagerConfiguration>
http://git-wip-us.apache.org/repos/asf/stratos/blob/07e86193/products/stratos/modules/distribution/src/main/conf/drools/mincheck.drl
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/conf/drools/mincheck.drl b/products/stratos/modules/distribution/src/main/conf/drools/mincheck.drl
index 96b60da..00a1850 100755
--- a/products/stratos/modules/distribution/src/main/conf/drools/mincheck.drl
+++ b/products/stratos/modules/distribution/src/main/conf/drools/mincheck.drl
@@ -84,7 +84,9 @@ dialect "mvel"
log.info("[min-check] Partition available, hence trying to spawn an instance to fulfil minimum count!" + " [cluster] " + clusterId);
log.debug("[min-check] " + " [partition] " + partitionContext.getPartitionId() + " [cluster] " + clusterId);
- delegator.delegateSpawn(partitionContext, clusterId, clusterInstanceContext.getId(), isPrimary);
+ long time = System.currentTimeMillis();
+ String scalingReason = "Scaling up to fulfil minimum count";
+ delegator.delegateSpawn(partitionContext, clusterId, clusterInstanceContext.getId(), isPrimary,scalingReason,time);
count++;
} else {
http://git-wip-us.apache.org/repos/asf/stratos/blob/07e86193/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl b/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl
index cad9c8f..ca532de 100644
--- a/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl
+++ b/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl
@@ -69,7 +69,7 @@ dialect "mvel"
eval(log.debug("[scaling] [network-partition] " + clusterInstanceContext.getNetworkPartitionId() + " [cluster] "
+ clusterId + " Algorithm name: " + algorithmName))
-
+
rifThreshold : Float() from loadThresholds.getRequestsInFlightThreshold()
rifAverage : Float() from clusterInstanceContext.getAverageRequestsInFlight()
@@ -163,6 +163,7 @@ dialect "mvel"
boolean partitionsAvailable = true;
int count = 0;
+ String autoscalingReason = (numberOfRequiredInstances == numberOfInstancesReuquiredBasedOnRif)?"Scaling up due to RIF":(numberOfRequiredInstances== numberOfInstancesReuquiredBasedOnMemoryConsumption)?"Scaling up due to MC":"Scaling up due to LA";
String autoscalingReason = (numberOfRequiredInstances == numberOfInstancesReuquiredBasedOnRif)?"Scaling up due to RIF":(numberOfRequiredInstances== numberOfInstancesReuquiredBasedOnMemoryConsumption)?"Scaling up due to MC":"Scaling up due to LA";
@@ -199,12 +200,9 @@ dialect "mvel"
}
}
} else {
- log.info("[scale-up] Trying to scale up over max, hence not scaling up cluster itself and
- notifying to parent for possible group scaling or app bursting.
- [cluster] " + clusterId + " [instance id]" + clusterInstanceContext.getId() +
+ log.info("[scale-up] Trying to scale up over max, hence not scaling up cluster itself and notifying to parent for possible group scaling or app bursting. [cluster] " + clusterId + " [instance id]" + clusterInstanceContext.getId() +
" [max] " + clusterMaxMembers);
- delegator.delegateScalingOverMaxNotification(clusterId, clusterInstanceContext.getNetworkPartitionId(),
- clusterInstanceContext.getId());
+ delegator.delegateScalingOverMaxNotification(clusterId, clusterInstanceContext.getNetworkPartitionId(),clusterInstanceContext.getId());
}
} else if(scaleDown){
http://git-wip-us.apache.org/repos/asf/stratos/blob/07e86193/service-stubs/org.apache.stratos.cloud.controller.service.stub/src/main/resources/CloudControllerService.wsdl
----------------------------------------------------------------------
diff --git a/service-stubs/org.apache.stratos.cloud.controller.service.stub/src/main/resources/CloudControllerService.wsdl b/service-stubs/org.apache.stratos.cloud.controller.service.stub/src/main/resources/CloudControllerService.wsdl
index 03abeb0..5499a5f 100644
--- a/service-stubs/org.apache.stratos.cloud.controller.service.stub/src/main/resources/CloudControllerService.wsdl
+++ b/service-stubs/org.apache.stratos.cloud.controller.service.stub/src/main/resources/CloudControllerService.wsdl
@@ -1,66 +1,89 @@
-<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="http://impl.services.controller.cloud.stratos.apache.org" xmlns:ax27="http://kubernetes.domain.controller.cloud.stratos.apache.org/xsd" xmlns:ax23="http://domain.controller.cloud.stratos.apache.org/xsd" xmlns:ax24="http://common.stratos.apache.org/xsd" xmlns:ax21="http://exception.controller.cloud.stratos.apache.org/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ax212="http://topology.domain.messaging.stratos.apache.org/xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:ax210="http://domain.common.stratos.apache.org/xsd" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://impl.services.controller.cloud.stratos.apache.org">
+<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ax29="http://kubernetes.domain.controller.cloud.stratos.apache.org/xsd" xmlns:ns="http://impl.services.controller.cloud.stratos.apache.org" xmlns:ax27="http://domain.common.stratos.apache.org/xsd" xmlns:ax23="http://domain.controller.cloud.stratos.apache.org/xsd" xmlns:ax24="http://common.stratos.apache.org/xsd" xmlns:ax21="http://exception.controller.cloud.stratos.apache.org/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ax212="http://topology.domain.messaging.stratos.apache.org/xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://impl.services.controller.cloud.stratos.apache.org">
<wsdl:types>
- <xs:schema xmlns:ax29="http://kubernetes.domain.controller.cloud.stratos.apache.org/xsd" xmlns:ax213="http://topology.domain.messaging.stratos.apache.org/xsd" xmlns:ax26="http://domain.controller.cloud.stratos.apache.org/xsd" xmlns:ax22="http://exception.controller.cloud.stratos.apache.org/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://impl.services.controller.cloud.stratos.apache.org">
+ <xs:schema xmlns:ax213="http://topology.domain.messaging.stratos.apache.org/xsd" xmlns:ax26="http://domain.controller.cloud.stratos.apache.org/xsd" xmlns:ax211="http://kubernetes.domain.controller.cloud.stratos.apache.org/xsd" xmlns:ax22="http://exception.controller.cloud.stratos.apache.org/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://impl.services.controller.cloud.stratos.apache.org">
<xs:import namespace="http://exception.controller.cloud.stratos.apache.org/xsd"/>
<xs:import namespace="http://domain.controller.cloud.stratos.apache.org/xsd"/>
<xs:import namespace="http://kubernetes.domain.controller.cloud.stratos.apache.org/xsd"/>
<xs:import namespace="http://topology.domain.messaging.stratos.apache.org/xsd"/>
- <xs:element name="getIaasProviders">
+ <xs:element name="CloudControllerServiceCartridgeNotFoundException">
<xs:complexType>
- <xs:sequence/>
+ <xs:sequence>
+ <xs:element minOccurs="0" name="CartridgeNotFoundException" nillable="true" type="ax21:CartridgeNotFoundException"/>
+ </xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="getIaasProvidersResponse">
+ <xs:element name="CloudControllerServiceInvalidIaasProviderException">
<xs:complexType>
<xs:sequence>
- <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="InvalidIaasProviderException" nillable="true" type="ax21:InvalidIaasProviderException"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="getCartridges">
+ <xs:element name="CloudControllerServiceCloudControllerException">
<xs:complexType>
- <xs:sequence/>
+ <xs:sequence>
+ <xs:element minOccurs="0" name="CloudControllerException" nillable="true" type="ax21:CloudControllerException"/>
+ </xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="getCartridgesResponse">
+ <xs:element name="startInstance">
<xs:complexType>
<xs:sequence>
- <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="instanceContext" nillable="true" type="ax26:InstanceContext"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="CloudControllerServiceCartridgeNotFoundException">
+ <xs:element name="startInstanceResponse">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="CartridgeNotFoundException" nillable="true" type="ax21:CartridgeNotFoundException"/>
+ <xs:element minOccurs="0" name="return" nillable="true" type="ax26:MemberContext"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="getCartridge">
+ <xs:element name="CloudControllerServiceInvalidMemberException">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="cartridgeType" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="InvalidMemberException" nillable="true" type="ax21:InvalidMemberException"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="getCartridgeResponse">
+ <xs:element name="CloudControllerServiceInvalidCartridgeTypeException">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="return" nillable="true" type="ax26:Cartridge"/>
+ <xs:element minOccurs="0" name="InvalidCartridgeTypeException" nillable="true" type="ax21:InvalidCartridgeTypeException"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="CloudControllerServiceInvalidCartridgeDefinitionException">
+ <xs:element name="terminateInstance">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="InvalidCartridgeDefinitionException" nillable="true" type="ax21:InvalidCartridgeDefinitionException"/>
+ <xs:element minOccurs="0" name="memberId" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="CloudControllerServiceInvalidIaasProviderException">
+ <xs:element name="terminateInstanceResponse">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="InvalidIaasProviderException" nillable="true" type="ax21:InvalidIaasProviderException"/>
+ <xs:element minOccurs="0" name="return" type="xs:boolean"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="getIaasProviders">
+ <xs:complexType>
+ <xs:sequence/>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="getIaasProvidersResponse">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="CloudControllerServiceInvalidCartridgeDefinitionException">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element minOccurs="0" name="InvalidCartridgeDefinitionException" nillable="true" type="ax21:InvalidCartridgeDefinitionException"/>
</xs:sequence>
</xs:complexType>
</xs:element>
@@ -160,13 +183,6 @@
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="CloudControllerServiceInvalidCartridgeTypeException">
- <xs:complexType>
- <xs:sequence>
- <xs:element minOccurs="0" name="InvalidCartridgeTypeException" nillable="true" type="ax21:InvalidCartridgeTypeException"/>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
<xs:element name="removeCartridge">
<xs:complexType>
<xs:sequence>
@@ -265,6 +281,18 @@
</xs:sequence>
</xs:complexType>
</xs:element>
+ <xs:element name="getCartridges">
+ <xs:complexType>
+ <xs:sequence/>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="getCartridgesResponse">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
<xs:element name="CloudControllerServiceNonExistingKubernetesClusterException">
<xs:complexType>
<xs:sequence>
@@ -375,45 +403,17 @@
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="CloudControllerServiceCloudControllerException">
- <xs:complexType>
- <xs:sequence>
- <xs:element minOccurs="0" name="CloudControllerException" nillable="true" type="ax21:CloudControllerException"/>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- <xs:element name="startInstance">
- <xs:complexType>
- <xs:sequence>
- <xs:element minOccurs="0" name="instanceContext" nillable="true" type="ax26:InstanceContext"/>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- <xs:element name="startInstanceResponse">
- <xs:complexType>
- <xs:sequence>
- <xs:element minOccurs="0" name="return" nillable="true" type="ax26:MemberContext"/>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- <xs:element name="CloudControllerServiceInvalidMemberException">
- <xs:complexType>
- <xs:sequence>
- <xs:element minOccurs="0" name="InvalidMemberException" nillable="true" type="ax21:InvalidMemberException"/>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- <xs:element name="terminateInstance">
+ <xs:element name="getCartridge">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="memberId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="cartridgeType" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="terminateInstanceResponse">
+ <xs:element name="getCartridgeResponse">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="return" type="xs:boolean"/>
+ <xs:element minOccurs="0" name="return" nillable="true" type="ax26:Cartridge"/>
</xs:sequence>
</xs:complexType>
</xs:element>
@@ -480,116 +480,116 @@
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="validateDeploymentPolicyNetworkPartition">
+ <xs:element name="startInstances">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="cartridgeType" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="networkPartitionId" nillable="true" type="xs:string"/>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="instanceContexts" nillable="true" type="ax26:InstanceContext"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="validateDeploymentPolicyNetworkPartitionResponse">
+ <xs:element name="startInstancesResponse">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="return" type="xs:boolean"/>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ax26:MemberContext"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="registerService">
+ <xs:element name="terminateInstanceForcefully">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="registrant" nillable="true" type="ax26:Registrant"/>
+ <xs:element minOccurs="0" name="memberId" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="registerServiceResponse">
+ <xs:element name="terminateInstanceForcefullyResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="startInstances">
+ <xs:element name="CloudControllerServiceInvalidClusterException">
<xs:complexType>
<xs:sequence>
- <xs:element maxOccurs="unbounded" minOccurs="0" name="instanceContexts" nillable="true" type="ax26:InstanceContext"/>
+ <xs:element minOccurs="0" name="InvalidClusterException" nillable="true" type="ax21:InvalidClusterException"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="startInstancesResponse">
+ <xs:element name="terminateInstances">
<xs:complexType>
<xs:sequence>
- <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ax26:MemberContext"/>
+ <xs:element minOccurs="0" name="clusterId" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="terminateInstanceForcefully">
+ <xs:element name="terminateInstancesResponse">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="memberId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="terminateInstanceForcefullyResponse">
+ <xs:element name="registerService">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="return" type="xs:boolean"/>
+ <xs:element minOccurs="0" name="registrant" nillable="true" type="ax26:Registrant"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="CloudControllerServiceInvalidClusterException">
+ <xs:element name="registerServiceResponse">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="InvalidClusterException" nillable="true" type="ax21:InvalidClusterException"/>
+ <xs:element minOccurs="0" name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="terminateInstances">
+ <xs:element name="CloudControllerServiceUnregisteredClusterException">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="clusterId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="UnregisteredClusterException" nillable="true" type="ax21:UnregisteredClusterException"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="terminateInstancesResponse">
+ <xs:element name="unregisterService">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="return" type="xs:boolean"/>
+ <xs:element minOccurs="0" name="clusterId" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="updateClusterStatus">
+ <xs:element name="unregisterServiceResponse">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="serviceName" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="clusterId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="instanceId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="status" nillable="true" type="ax212:ClusterStatus"/>
+ <xs:element minOccurs="0" name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="updateClusterStatusResponse">
+ <xs:element name="validateDeploymentPolicyNetworkPartition">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="return" type="xs:boolean"/>
+ <xs:element minOccurs="0" name="cartridgeType" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="networkPartitionId" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="CloudControllerServiceUnregisteredClusterException">
+ <xs:element name="validateDeploymentPolicyNetworkPartitionResponse">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="UnregisteredClusterException" nillable="true" type="ax21:UnregisteredClusterException"/>
+ <xs:element minOccurs="0" name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="unregisterService">
+ <xs:element name="updateClusterStatus">
<xs:complexType>
<xs:sequence>
+ <xs:element minOccurs="0" name="serviceName" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="clusterId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="instanceId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="status" nillable="true" type="ax212:ClusterStatus"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="unregisterServiceResponse">
+ <xs:element name="updateClusterStatusResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:boolean"/>
@@ -694,42 +694,42 @@
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="updateKubernetesHost">
+ <xs:element name="CloudControllerServiceInvalidKubernetesMasterException">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="kubernetesHost" nillable="true" type="ax29:KubernetesHost"/>
+ <xs:element minOccurs="0" name="InvalidKubernetesMasterException" nillable="true" type="ax21:InvalidKubernetesMasterException"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="updateKubernetesHostResponse">
+ <xs:element name="CloudControllerServiceNonExistingKubernetesMasterException">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="return" type="xs:boolean"/>
+ <xs:element minOccurs="0" name="NonExistingKubernetesMasterException" nillable="true" type="ax21:NonExistingKubernetesMasterException"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="CloudControllerServiceInvalidKubernetesMasterException">
+ <xs:element name="updateKubernetesMaster">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="InvalidKubernetesMasterException" nillable="true" type="ax21:InvalidKubernetesMasterException"/>
+ <xs:element minOccurs="0" name="kubernetesMaster" nillable="true" type="ax29:KubernetesMaster"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="CloudControllerServiceNonExistingKubernetesMasterException">
+ <xs:element name="updateKubernetesMasterResponse">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="NonExistingKubernetesMasterException" nillable="true" type="ax21:NonExistingKubernetesMasterException"/>
+ <xs:element minOccurs="0" name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="updateKubernetesMaster">
+ <xs:element name="updateKubernetesHost">
<xs:complexType>
<xs:sequence>
- <xs:element minOccurs="0" name="kubernetesMaster" nillable="true" type="ax29:KubernetesMaster"/>
+ <xs:element minOccurs="0" name="kubernetesHost" nillable="true" type="ax29:KubernetesHost"/>
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="updateKubernetesMasterResponse">
+ <xs:element name="updateKubernetesHostResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:boolean"/>
@@ -781,12 +781,29 @@
<xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
- <xs:complexType name="InvalidCartridgeDefinitionException">
+ <xs:complexType name="InvalidIaasProviderException">
<xs:sequence>
<xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
- <xs:complexType name="InvalidIaasProviderException">
+ <xs:complexType name="CloudControllerException">
+ <xs:complexContent>
+ <xs:extension base="xs:RuntimeException">
+ <xs:sequence/>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+ <xs:complexType name="InvalidMemberException">
+ <xs:sequence>
+ <xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="InvalidCartridgeTypeException">
+ <xs:sequence>
+ <xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="InvalidCartridgeDefinitionException">
<xs:sequence>
<xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
</xs:sequence>
@@ -807,11 +824,6 @@
<xs:complexType name="NetworkPartitionNotExistsException">
<xs:sequence/>
</xs:complexType>
- <xs:complexType name="InvalidCartridgeTypeException">
- <xs:sequence>
- <xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
- </xs:sequence>
- </xs:complexType>
<xs:complexType name="CartridgeDefinitionNotExistsException">
<xs:sequence>
<xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
@@ -842,18 +854,6 @@
<xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
- <xs:complexType name="CloudControllerException">
- <xs:complexContent>
- <xs:extension base="xs:RuntimeException">
- <xs:sequence/>
- </xs:extension>
- </xs:complexContent>
- </xs:complexType>
- <xs:complexType name="InvalidMemberException">
- <xs:sequence>
- <xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
- </xs:sequence>
- </xs:complexType>
<xs:complexType name="InvalidPartitionException">
<xs:sequence>
<xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
@@ -895,31 +895,16 @@
</xs:sequence>
</xs:complexType>
</xs:schema>
- <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://domain.common.stratos.apache.org/xsd">
- <xs:complexType name="NameValuePair">
- <xs:sequence>
- <xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="value" nillable="true" type="xs:string"/>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="LoadBalancingIPType">
- <xs:complexContent>
- <xs:extension base="xs:Enum">
- <xs:sequence/>
- </xs:extension>
- </xs:complexContent>
- </xs:complexType>
- </xs:schema>
- <xs:schema xmlns:ax28="http://common.stratos.apache.org/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://kubernetes.domain.controller.cloud.stratos.apache.org/xsd">
+ <xs:schema xmlns:ax210="http://common.stratos.apache.org/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://kubernetes.domain.controller.cloud.stratos.apache.org/xsd">
<xs:import namespace="http://common.stratos.apache.org/xsd"/>
<xs:complexType name="KubernetesCluster">
<xs:sequence>
<xs:element minOccurs="0" name="clusterId" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="description" nillable="true" type="xs:string"/>
- <xs:element maxOccurs="unbounded" minOccurs="0" name="kubernetesHosts" nillable="true" type="ax27:KubernetesHost"/>
- <xs:element minOccurs="0" name="kubernetesMaster" nillable="true" type="ax27:KubernetesMaster"/>
- <xs:element minOccurs="0" name="portRange" nillable="true" type="ax27:PortRange"/>
- <xs:element minOccurs="0" name="properties" nillable="true" type="ax28:Properties"/>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="kubernetesHosts" nillable="true" type="ax29:KubernetesHost"/>
+ <xs:element minOccurs="0" name="kubernetesMaster" nillable="true" type="ax29:KubernetesMaster"/>
+ <xs:element minOccurs="0" name="portRange" nillable="true" type="ax29:PortRange"/>
+ <xs:element minOccurs="0" name="properties" nillable="true" type="ax210:Properties"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="KubernetesHost">
@@ -927,13 +912,13 @@
<xs:element minOccurs="0" name="hostId" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="hostname" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="privateIPAddress" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="properties" nillable="true" type="ax28:Properties"/>
+ <xs:element minOccurs="0" name="properties" nillable="true" type="ax210:Properties"/>
<xs:element minOccurs="0" name="publicIPAddress" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="KubernetesMaster">
<xs:complexContent>
- <xs:extension base="ax27:KubernetesHost">
+ <xs:extension base="ax29:KubernetesHost">
<xs:sequence/>
</xs:extension>
</xs:complexContent>
@@ -945,9 +930,102 @@
</xs:sequence>
</xs:complexType>
</xs:schema>
- <xs:schema xmlns:ax25="http://common.stratos.apache.org/xsd" xmlns:ax211="http://domain.common.stratos.apache.org/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://domain.controller.cloud.stratos.apache.org/xsd">
+ <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://domain.common.stratos.apache.org/xsd">
+ <xs:complexType name="NameValuePair">
+ <xs:sequence>
+ <xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="value" nillable="true" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="LoadBalancingIPType">
+ <xs:complexContent>
+ <xs:extension base="xs:Enum">
+ <xs:sequence/>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+ </xs:schema>
+ <xs:schema xmlns:ax28="http://domain.common.stratos.apache.org/xsd" xmlns:ax25="http://common.stratos.apache.org/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://domain.controller.cloud.stratos.apache.org/xsd">
<xs:import namespace="http://common.stratos.apache.org/xsd"/>
<xs:import namespace="http://domain.common.stratos.apache.org/xsd"/>
+ <xs:complexType name="InstanceContext">
+ <xs:sequence>
+ <xs:element minOccurs="0" name="cartridgeType" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="clusterId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="clusterInstanceId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="initTime" type="xs:long"/>
+ <xs:element minOccurs="0" name="networkPartitionId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="obsoleteExpiryTime" type="xs:long"/>
+ <xs:element minOccurs="0" name="partition" nillable="true" type="ax23:Partition"/>
+ <xs:element minOccurs="0" name="properties" nillable="true" type="ax25:Properties"/>
+ <xs:element minOccurs="0" name="volumeRequired" type="xs:boolean"/>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="volumes" nillable="true" type="ax23:Volume"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="Partition">
+ <xs:sequence>
+ <xs:element minOccurs="0" name="description" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="id" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="isPublic" type="xs:boolean"/>
+ <xs:element minOccurs="0" name="kubernetesClusterId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="partitionMax" type="xs:int"/>
+ <xs:element minOccurs="0" name="properties" nillable="true" type="ax25:Properties"/>
+ <xs:element minOccurs="0" name="provider" nillable="true" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="Volume">
+ <xs:sequence>
+ <xs:element minOccurs="0" name="device" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="iaasType" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="id" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="mappingPath" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="removeOntermination" type="xs:boolean"/>
+ <xs:element minOccurs="0" name="size" type="xs:int"/>
+ <xs:element minOccurs="0" name="snapshotId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="volumeId" nillable="true" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="MemberContext">
+ <xs:sequence>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="allocatedIPs" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="applicationId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="cartridgeType" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="clusterId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="clusterInstanceId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="defaultPrivateIP" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="defaultPublicIP" nillable="true" type="xs:string"/>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="dynamicPayload" nillable="true" type="ax27:NameValuePair"/>
+ <xs:element minOccurs="0" name="initTime" type="xs:long"/>
+ <xs:element minOccurs="0" name="instanceId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="instanceMetadata" nillable="true" type="ax23:InstanceMetadata"/>
+ <xs:element minOccurs="0" name="kubernetesPodId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="kubernetesPodLabel" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="lbClusterId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="loadBalancingIPType" nillable="true" type="ax27:LoadBalancingIPType"/>
+ <xs:element minOccurs="0" name="memberId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="networkPartitionId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="obsoleteExpiryTime" type="xs:long"/>
+ <xs:element minOccurs="0" name="obsoleteInitTime" type="xs:long"/>
+ <xs:element minOccurs="0" name="partition" nillable="true" type="ax23:Partition"/>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="privateIPs" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="properties" nillable="true" type="ax25:Properties"/>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="publicIPs" nillable="true" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="InstanceMetadata">
+ <xs:sequence>
+ <xs:element minOccurs="0" name="cpu" type="xs:int"/>
+ <xs:element minOccurs="0" name="hostname" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="hypervisor" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="imageId" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="loginPort" type="xs:int"/>
+ <xs:element minOccurs="0" name="operatingSystem64bit" type="xs:boolean"/>
+ <xs:element minOccurs="0" name="operatingSystemArchitecture" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="operatingSystemName" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="operatingSystemVersion" nillable="true" type="xs:string"/>
+ <xs:element minOccurs="0" name="ram" type="xs:int"/>
+ </xs:sequence>
+ </xs:complexType>
<xs:complexType name="Cartridge">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="appTypeMappings" nillable="true" type="ax23:AppType"/>
@@ -1023,22 +1101,8 @@
<xs:element maxOccurs="unbounded" minOccurs="0" name="volumes" nillable="true" type="ax23:Volume"/>
</xs:sequence>
</xs:complexType>
- <xs:complexType name="Volume">
- <xs:sequence>
- <xs:element minOccurs="0" name="device" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="iaasType" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="id" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="mappingPath" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="removeOntermination" type="xs:boolean"/>
- <xs:element minOccurs="0" name="size" type="xs:int"/>
- <xs:element minOccurs="0" name="snapshotId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="volumeId" nillable="true" type="xs:string"/>
- </xs:sequence>
- </xs:complexType>
<xs:complexType name="PortMapping">
<xs:sequence>
- <xs:element minOccurs="0" name="kubernetesServicePort" type="xs:int"/>
- <xs:element minOccurs="0" name="kubernetesServicePortMapping" type="xs:boolean"/>
<xs:element minOccurs="0" name="name" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="port" type="xs:int"/>
<xs:element minOccurs="0" name="protocol" nillable="true" type="xs:string"/>
@@ -1055,17 +1119,6 @@
<xs:element minOccurs="0" name="provider" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
- <xs:complexType name="Partition">
- <xs:sequence>
- <xs:element minOccurs="0" name="description" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="id" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="isPublic" type="xs:boolean"/>
- <xs:element minOccurs="0" name="kubernetesClusterId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="partitionMax" type="xs:int"/>
- <xs:element minOccurs="0" name="properties" nillable="true" type="ax25:Properties"/>
- <xs:element minOccurs="0" name="provider" nillable="true" type="xs:string"/>
- </xs:sequence>
- </xs:complexType>
<xs:complexType name="ServiceGroup">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="cartridges" nillable="true" type="xs:string"/>
@@ -1096,61 +1149,6 @@
<xs:element maxOccurs="unbounded" minOccurs="0" name="volumes" nillable="true" type="ax23:Volume"/>
</xs:sequence>
</xs:complexType>
- <xs:complexType name="InstanceContext">
- <xs:sequence>
- <xs:element minOccurs="0" name="cartridgeType" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="clusterId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="clusterInstanceId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="initTime" type="xs:long"/>
- <xs:element minOccurs="0" name="networkPartitionId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="obsoleteExpiryTime" type="xs:long"/>
- <xs:element minOccurs="0" name="partition" nillable="true" type="ax23:Partition"/>
- <xs:element minOccurs="0" name="properties" nillable="true" type="ax25:Properties"/>
- <xs:element minOccurs="0" name="volumeRequired" type="xs:boolean"/>
- <xs:element maxOccurs="unbounded" minOccurs="0" name="volumes" nillable="true" type="ax23:Volume"/>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="MemberContext">
- <xs:sequence>
- <xs:element maxOccurs="unbounded" minOccurs="0" name="allocatedIPs" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="applicationId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="cartridgeType" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="clusterId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="clusterInstanceId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="defaultPrivateIP" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="defaultPublicIP" nillable="true" type="xs:string"/>
- <xs:element maxOccurs="unbounded" minOccurs="0" name="dynamicPayload" nillable="true" type="ax210:NameValuePair"/>
- <xs:element minOccurs="0" name="initTime" type="xs:long"/>
- <xs:element minOccurs="0" name="instanceId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="instanceMetadata" nillable="true" type="ax23:InstanceMetadata"/>
- <xs:element minOccurs="0" name="kubernetesPodId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="kubernetesPodLabel" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="lbClusterId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="loadBalancingIPType" nillable="true" type="ax210:LoadBalancingIPType"/>
- <xs:element minOccurs="0" name="memberId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="networkPartitionId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="obsoleteExpiryTime" type="xs:long"/>
- <xs:element minOccurs="0" name="obsoleteInitTime" type="xs:long"/>
- <xs:element minOccurs="0" name="partition" nillable="true" type="ax23:Partition"/>
- <xs:element maxOccurs="unbounded" minOccurs="0" name="privateIPs" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="properties" nillable="true" type="ax25:Properties"/>
- <xs:element maxOccurs="unbounded" minOccurs="0" name="publicIPs" nillable="true" type="xs:string"/>
- </xs:sequence>
- </xs:complexType>
- <xs:complexType name="InstanceMetadata">
- <xs:sequence>
- <xs:element minOccurs="0" name="cpu" type="xs:int"/>
- <xs:element minOccurs="0" name="hostname" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="hypervisor" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="imageId" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="loginPort" type="xs:int"/>
- <xs:element minOccurs="0" name="operatingSystem64bit" type="xs:boolean"/>
- <xs:element minOccurs="0" name="operatingSystemArchitecture" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="operatingSystemName" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="operatingSystemVersion" nillable="true" type="xs:string"/>
- <xs:element minOccurs="0" name="ram" type="xs:int"/>
- </xs:sequence>
- </xs:complexType>
<xs:complexType name="Registrant">
<xs:sequence>
<xs:element minOccurs="0" name="autoScalerPolicyName" nillable="true" type="xs:string"/>
@@ -3136,4 +3134,4 @@
<http:address location="http://localhost:8080/axis2/services/CloudControllerService"/>
</wsdl:port>
</wsdl:service>
-</wsdl:definitions>
+</wsdl:definitions>
\ No newline at end of file
[11/18] stratos git commit: Adding DAS Artifacts
Posted by im...@apache.org.
Adding DAS Artifacts
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/a62fab20
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/a62fab20
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/a62fab20
Branch: refs/heads/master
Commit: a62fab2081f3b015a713465dc40fde3c184aa24e
Parents: 632a3a4
Author: Thanuja <th...@wso2.com>
Authored: Wed Jul 22 18:16:01 2015 +0530
Committer: Thanuja <th...@wso2.com>
Committed: Wed Jul 22 18:16:01 2015 +0530
----------------------------------------------------------------------
DAS-Artifacts/CCEventReceiver.xml | 9 ++
DAS-Artifacts/SparkQuery.txt | 19 ++++
...g.apache.stratos.cloud.controller_1.0.0.json | 112 +++++++++++++++++++
.../org_apache_stratos_cloud_controller.xml | 1 +
DAS-Artifacts/sparkudf-1.0-SNAPSHOT.jar | Bin 0 -> 2428 bytes
5 files changed, 141 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/a62fab20/DAS-Artifacts/CCEventReceiver.xml
----------------------------------------------------------------------
diff --git a/DAS-Artifacts/CCEventReceiver.xml b/DAS-Artifacts/CCEventReceiver.xml
new file mode 100644
index 0000000..0ddd086
--- /dev/null
+++ b/DAS-Artifacts/CCEventReceiver.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<eventReceiver name="CCEventReceiver" statistics="disable"
+ trace="enable" xmlns="http://wso2.org/carbon/eventreceiver">
+ <from eventAdapterType="wso2event">
+ <property name="events.duplicated.in.cluster">false</property>
+ </from>
+ <mapping customMapping="disable" type="wso2event"/>
+ <to streamName="org.apache.stratos.cloud.controller" version="1.0.0"/>
+</eventReceiver>
http://git-wip-us.apache.org/repos/asf/stratos/blob/a62fab20/DAS-Artifacts/SparkQuery.txt
----------------------------------------------------------------------
diff --git a/DAS-Artifacts/SparkQuery.txt b/DAS-Artifacts/SparkQuery.txt
new file mode 100644
index 0000000..39f7d47
--- /dev/null
+++ b/DAS-Artifacts/SparkQuery.txt
@@ -0,0 +1,19 @@
+CREATE TEMPORARY TABLE memberstatus
+USING CarbonAnalytics
+OPTIONS (tableName "ORG_APACHE_STRATOS_CLOUD_CONTROLLER");
+
+CREATE TEMPORARY TABLE memberstatusnew
+USING CarbonAnalytics
+OPTIONS (tableName "CLUSTER_MEMBER_NEW",
+ schema "startTime String, endTime String, clusterId STRING, activatedInstanceCount INT, terminatedInstanceCount INT, activeInstanceCount INT");
+
+
+;WITH InstanceCount as
+(select clusterId, count(case when status='Active' and timeStamp > current_time(null)-60000 and timeStamp <= current_time(null) then 1 else NULL end) as activatedInstanceCount, count(case when status='Terminated' and timeStamp > current_time(null)-60000 and timeStamp <= current_time(null) then 1 else NULL end) as terminatedInstanceCount, (sum(case when status='Active' then 1 else 0 end) - sum(case when status='Terminated' then 1 else 0 end))as activeInstanceCount from memberstatus group by clusterId)
+INSERT INTO table memberstatusnew select time(current_time(null)-60000),time(current_time(null)),clusterId, activatedInstanceCount, terminatedInstanceCount,activeInstanceCount from InstanceCount;
+
+CREATE TEMPORARY TABLE membersnew
+USING CarbonAnalytics
+OPTIONS (tableName "MEMBER_NEW",schema "clusterId STRING, clusterInstanceId STRING, partitionId STRING, networkId STRING, cartridgeType STRING, instanceType STRING, memberId STRING, scalingTime LONG,scalingReason STRING, timeStamp LONG");
+
+INSERT INTO TABLE membersnew select clusterId, clusterInstanceId,partitionId,networkId,cartridgeType,instanceType, memberId, time(scalingTime),scalingReason,time(timeStamp) FROM memberstatus where status='Created';
http://git-wip-us.apache.org/repos/asf/stratos/blob/a62fab20/DAS-Artifacts/org.apache.stratos.cloud.controller_1.0.0.json
----------------------------------------------------------------------
diff --git a/DAS-Artifacts/org.apache.stratos.cloud.controller_1.0.0.json b/DAS-Artifacts/org.apache.stratos.cloud.controller_1.0.0.json
new file mode 100644
index 0000000..de1025f
--- /dev/null
+++ b/DAS-Artifacts/org.apache.stratos.cloud.controller_1.0.0.json
@@ -0,0 +1,112 @@
+{
+ "name": "org.apache.stratos.cloud.controller",
+ "version": "1.0.0",
+ "nickName": "cloud.controller",
+ "description": "Instances booted up by the Cloud Controller",
+ "payloadData": [
+ {
+ "name": "timeStamp",
+ "type": "LONG"
+ },
+ {
+ "name": "memberId",
+ "type": "STRING"
+ },
+ {
+ "name": "cartridgeType",
+ "type": "STRING"
+ },
+ {
+ "name": "clusterId",
+ "type": "STRING"
+ },
+ {
+ "name": "clusterInstanceId",
+ "type": "STRING"
+ },
+ {
+ "name": "lbclusterId",
+ "type": "STRING"
+ },
+ {
+ "name": "partitionId",
+ "type": "STRING"
+ },
+ {
+ "name": "networkId",
+ "type": "STRING"
+ },
+ {
+ "name": "instanceType",
+ "type": "STRING"
+ },
+ {
+ "name": "scalingReason",
+ "type": "STRING"
+ },
+ {
+ "name": "scalingTime",
+ "type": "LONG"
+ },
+ {
+ "name": "isMultiTenant",
+ "type": "STRING"
+ },
+ {
+ "name": "iaas",
+ "type": "STRING"
+ },
+ {
+ "name": "status",
+ "type": "STRING"
+ },
+ {
+ "name": "hostName",
+ "type": "STRING"
+ },
+ {
+ "name": "hypervisor",
+ "type": "STRING"
+ },
+ {
+ "name": "ram",
+ "type": "STRING"
+ },
+ {
+ "name": "imageId",
+ "type": "STRING"
+ },
+ {
+ "name": "loginPort",
+ "type": "INT"
+ },
+ {
+ "name": "osName",
+ "type": "STRING"
+ },
+ {
+ "name": "osVersion",
+ "type": "STRING"
+ },
+ {
+ "name": "osArch",
+ "type": "STRING"
+ },
+ {
+ "name": "is64bitOS",
+ "type": "STRING"
+ },
+ {
+ "name": "privateIPAddresses",
+ "type": "STRING"
+ },
+ {
+ "name": "publicIPAddresses",
+ "type": "STRING"
+ },
+ {
+ "name": "allocateIPAddresses",
+ "type": "STRING"
+ }
+ ]
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/a62fab20/DAS-Artifacts/org_apache_stratos_cloud_controller.xml
----------------------------------------------------------------------
diff --git a/DAS-Artifacts/org_apache_stratos_cloud_controller.xml b/DAS-Artifacts/org_apache_stratos_cloud_controller.xml
new file mode 100644
index 0000000..ee99acd
--- /dev/null
+++ b/DAS-Artifacts/org_apache_stratos_cloud_controller.xml
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?><EventStoreConfiguration><TableSchema><ColumnDefinition><Name>timeStamp</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>LONG</Type></ColumnDefinition><ColumnDefinition><Name>memberId</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>cartridgeType</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>clusterId</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>clusterInstanceId</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScorePar
am>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>lbclusterId</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>partitionId</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>networkId</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>instanceType</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>scalingReason</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam
><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>scalingTime</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>LONG</Type></ColumnDefinition><ColumnDefinition><Name>isMultiTenant</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>iaas</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>status</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>hostName</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><Co
lumnDefinition><Name>hypervisor</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>ram</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>imageId</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>loginPort</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>INTEGER</Type></ColumnDefinition><ColumnDefinition><Name>osName</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>osVersion</Name><EnableIn
dexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>osArch</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>is64bitOS</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>privateIPAddresses</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>publicIPAddresses</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>allocateIPAddresses</Name><EnableIndexing>false<
/EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition></TableSchema><Source><StreamId>org.apache.stratos.cloud.controller:1.0.0</StreamId></Source><RecordStoreName>EVENT_STORE</RecordStoreName></EventStoreConfiguration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/a62fab20/DAS-Artifacts/sparkudf-1.0-SNAPSHOT.jar
----------------------------------------------------------------------
diff --git a/DAS-Artifacts/sparkudf-1.0-SNAPSHOT.jar b/DAS-Artifacts/sparkudf-1.0-SNAPSHOT.jar
new file mode 100644
index 0000000..3328918
Binary files /dev/null and b/DAS-Artifacts/sparkudf-1.0-SNAPSHOT.jar differ
[12/18] stratos git commit: Removing comments and jar
Posted by im...@apache.org.
Removing comments and jar
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/d5d7f79d
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/d5d7f79d
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/d5d7f79d
Branch: refs/heads/master
Commit: d5d7f79d6e6b7069cf1993bd9b085cee599ca7cc
Parents: a62fab2
Author: Thanuja <th...@wso2.com>
Authored: Wed Jul 22 22:14:11 2015 +0530
Committer: Thanuja <th...@wso2.com>
Committed: Wed Jul 22 22:14:11 2015 +0530
----------------------------------------------------------------------
DAS-Artifacts/sparkudf-1.0-SNAPSHOT.jar | Bin 2428 -> 0 bytes
.../stratos/autoscaler/rule/RuleTasksDelegator.java | 4 +---
.../controller/util/CloudControllerConstants.java | 6 ------
3 files changed, 1 insertion(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/d5d7f79d/DAS-Artifacts/sparkudf-1.0-SNAPSHOT.jar
----------------------------------------------------------------------
diff --git a/DAS-Artifacts/sparkudf-1.0-SNAPSHOT.jar b/DAS-Artifacts/sparkudf-1.0-SNAPSHOT.jar
deleted file mode 100644
index 3328918..0000000
Binary files a/DAS-Artifacts/sparkudf-1.0-SNAPSHOT.jar and /dev/null differ
http://git-wip-us.apache.org/repos/asf/stratos/blob/d5d7f79d/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java
----------------------------------------------------------------------
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 5627b8c..3a69880 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
@@ -287,9 +287,7 @@ public class RuleTasksDelegator {
if (log.isDebugEnabled()) {
log.debug("delegateTerminateDependency:memberId:" + memberId);
}
- //InstanceNotificationClient.getInstance().sendMemberCleanupEvent(memberId);
- //partitionContext.moveActiveMemberToTerminationPendingMembers(memberId);
- //CloudControllerClient.getInstance().terminate(memberId);
+
} catch (Exception e) {
log.error("Cannot terminate instance", e);
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/d5d7f79d/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
index 6d07e7f..e2d953b 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
@@ -188,12 +188,6 @@ public final class CloudControllerConstants {
"/" + CLOUD_CONTROLLER_ELEMENT + "/" + BAM_SERVER_ADMIN_USERNAME_ELEMENT;
public static final String BAM_SERVER_ADMIN_PASSWORD_XPATH =
"/" + CLOUD_CONTROLLER_ELEMENT + "/" + BAM_SERVER_ADMIN_PASSWORD_ELEMENT;
- // public static final String CASSANDRA_HOST_ADDRESS_XPATH =
- // "/"+CLOUD_CONTROLLER_ELEMENT+
- // "/"+CASSANDRA_HOST_ADDRESS;
- // public static final String CASSANDRA_HOST_PORT_XPATH =
- // "/"+CLOUD_CONTROLLER_ELEMENT+
- // "/"+CASSANDRA_HOST_PORT;
/**
* Secret Manager related aliases.
[06/18] stratos git commit: Publishing events for Metering Service
Implementation
Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/76c7724b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
index 4d51cc1..6518607 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
@@ -55,1580 +55,1585 @@ import java.util.concurrent.locks.Lock;
*/
public class CloudControllerServiceImpl implements CloudControllerService {
- private static final Log log = LogFactory.getLog(CloudControllerServiceImpl.class);
-
- private static final String PERSISTENCE_MAPPING = "PERSISTENCE_MAPPING";
- public static final String PAYLOAD_PARAMETER = "payload_parameter.";
-
- private CloudControllerContext cloudControllerContext = CloudControllerContext.getInstance();
- private ExecutorService executorService;
-
- public CloudControllerServiceImpl() {
- executorService = StratosThreadPool.getExecutorService("cloud.controller.instance.manager.thread.pool", 50);
-
- }
-
- public boolean addCartridge(Cartridge cartridgeConfig) throws InvalidCartridgeDefinitionException,
- InvalidIaasProviderException, CartridgeAlreadyExistsException {
-
- handleNullObject(cartridgeConfig, "Cartridge definition is null");
-
- if (log.isInfoEnabled()) {
- log.info("Adding cartridge: [cartridge-type] " + cartridgeConfig.getType());
- }
- if (log.isDebugEnabled()) {
- log.debug("Cartridge definition: " + cartridgeConfig.toString());
- }
-
- try {
- CloudControllerUtil.extractIaaSProvidersFromCartridge(cartridgeConfig);
- } catch (Exception e) {
- String message = "Invalid cartridge definition: [cartridge-type] " + cartridgeConfig.getType();
- log.error(message, e);
- throw new InvalidCartridgeDefinitionException(message, e);
- }
-
- String cartridgeType = cartridgeConfig.getType();
- if (cloudControllerContext.getCartridge(cartridgeType) != null) {
- String message = "Cartridge already exists: [cartridge-type] " + cartridgeType;
- log.error(message);
- throw new CartridgeAlreadyExistsException(message);
- }
-
- // Add cartridge to the cloud controller context and persist
- CloudControllerContext.getInstance().addCartridge(cartridgeConfig);
- CloudControllerContext.getInstance().persist();
-
- List<Cartridge> cartridgeList = new ArrayList<Cartridge>();
- cartridgeList.add(cartridgeConfig);
-
- TopologyBuilder.handleServiceCreated(cartridgeList);
-
- if (log.isInfoEnabled()) {
- log.info("Successfully added cartridge: [cartridge-type] " + cartridgeType);
- }
- return true;
- }
-
- @Override
- public boolean updateCartridge(Cartridge cartridge) throws InvalidCartridgeDefinitionException,
- InvalidIaasProviderException,
- CartridgeDefinitionNotExistsException {
-
- handleNullObject(cartridge, "Cartridge definition is null");
-
- if (log.isInfoEnabled()) {
- log.info("Updating cartridge: [cartridge-type] " + cartridge.getType());
- }
- if (log.isDebugEnabled()) {
- log.debug("Cartridge definition: " + cartridge.toString());
- }
-
- try {
- CloudControllerUtil.extractIaaSProvidersFromCartridge(cartridge);
- } catch (Exception e) {
- String msg = "Invalid cartridge definition: [cartridge-type] " + cartridge.getType();
- log.error(msg, e);
- throw new InvalidCartridgeDefinitionException(msg, e);
- }
-
- String cartridgeType = cartridge.getType();
- if (cloudControllerContext.getCartridge(cartridgeType) != null) {
- Cartridge cartridgeToBeRemoved = cloudControllerContext.getCartridge(cartridgeType);
- try {
- removeCartridgeFromCC(cartridgeToBeRemoved.getType());
- } catch (InvalidCartridgeTypeException ignore) {
- }
- copyIaasProviders(cartridge, cartridgeToBeRemoved);
- } else {
- throw new CartridgeDefinitionNotExistsException("This cartridge definition not exists");
- }
-
- // Add cartridge to the cloud controller context and persist
- CloudControllerContext.getInstance().addCartridge(cartridge);
- CloudControllerContext.getInstance().persist();
- // transaction ends
-
- if (log.isInfoEnabled()) {
- log.info("Successfully updated cartridge: [cartridge-type] " + cartridgeType);
- }
- return true;
- }
-
- private void copyIaasProviders(Cartridge destCartridge,
- Cartridge sourceCartridge) {
-
- List<IaasProvider> newIaasProviders = CloudControllerContext.getInstance().getIaasProviders(destCartridge.getType());
-
- Map<String, IaasProvider> iaasProviderMap = CloudControllerContext.getInstance().getPartitionToIaasProvider(sourceCartridge.getType());
-
- if (iaasProviderMap != null) {
- for (Entry<String, IaasProvider> entry : iaasProviderMap.entrySet()) {
- if (entry == null) {
- continue;
- }
- String partitionId = entry.getKey();
- IaasProvider iaasProvider = entry.getValue();
- if (newIaasProviders.contains(iaasProvider)) {
- if (log.isDebugEnabled()) {
- log.debug("Copying partition from the cartridge that is undeployed, to the new cartridge: "
- + "[partition-id] " + partitionId + " [cartridge-type] " + destCartridge.getType());
- }
- CloudControllerContext.getInstance().addIaasProvider(destCartridge.getType(), partitionId,
- newIaasProviders.get(newIaasProviders.indexOf(iaasProvider)));
- }
- }
- }
-
- }
-
- public boolean removeCartridge(String cartridgeType) throws InvalidCartridgeTypeException {
- //Removing the cartridge from CC
- Cartridge cartridge = removeCartridgeFromCC(cartridgeType);
- //removing the cartridge from Topology
- removeCartridgeFromTopology(cartridge);
-
- if (log.isInfoEnabled()) {
- log.info("Successfully removed cartridge: [cartridge-type] " + cartridgeType);
- }
- return true;
- }
-
- private Cartridge removeCartridgeFromCC(String cartridgeType) throws InvalidCartridgeTypeException {
- Cartridge cartridge = null;
- if ((cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType)) != null) {
- if (CloudControllerContext.getInstance().getCartridges().remove(cartridge)) {
- // invalidate partition validation cache
- CloudControllerContext.getInstance().removeFromCartridgeTypeToPartitionIds(cartridgeType);
-
- if (log.isDebugEnabled()) {
- log.debug("Partition cache invalidated for cartridge " + cartridgeType);
- }
-
- CloudControllerContext.getInstance().persist();
-
- if (log.isInfoEnabled()) {
- log.info("Successfully removed cartridge: [cartridge-type] " + cartridgeType);
- }
- return cartridge;
- }
- }
- String msg = "Cartridge not found: [cartridge-type] " + cartridgeType;
- log.error(msg);
- throw new InvalidCartridgeTypeException(msg);
- }
-
- private void removeCartridgeFromTopology(Cartridge cartridge) throws InvalidCartridgeTypeException {
- // sends the service removed event
- List<Cartridge> cartridgeList = new ArrayList<Cartridge>();
- cartridgeList.add(cartridge);
- TopologyBuilder.handleServiceRemoved(cartridgeList);
- }
-
- public boolean addServiceGroup(ServiceGroup servicegroup) throws InvalidServiceGroupException {
-
- if (servicegroup == null) {
- String msg = "Invalid ServiceGroup Definition: Definition is null.";
- log.error(msg);
- throw new IllegalArgumentException(msg);
-
- }
- CloudControllerContext.getInstance().addServiceGroup(servicegroup);
- CloudControllerContext.getInstance().persist();
- return true;
- }
-
- public boolean removeServiceGroup(String name) throws InvalidServiceGroupException {
- if (log.isDebugEnabled()) {
- log.debug("CloudControllerServiceImpl:removeServiceGroup: " + name);
- }
-
- ServiceGroup serviceGroup = null;
-
- serviceGroup = CloudControllerContext.getInstance().getServiceGroup(name);
-
- if (serviceGroup != null) {
- if (CloudControllerContext.getInstance().getServiceGroups().remove(serviceGroup)) {
- CloudControllerContext.getInstance().persist();
- if (log.isInfoEnabled()) {
- log.info("Successfully removed the cartridge group: [group-name] " + serviceGroup);
- }
- return true;
- }
- }
-
- String msg = "Cartridge group not found: [group-name] " + name;
- log.error(msg);
- throw new InvalidServiceGroupException(msg);
-
- }
-
- @Override
- public ServiceGroup getServiceGroup(String name) throws InvalidServiceGroupException {
-
- if (log.isDebugEnabled()) {
- log.debug("getServiceGroupDefinition:" + name);
- }
-
- ServiceGroup serviceGroup = CloudControllerContext.getInstance().getServiceGroup(name);
-
- if (serviceGroup == null) {
- String message = "Cartridge group not found: [group-name] " + name;
- if (log.isDebugEnabled()) {
- log.debug(message);
- }
- throw new InvalidServiceGroupException(message);
- }
-
- return serviceGroup;
- }
-
- public String[] getServiceGroupSubGroups(String name) throws InvalidServiceGroupException {
- ServiceGroup serviceGroup = this.getServiceGroup(name);
- if (serviceGroup == null) {
- throw new InvalidServiceGroupException("Invalid cartridge group: [group-name] " + serviceGroup);
- }
-
- return serviceGroup.getSubGroups();
- }
-
- /**
- *
- */
- public String[] getServiceGroupCartridges(String name) throws InvalidServiceGroupException {
- ServiceGroup serviceGroup = this.getServiceGroup(name);
- if (serviceGroup == null) {
- throw new InvalidServiceGroupException("Invalid cartridge group: [group-name] " + serviceGroup);
- }
- String[] cs = serviceGroup.getCartridges();
- return cs;
-
- }
-
- public Dependencies getServiceGroupDependencies(String name) throws InvalidServiceGroupException {
- ServiceGroup serviceGroup = this.getServiceGroup(name);
- if (serviceGroup == null) {
- throw new InvalidServiceGroupException("Invalid cartridge group: [group-name] " + serviceGroup);
- }
- return serviceGroup.getDependencies();
- }
-
- @Override
- public MemberContext[] startInstances(InstanceContext[] instanceContexts)
- throws CartridgeNotFoundException, InvalidIaasProviderException, CloudControllerException {
-
- handleNullObject(instanceContexts, "Instance start-up failed, member contexts is null");
-
- List<MemberContext> memberContextList = new ArrayList<MemberContext>();
- for (InstanceContext instanceContext : instanceContexts) {
- if (instanceContext != null) {
- MemberContext memberContext = startInstance(instanceContext);
- memberContextList.add(memberContext);
- }
- }
- MemberContext[] memberContextsArray = memberContextList.toArray(new MemberContext[memberContextList.size()]);
- return memberContextsArray;
- }
-
- public MemberContext startInstance(InstanceContext instanceContext) throws
- CartridgeNotFoundException, InvalidIaasProviderException, CloudControllerException {
-
- try {
- // Validate instance context
- handleNullObject(instanceContext, "Could not start instance, instance context is null");
- if (log.isDebugEnabled()) {
- log.debug("Starting up instance: " + instanceContext);
- }
-
- // Validate partition
- Partition partition = instanceContext.getPartition();
- handleNullObject(partition, "Could not start instance, partition is null");
-
- // Validate cluster
- String partitionId = partition.getId();
- String clusterId = instanceContext.getClusterId();
- ClusterContext clusterContext = CloudControllerContext.getInstance().getClusterContext(clusterId);
- handleNullObject(clusterContext, "Could not start instance, cluster context not found: [cluster-id] " + clusterId);
-
- // Validate cartridge
- String cartridgeType = clusterContext.getCartridgeType();
- Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType);
- if (cartridge == null) {
- String msg = "Could not startup instance, cartridge not found: [cartridge-type] " + cartridgeType;
- log.error(msg);
- throw new CartridgeNotFoundException(msg);
- }
-
- // Validate iaas provider
- IaasProvider iaasProvider = CloudControllerContext.getInstance().getIaasProviderOfPartition(cartridge.getType(), partitionId);
- if (iaasProvider == null) {
- String msg = String.format("Could not start instance, " +
- "IaaS provider not found in cartridge %s for partition %s, " +
- "partitions found: %s ", cartridgeType, partitionId,
- CloudControllerContext.getInstance().getPartitionToIaasProvider(cartridge.getType()).keySet().toString());
- log.error(msg);
- throw new InvalidIaasProviderException(msg);
- }
-
- // Generate member ID
- String memberId = generateMemberId(clusterId);
-
- // Create member context
- String applicationId = clusterContext.getApplicationId();
- MemberContext memberContext = createMemberContext(applicationId, cartridgeType, memberId,
- CloudControllerUtil.getLoadBalancingIPTypeEnumFromString(cartridge.getLoadBalancingIPType()), instanceContext);
-
- // Prepare payload
- StringBuilder payload = new StringBuilder(clusterContext.getPayload());
- addToPayload(payload, "MEMBER_ID", memberId);
- addToPayload(payload, "INSTANCE_ID", memberContext.getInstanceId());
- addToPayload(payload, "CLUSTER_INSTANCE_ID", memberContext.getClusterInstanceId());
- addToPayload(payload, "LB_CLUSTER_ID", memberContext.getLbClusterId());
- addToPayload(payload, "NETWORK_PARTITION_ID", memberContext.getNetworkPartitionId());
- addToPayload(payload, "PARTITION_ID", partitionId);
- addToPayload(payload, "INTERNAL", "false");
-
- if (memberContext.getProperties() != null) {
- org.apache.stratos.common.Properties properties = memberContext.getProperties();
- if (properties != null) {
- for (Property prop : properties.getProperties()) {
- addToPayload(payload, prop.getName(), String.valueOf(prop.getValue()));
- }
- }
- }
-
- NetworkPartition networkPartition =
- CloudControllerContext.getInstance().getNetworkPartition(memberContext.getNetworkPartitionId());
-
-
- if (networkPartition.getProperties() != null) {
- if (networkPartition.getProperties().getProperties() != null) {
- for (Property property : networkPartition.getProperties().getProperties()) {
- // check if a property is related to the payload. Currently
- // this is done by checking if the
- // property name starts with 'payload_parameter.' suffix. If
- // so the payload param name will
- // be taken as the substring from the index of '.' to the
- // end of the property name.
- if (property.getName().startsWith(PAYLOAD_PARAMETER)) {
- String propertyName = property.getName();
- String payloadParamName = propertyName.substring(propertyName.indexOf(".") + 1);
- if (payload.toString().contains(payloadParamName)) {
- replaceInPayload(payloadParamName, payload, payloadParamName, property.getValue());
- } else {
- addToPayload(payload, payloadParamName, property.getValue());
- }
- }
- }
- }
- }
-
- Iaas iaas = iaasProvider.getIaas();
- if (clusterContext.isVolumeRequired()) {
- addToPayload(payload, PERSISTENCE_MAPPING, getPersistencePayload(clusterContext, iaas).toString());
- }
-
- if (log.isDebugEnabled()) {
- log.debug("Payload: " + payload.toString());
- }
-
- if (clusterContext.isVolumeRequired()) {
-
- Volume[] volumes = clusterContext.getVolumes();
- if (volumes != null) {
- for (int i = 0; i < volumes.length; i++) {
-
- if (volumes[i].getId() == null) {
- // Create a new volume
- volumes[i] = createVolumeAndSetInClusterContext(volumes[i], iaasProvider);
- }
- }
- }
- clusterContext.setVolumes(volumes);
- }
-
- // Handle member created event
- TopologyBuilder.handleMemberCreatedEvent(memberContext);
-
- // Persist member context
- CloudControllerContext.getInstance().addMemberContext(memberContext);
- CloudControllerContext.getInstance().persist();
-
- // Start instance in a new thread
- if (log.isDebugEnabled()) {
- log.debug(String.format("Starting instance creator thread: [cluster] %s [cluster-instance] %s " +
- "[member] %s [application-id] %s", instanceContext.getClusterId(),
- instanceContext.getClusterInstanceId(), memberId, applicationId));
- }
- executorService.execute(new InstanceCreator(memberContext, iaasProvider, payload.toString().getBytes()));
-
- return memberContext;
- } catch (Exception e) {
- String msg = String.format("Could not start instance: [cluster] %s [cluster-instance] %s",
- instanceContext.getClusterId(), instanceContext.getClusterInstanceId());
- log.error(msg, e);
- throw new CloudControllerException(msg, e);
- }
- }
-
- private MemberContext createMemberContext(String applicationId, String cartridgeType, String memberId,
- LoadBalancingIPType loadBalancingIPType, InstanceContext instanceContext) {
- MemberContext memberContext = new MemberContext(
- applicationId, cartridgeType, instanceContext.getClusterId(), memberId);
-
- memberContext.setClusterInstanceId(instanceContext.getClusterInstanceId());
- memberContext.setNetworkPartitionId(instanceContext.getNetworkPartitionId());
- memberContext.setPartition(cloudControllerContext.getNetworkPartition(instanceContext.getNetworkPartitionId()).
- getPartition(instanceContext.getPartition().getId()));
- memberContext.setInitTime(instanceContext.getInitTime());
- memberContext.setProperties(instanceContext.getProperties());
- memberContext.setLoadBalancingIPType(loadBalancingIPType);
- memberContext.setInitTime(System.currentTimeMillis());
- memberContext.setObsoleteExpiryTime(instanceContext.getObsoleteExpiryTime());
-
- return memberContext;
- }
-
- private Volume createVolumeAndSetInClusterContext(Volume volume,
- IaasProvider iaasProvider) {
- // iaas cannot be null at this state #startInstance method
- Iaas iaas = iaasProvider.getIaas();
- int sizeGB = volume.getSize();
- String snapshotId = volume.getSnapshotId();
- if (StringUtils.isNotEmpty(volume.getVolumeId())) {
- // volumeID is specified, so not creating additional volumes
- if (log.isDebugEnabled()) {
- log.debug("Volume creation is skipping since a volume ID is specified. [Volume ID] " + volume.getVolumeId());
- }
- volume.setId(volume.getVolumeId());
- } else {
- String volumeId = iaas.createVolume(sizeGB, snapshotId);
- volume.setId(volumeId);
- }
-
- volume.setIaasType(iaasProvider.getType());
-
- return volume;
- }
-
-
- private StringBuilder getPersistencePayload(ClusterContext ctx, Iaas iaas) {
- StringBuilder persistencePayload = new StringBuilder();
- if (isPersistenceMappingAvailable(ctx)) {
- for (Volume volume : ctx.getVolumes()) {
- if (log.isDebugEnabled()) {
- log.debug("Adding persistence mapping " + volume.toString());
- }
- if (persistencePayload.length() != 0) {
- persistencePayload.append("|");
- }
-
- persistencePayload.append(iaas.getIaasDevice(volume.getDevice()));
- persistencePayload.append("|");
- persistencePayload.append(volume.getId());
- persistencePayload.append("|");
- persistencePayload.append(volume.getMappingPath());
- }
- }
- if (log.isDebugEnabled()) {
- log.debug("Persistence payload: " + persistencePayload.toString());
- }
- return persistencePayload;
- }
-
- private boolean isPersistenceMappingAvailable(ClusterContext ctx) {
- return ctx.getVolumes() != null && ctx.isVolumeRequired();
- }
-
- private void addToPayload(StringBuilder payload, String name, String value) {
- payload.append(",");
- payload.append(name + "=" + value);
- }
-
- private void replaceInPayload(String payloadParamName, StringBuilder payload, String name, String value) {
-
- payload.replace(payload.indexOf(payloadParamName), payload.indexOf(",", payload.indexOf(payloadParamName)),
- "," + name + "=" + value);
- }
-
- private String generateMemberId(String clusterId) {
- UUID memberId = UUID.randomUUID();
- return clusterId + memberId.toString();
- }
-
- public boolean terminateInstanceForcefully(String memberId) {
-
- log.info(String.format("Starting to forcefully terminate the member " + memberId));
- boolean memberTerminated = true;
- try {
- this.terminateInstance(memberId);
- } catch (InvalidMemberException e) {
- memberTerminated = false;
- } catch (CloudControllerException e) {
- memberTerminated = false;
- } catch (InvalidCartridgeTypeException e) {
- memberTerminated = false;
- }
-
- if (memberTerminated) {
- log.info(String.format("Member terminated [member-id] %s ", memberId));
- } else {
- log.warn(String.format("Stratos could not terminate the member [member-id] %s. This may due to a issue " +
- "in the underlying IaaS, Please terminate the member manually if it is available", memberId));
- MemberContext memberContext = CloudControllerContext.getInstance().getMemberContextOfMemberId(memberId);
- CloudControllerServiceUtil.executeMemberTerminationPostProcess(memberContext);
- }
- return true;
- }
-
- @Override
- public boolean terminateInstance(String memberId) throws InvalidMemberException,
- InvalidCartridgeTypeException, CloudControllerException {
-
- try {
- handleNullObject(memberId, "Could not terminate instance, member id is null.");
-
- MemberContext memberContext = CloudControllerContext.getInstance().getMemberContextOfMemberId(memberId);
- if (memberContext == null) {
- String msg = "Could not terminate instance, member context not found: [member-id] " + memberId;
- log.error(msg);
- throw new InvalidMemberException(msg);
- }
-
- if (StringUtils.isBlank(memberContext.getInstanceId())) {
- if (log.isErrorEnabled()) {
- log.error(String.format(
- "Could not terminate instance, instance id is blank: [member-id] %s " +
- ", removing member from topology...",
- memberContext.getMemberId()));
- }
- CloudControllerServiceUtil.executeMemberTerminationPostProcess(memberContext);
- }
-
- // check if status == active, if true, then this is a termination on member faulty
- TopologyManager.acquireWriteLock();
- Topology topology = TopologyManager.getTopology();
- org.apache.stratos.messaging.domain.topology.Service service = topology.getService(memberContext.getCartridgeType());
-
- if (service != null) {
- Cluster cluster = service.getCluster(memberContext.getClusterId());
- if (cluster != null) {
- Member member = cluster.getMember(memberId);
- if (member != null) {
-
- // check if ready to shutdown member is expired and send
- // member terminated if it is.
- if (isMemberExpired(member, memberContext.getObsoleteInitTime(), memberContext.getObsoleteExpiryTime())) {
- if (log.isInfoEnabled()) {
- log.info(String.format(
- "Member pending termination in ReadyToShutdown state exceeded expiry time. " +
- "This member has to be manually deleted: %s", memberContext.getMemberId()));
- }
-
- CloudControllerServiceUtil.executeMemberTerminationPostProcess(memberContext);
- return false;
- }
- }
- }
- }
-
- executorService.execute(new InstanceTerminator(memberContext));
- } catch (InvalidMemberException e) {
- String message = "Could not terminate instance: [member-id] " + memberId;
- log.error(message, e);
- throw e;
- } catch (Exception e) {
- String message = "Could not terminate instance: [member-id] " + memberId;
- log.error(message, e);
- throw new CloudControllerException(message, e);
- } finally {
- TopologyManager.releaseWriteLock();
- }
- return true;
- }
-
- /**
- * Check if a member has been in the ReadyToShutdown status for a specified expiry time
- *
- * @param member
- * @param initTime
- * @param expiryTime
- * @return
- */
- private boolean isMemberExpired(Member member, long initTime, long expiryTime) {
- if (member.getStatus() == MemberStatus.ReadyToShutDown) {
- if (initTime == 0) {
- // obsolete init time hasn't been set, i.e. not a member detected faulty.
- // this is a graceful shutdown
- return false;
- }
-
- // member detected faulty, calculate ready to shutdown waiting period
- long timeInReadyToShutdownStatus = System.currentTimeMillis() - initTime;
- return timeInReadyToShutdownStatus >= expiryTime;
- }
-
- return false;
- }
-
- @Override
- public boolean terminateInstances(String clusterId) throws InvalidClusterException {
-
- log.info("Starting to terminate all instances of cluster : "
- + clusterId);
-
- handleNullObject(clusterId, "Instance termination failed. Cluster id is null.");
-
- List<MemberContext> memberContexts = CloudControllerContext.getInstance().getMemberContextsOfClusterId(clusterId);
- if (memberContexts == null) {
- String msg = "Instance termination failed. No members found for cluster id: " + clusterId;
- log.warn(msg);
- return false;
- }
-
- for (MemberContext memberContext : memberContexts) {
- executorService.execute(new InstanceTerminator(memberContext));
- }
- return true;
- }
-
- @Override
- public boolean registerService(Registrant registrant)
- throws CartridgeNotFoundException {
-
- String cartridgeType = registrant.getCartridgeType();
- handleNullObject(cartridgeType, "Service registration failed, cartridge Type is null.");
-
- String clusterId = registrant.getClusterId();
- handleNullObject(clusterId, "Service registration failed, cluster id is null.");
-
- String payload = registrant.getPayload();
- handleNullObject(payload, "Service registration failed, payload is null.");
-
- String hostName = registrant.getHostName();
- handleNullObject(hostName, "Service registration failed, hostname is null.");
-
- Cartridge cartridge = null;
- if ((cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType)) == null) {
- String msg = "Registration of cluster: " + clusterId +
- " failed, cartridge not found: [cartridge-type] " + cartridgeType;
- log.error(msg);
- throw new CartridgeNotFoundException(msg);
- }
-
- CloudControllerContext.getInstance().persist();
-
- log.info("Successfully registered service: " + registrant);
- return true;
- }
-
- @Override
- public String[] getCartridges() {
- // get the list of cartridges registered
- Collection<Cartridge> cartridges = CloudControllerContext.getInstance().getCartridges();
-
- if (cartridges == null) {
- log.info("No registered Cartridge found.");
- return new String[0];
- }
-
- String[] cartridgeTypes = new String[cartridges.size()];
- int i = 0;
-
- if (log.isDebugEnabled()) {
- log.debug("Registered Cartridges : \n");
- }
- for (Cartridge cartridge : cartridges) {
- if (log.isDebugEnabled()) {
- log.debug(cartridge);
- }
- cartridgeTypes[i] = cartridge.getType();
- i++;
- }
-
- return cartridgeTypes;
- }
-
- @Override
- public Cartridge getCartridge(String cartridgeType) throws CartridgeNotFoundException {
- Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType);
- if (cartridge != null) {
- return cartridge;
- }
-
- String msg = "Could not find cartridge: [cartridge-type] " + cartridgeType;
- throw new CartridgeNotFoundException(msg);
- }
-
- @Override
- public boolean unregisterService(String clusterId) throws UnregisteredClusterException {
- final String clusterId_ = clusterId;
-
- ClusterContext ctxt = CloudControllerContext.getInstance().getClusterContext(clusterId_);
- handleNullObject(ctxt, "Service unregistration failed. Invalid cluster id: " + clusterId);
-
- final String cartridgeType = ctxt.getCartridgeType();
- Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType);
-
- if (cartridge == null) {
- String msg =
- String.format("Service unregistration failed. No matching cartridge found: [cartridge-type] %s " +
- "[application-id] %s", cartridgeType, ctxt.getApplicationId());
- log.error(msg);
- throw new UnregisteredClusterException(msg);
- }
-
- Runnable terminateInTimeout = new Runnable() {
- @Override
- public void run() {
- ClusterContext ctxt = CloudControllerContext.getInstance().getClusterContext(clusterId_);
- if (ctxt == null) {
- String msg = String.format("Service unregistration failed. Cluster not found: [cluster-id] %s " +
- "[application-id] %s", clusterId_, ctxt.getApplicationId());
- log.error(msg);
- return;
- }
- Collection<Member> members = TopologyManager.getTopology().
- getService(ctxt.getCartridgeType()).getCluster(clusterId_).getMembers();
- //finding the responding members from the existing members in the topology.
- int sizeOfRespondingMembers = 0;
- for (Member member : members) {
- if (member.getStatus().getCode() >= MemberStatus.Active.getCode()) {
- sizeOfRespondingMembers++;
- }
- }
-
- long endTime = System.currentTimeMillis() + ctxt.getTimeoutInMillis() * sizeOfRespondingMembers;
- while (System.currentTimeMillis() < endTime) {
- CloudControllerUtil.sleep(1000);
-
- }
-
- // if there are still alive members
- if (members.size() > 0) {
- //forcefully terminate them
- for (Member member : members) {
-
- try {
- terminateInstance(member.getMemberId());
- } catch (Exception e) {
- // we are not gonna stop the execution due to errors.
- log.warn((String.format("Instance termination failed of member [member-id] %s " +
- "[application-id] %s", member.getMemberId(), ctxt.getApplicationId())), e);
-
- }
- }
- }
- }
- };
- Runnable unregister = new Runnable() {
- public void run() {
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireClusterContextWriteLock();
- ClusterContext ctxt = CloudControllerContext.getInstance().getClusterContext(clusterId_);
- if (ctxt == null) {
- String msg = String.format("Service unregistration failed. Cluster not found: [cluster-id] %s " +
- "[application-id] %s ", clusterId_, ctxt.getApplicationId());
- log.error(msg);
- return;
- }
- Collection<Member> members = TopologyManager.getTopology().
- getService(ctxt.getCartridgeType()).getCluster(clusterId_).getMembers();
-
- while (members.size() > 0) {
- //waiting until all the members got removed from the Topology/ timed out
- CloudControllerUtil.sleep(1000);
- }
-
- log.info(String.format("Unregistration of service cluster: [cluster-id] %s [application-id]",
- clusterId_, ctxt.getApplicationId()));
- deleteVolumes(ctxt);
- onClusterRemoval(clusterId_);
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- }
-
- private void deleteVolumes(ClusterContext ctxt) {
- if (ctxt.isVolumeRequired()) {
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireCartridgesWriteLock();
-
- Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(ctxt.getCartridgeType());
- if (cartridge != null && CloudControllerContext.getInstance().getIaasProviders(cartridge.getType()) != null && ctxt.getVolumes() != null) {
- for (Volume volume : ctxt.getVolumes()) {
- if (volume.getId() != null) {
- String iaasType = volume.getIaasType();
- Iaas iaas = CloudControllerContext.getInstance().getIaasProvider(cartridge.getType(), iaasType).getIaas();
- if (iaas != null) {
- try {
- // delete the volumes if remove on unsubscription is true.
- if (volume.isRemoveOntermination()) {
- iaas.deleteVolume(volume.getId());
- volume.setId(null);
- }
- } catch (Exception ignore) {
- if (log.isErrorEnabled()) {
- log.error((String.format("Error while deleting volume [id] %s " +
- "[application-id]", volume.getId(), ctxt.getApplicationId())),
- ignore);
- }
- }
- }
- }
- }
- CloudControllerContext.getInstance().updateCartridge(cartridge);
- }
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- }
- }
- };
- new Thread(terminateInTimeout).start();
- new Thread(unregister).start();
- return true;
- }
-
- /**
- * FIXME: A validate method shouldn't persist data
- */
- @Override
- public boolean validateDeploymentPolicyNetworkPartition(String cartridgeType, String networkPartitionId)
- throws InvalidPartitionException, InvalidCartridgeTypeException {
-
- NetworkPartition networkPartition = CloudControllerContext.getInstance().getNetworkPartition(networkPartitionId);
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireCartridgesWriteLock();
-
- List<String> validatedPartitions = CloudControllerContext.getInstance().getPartitionIds(cartridgeType);
- if (validatedPartitions != null) {
- // cache hit for this cartridge
- // get list of partitions
- if (log.isDebugEnabled()) {
- log.debug("Partition validation cache hit for cartridge type: " + cartridgeType);
- }
- }
-
- Map<String, IaasProvider> partitionToIaasProviders = new ConcurrentHashMap<String, IaasProvider>();
-
- if (log.isDebugEnabled()) {
- log.debug("Deployment policy validation started for cartridge type: " + cartridgeType);
- }
-
- Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType);
- if (cartridge == null) {
- String msg = "Cartridge not found: " + cartridgeType;
- log.error(msg);
- throw new InvalidCartridgeTypeException(msg);
- }
-
- Map<String, Future<IaasProvider>> jobList = new HashMap<String, Future<IaasProvider>>();
- for (Partition partition : networkPartition.getPartitions()) {
- if (validatedPartitions != null && validatedPartitions.contains(partition.getId())) {
- // partition cache hit
- String provider = partition.getProvider();
- IaasProvider iaasProvider = CloudControllerContext.getInstance()
- .getIaasProvider(cartridge.getType(), provider);
- partitionToIaasProviders.put(partition.getId(), iaasProvider);
- continue;
- }
-
- Callable<IaasProvider> worker = new PartitionValidatorCallable(partition, cartridge);
- Future<IaasProvider> job = CloudControllerContext.getInstance()
- .getExecutorService().submit(worker);
- jobList.put(partition.getId(), job);
- }
-
- // Retrieve the results of the concurrently performed sanity checks.
- for (Entry<String, Future<IaasProvider>> entry : jobList.entrySet()) {
- if (entry == null) {
- continue;
- }
- String partitionId = entry.getKey();
- Future<IaasProvider> job = entry.getValue();
- try {
- // add to a temporary Map
- IaasProvider iaasProvider = job.get();
- if (iaasProvider != null) {
- partitionToIaasProviders.put(partitionId, iaasProvider);
- }
-
- // add to cache
- CloudControllerContext.getInstance().addToCartridgeTypeToPartitionIdMap(cartridgeType, partitionId);
-
- if (log.isDebugEnabled()) {
- log.debug("Partition " + partitionId + " added to the cache against cartridge: " +
- "[cartridge-type] " + cartridgeType);
- }
- } catch (Exception e) {
- String message = "Could not cache partitions against the cartridge: [cartridge-type] " + cartridgeType;
- log.error(message, e);
- throw new InvalidPartitionException(message, e);
- }
- }
-
- // if and only if the deployment policy valid
- CloudControllerContext.getInstance().addIaasProviders(cartridgeType, partitionToIaasProviders);
- CloudControllerContext.getInstance().updateCartridge(cartridge);
-
- // persist data
- CloudControllerContext.getInstance().persist();
-
- log.info("All partitions [" + CloudControllerUtil.getPartitionIds(networkPartition.getPartitions()) + "]" +
- " were validated successfully, against the cartridge: " + cartridgeType);
-
- return true;
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- }
-
- private void onClusterRemoval(final String clusterId) {
- ClusterContext ctxt = CloudControllerContext.getInstance().getClusterContext(clusterId);
- TopologyBuilder.handleClusterRemoved(ctxt);
- CloudControllerContext.getInstance().removeClusterContext(clusterId);
- CloudControllerContext.getInstance().removeMemberContextsOfCluster(clusterId);
- CloudControllerContext.getInstance().persist();
- }
-
- @Override
- public boolean validatePartition(Partition partition) throws InvalidPartitionException {
- handleNullObject(partition, "Partition validation failed. Partition is null.");
-
- String provider = partition.getProvider();
- String partitionId = partition.getId();
-
- handleNullObject(provider, "Partition [" + partitionId + "] validation failed. Partition provider is null.");
- IaasProvider iaasProvider = CloudControllerConfig.getInstance().getIaasProvider(provider);
-
- return CloudControllerServiceUtil.validatePartition(partition, iaasProvider);
- }
-
- public ClusterContext getClusterContext(String clusterId) {
- return CloudControllerContext.getInstance().getClusterContext(clusterId);
- }
-
- @Override
- public boolean updateClusterStatus(String serviceName, String clusterId, String instanceId, ClusterStatus status) {
- //TODO
- return true;
- }
-
- private void handleNullObject(Object obj, String errorMsg) {
- if (obj == null) {
- log.error(errorMsg);
- throw new CloudControllerException(errorMsg);
- }
- }
-
- @Override
- public boolean createApplicationClusters(String appId, ApplicationClusterContext[] appClustersContexts) throws
- ApplicationClusterRegistrationException {
- if (appClustersContexts == null || appClustersContexts.length == 0) {
- String errorMsg = "No application cluster information found, unable to create clusters: " +
- "[application-id] " + appId;
- log.error(errorMsg);
- throw new ApplicationClusterRegistrationException(errorMsg);
- }
-
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireClusterContextWriteLock();
-
- // Create a Cluster Context obj. for each of the Clusters in the Application
- List<Cluster> clusters = new ArrayList<Cluster>();
- Map<String, List<String>> accessUrls = new HashMap<String, List<String>>();
-
- for (ApplicationClusterContext appClusterCtxt : appClustersContexts) {
- String clusterId = appClusterCtxt.getClusterId();
- if (appClusterCtxt.isLbCluster()) {
- String[] dependencyClusterIDs = appClusterCtxt.getDependencyClusterIds();
- if (dependencyClusterIDs != null) {
- for (int i = 0; i < dependencyClusterIDs.length; i++) {
-
- List<String> accessUrlPerCluster = new ArrayList();
- Collection<ClusterPortMapping> clusterPortMappings =
- CloudControllerContext.getInstance().getClusterPortMappings(appId, clusterId);
-
- for (ClusterPortMapping clusterPortMapping : clusterPortMappings) {
- try {
- if (clusterPortMapping.isKubernetes()) {
- URL accessUrl = new URL(clusterPortMapping.getProtocol(), appClusterCtxt.getHostName(),
- clusterPortMapping.getKubernetesServicePort(), "");
- accessUrlPerCluster.add(accessUrl.toString());
- } else {
- URL accessUrl = new URL(clusterPortMapping.getProtocol(), appClusterCtxt.getHostName(),
- clusterPortMapping.getProxyPort(), "");
- accessUrlPerCluster.add(accessUrl.toString());
- }
- } catch (MalformedURLException e) {
- String message = "Could not generate access URL";
- log.error(message, e);
- throw new ApplicationClusterRegistrationException(message, e);
- }
- }
- accessUrls.put(dependencyClusterIDs[i], accessUrlPerCluster);
- }
- }
- }
- }
-
- for (ApplicationClusterContext appClusterCtxt : appClustersContexts) {
- ClusterContext clusterContext = new ClusterContext(
- appId, appClusterCtxt.getCartridgeType(), appClusterCtxt.getClusterId(),
- appClusterCtxt.getTextPayload(), appClusterCtxt.getHostName(),
- appClusterCtxt.isLbCluster(), appClusterCtxt.getProperties());
-
- if (appClusterCtxt.isVolumeRequired()) {
- clusterContext.setVolumeRequired(true);
- clusterContext.setVolumes(appClusterCtxt.getVolumes());
- }
- CloudControllerContext.getInstance().addClusterContext(clusterContext);
-
- // Create cluster object
- Cluster cluster = new Cluster(appClusterCtxt.getCartridgeType(), appClusterCtxt.getClusterId(),
- appClusterCtxt.getDeploymentPolicyName(), appClusterCtxt.getAutoscalePolicyName(), appId);
- cluster.setLbCluster(false);
- cluster.setTenantRange(appClusterCtxt.getTenantRange());
- cluster.setHostNames(Arrays.asList(appClusterCtxt.getHostName()));
- cluster.setAccessUrls(accessUrls.get(appClusterCtxt.getClusterId()));
-
- if (appClusterCtxt.getProperties() != null) {
- Properties properties = CloudControllerUtil.toJavaUtilProperties(appClusterCtxt.getProperties());
- cluster.setProperties(properties);
- }
-
- clusters.add(cluster);
- }
- TopologyBuilder.handleApplicationClustersCreated(appId, clusters);
- CloudControllerContext.getInstance().persist();
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- return true;
- }
-
- public boolean createClusterInstance(String serviceType, String clusterId,
- String alias, String instanceId, String partitionId,
- String networkPartitionId) throws ClusterInstanceCreationException {
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireClusterContextWriteLock();
- TopologyBuilder.handleClusterInstanceCreated(serviceType, clusterId, alias,
- instanceId, partitionId, networkPartitionId);
-
- CloudControllerContext.getInstance().persist();
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- return true;
- }
-
- @Override
- public KubernetesCluster[] getKubernetesClusters() {
- return CloudControllerContext.getInstance().getKubernetesClusters();
- }
-
- @Override
- public KubernetesCluster getKubernetesCluster(String kubernetesClusterId) throws
- NonExistingKubernetesClusterException {
- return CloudControllerContext.getInstance().getKubernetesCluster(kubernetesClusterId);
- }
-
- @Override
- public KubernetesMaster getMasterForKubernetesCluster(String kubernetesClusterId) throws
- NonExistingKubernetesClusterException {
- return CloudControllerContext.getInstance().getKubernetesMasterInGroup(kubernetesClusterId);
- }
-
- @Override
- public KubernetesHost[] getHostsForKubernetesCluster(String kubernetesClusterId) throws
- NonExistingKubernetesClusterException {
- return CloudControllerContext.getInstance().getKubernetesHostsInGroup(kubernetesClusterId);
- }
-
-
- @Override
- public boolean addKubernetesCluster(KubernetesCluster kubernetesCluster) throws InvalidKubernetesClusterException,
- KubernetesClusterAlreadyExistsException {
- if (kubernetesCluster == null) {
- throw new InvalidKubernetesClusterException("Kubernetes cluster cannot be null");
- }
-
- try {
- if (CloudControllerContext.getInstance().getKubernetesCluster(kubernetesCluster.getClusterId()) != null) {
- throw new KubernetesClusterAlreadyExistsException("Kubernetes cluster already exists");
- }
- } catch (NonExistingKubernetesClusterException ignore) {
- }
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireKubernetesClusterWriteLock();
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Adding kubernetes cluster: [kubernetes-cluster-id] %s",
- kubernetesCluster.getClusterId()));
- }
- CloudControllerUtil.validateKubernetesCluster(kubernetesCluster);
-
- // Add to information model
- CloudControllerContext.getInstance().addKubernetesCluster(kubernetesCluster);
- CloudControllerContext.getInstance().persist();
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Kubernetes cluster added successfully: [kubernetes-cluster-id] %s",
- kubernetesCluster.getClusterId()));
- }
- return true;
- } catch (Exception e) {
- throw new InvalidKubernetesClusterException(e.getMessage(), e);
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- }
-
- @Override
- public boolean updateKubernetesCluster(KubernetesCluster kubernetesCluster) throws InvalidKubernetesClusterException {
- if (kubernetesCluster == null) {
- throw new InvalidKubernetesClusterException("Kubernetes cluster cannot be null");
- }
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireKubernetesClusterWriteLock();
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Updating kubernetes cluster: [kubernetes-cluster-id] %s",
- kubernetesCluster.getClusterId()));
- }
- CloudControllerUtil.validateKubernetesCluster(kubernetesCluster);
-
- // Updating the information model
- CloudControllerContext.getInstance().updateKubernetesCluster(kubernetesCluster);
- CloudControllerContext.getInstance().persist();
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Kubernetes cluster updated successfully: [kubernetes-cluster-id] %s",
- kubernetesCluster.getClusterId()));
- }
- return true;
- } catch (Exception e) {
- throw new InvalidKubernetesClusterException(e.getMessage(), e);
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- }
-
- @Override
- public boolean addKubernetesHost(String kubernetesClusterId, KubernetesHost kubernetesHost) throws
- InvalidKubernetesHostException, NonExistingKubernetesClusterException {
- if (kubernetesHost == null) {
- throw new InvalidKubernetesHostException("Kubernetes host cannot be null");
- }
- if (StringUtils.isEmpty(kubernetesClusterId)) {
- throw new NonExistingKubernetesClusterException("Kubernetes cluster id cannot be null");
- }
-
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireKubernetesClusterWriteLock();
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Adding kubernetes host for kubernetes cluster: [kubernetes-cluster-id] %s " +
- "[hostname] %s", kubernetesClusterId, kubernetesHost.getHostname()));
- }
- CloudControllerUtil.validateKubernetesHost(kubernetesHost);
-
- KubernetesCluster kubernetesCluster = getKubernetesCluster(kubernetesClusterId);
- ArrayList<KubernetesHost> kubernetesHostArrayList;
-
- if (kubernetesCluster.getKubernetesHosts() == null) {
- kubernetesHostArrayList = new ArrayList<KubernetesHost>();
- } else {
- if (CloudControllerContext.getInstance().kubernetesHostExists(kubernetesHost.getHostId())) {
- throw new InvalidKubernetesHostException("Kubernetes host already exists: [hostname] " +
- kubernetesHost.getHostId());
- }
- kubernetesHostArrayList = new
- ArrayList<KubernetesHost>(Arrays.asList(kubernetesCluster.getKubernetesHosts()));
- }
- kubernetesHostArrayList.add(kubernetesHost);
-
- // Update information model
- kubernetesCluster.setKubernetesHosts(kubernetesHostArrayList.toArray(new KubernetesHost[kubernetesHostArrayList.size()]));
- CloudControllerContext.getInstance().updateKubernetesCluster(kubernetesCluster);
- CloudControllerContext.getInstance().persist();
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Kubernetes host added successfully: [id] %s", kubernetesCluster.getClusterId()));
- }
-
- return true;
- } catch (Exception e) {
- throw new InvalidKubernetesHostException(e.getMessage(), e);
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- }
-
- @Override
- public boolean removeKubernetesCluster(String kubernetesClusterId) throws NonExistingKubernetesClusterException {
- if (StringUtils.isEmpty(kubernetesClusterId)) {
- throw new NonExistingKubernetesClusterException("Kubernetes cluster id cannot be empty");
- }
-
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireKubernetesClusterWriteLock();
-
- if (log.isInfoEnabled()) {
- log.info("Removing Kubernetes cluster: " + kubernetesClusterId);
- }
- // Remove entry from information model
- CloudControllerContext.getInstance().removeKubernetesCluster(kubernetesClusterId);
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Kubernetes cluster removed successfully: [id] %s", kubernetesClusterId));
- }
-
- CloudControllerContext.getInstance().persist();
-
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- return true;
- }
-
- @Override
- public boolean removeKubernetesHost(String kubernetesHostId) throws NonExistingKubernetesHostException {
- if (kubernetesHostId == null) {
- throw new NonExistingKubernetesHostException("Kubernetes host id cannot be null");
- }
-
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireKubernetesClusterWriteLock();
-
- if (log.isInfoEnabled()) {
- log.info("Removing Kubernetes Host: " + kubernetesHostId);
- }
- try {
- KubernetesCluster kubernetesClusterStored = CloudControllerContext.getInstance().getKubernetesClusterContainingHost(kubernetesHostId);
-
- // Kubernetes master cannot be removed
- if (kubernetesClusterStored.getKubernetesMaster().getHostId().equals(kubernetesHostId)) {
- throw new NonExistingKubernetesHostException("Kubernetes master is not allowed to be removed [id] " + kubernetesHostId);
- }
-
- List<KubernetesHost> kubernetesHostList = new ArrayList<KubernetesHost>();
- for (KubernetesHost kubernetesHost : kubernetesClusterStored.getKubernetesHosts()) {
- if (!kubernetesHost.getHostId().equals(kubernetesHostId)) {
- kubernetesHostList.add(kubernetesHost);
- }
- }
- // member count will be equal only when host object was not found
- if (kubernetesHostList.size() == kubernetesClusterStored.getKubernetesHosts().length) {
- throw new NonExistingKubernetesHostException("Kubernetes host not found for [id] " + kubernetesHostId);
- }
- KubernetesHost[] kubernetesHostsArray = new KubernetesHost[kubernetesHostList.size()];
- kubernetesHostList.toArray(kubernetesHostsArray);
-
- // Update information model
- kubernetesClusterStored.setKubernetesHosts(kubernetesHostsArray);
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Kubernetes host removed successfully: [id] %s", kubernetesHostId));
- }
-
- CloudControllerContext.getInstance().persist();
-
- return true;
- } catch (Exception e) {
- throw new NonExistingKubernetesHostException(e.getMessage(), e);
- }
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- }
-
- @Override
- public boolean updateKubernetesMaster(KubernetesMaster kubernetesMaster)
- throws InvalidKubernetesMasterException, NonExistingKubernetesMasterException {
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireKubernetesClusterWriteLock();
- CloudControllerUtil.validateKubernetesMaster(kubernetesMaster);
- if (log.isInfoEnabled()) {
- log.info("Updating Kubernetes master: " + kubernetesMaster);
- }
- try {
- KubernetesCluster kubernetesClusterStored = CloudControllerContext.getInstance().getKubernetesClusterContainingHost(kubernetesMaster.getHostId());
-
- // Update information model
- kubernetesClusterStored.setKubernetesMaster(kubernetesMaster);
-
- CloudControllerContext.getInstance().persist();
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Kubernetes master updated successfully: [id] %s", kubernetesMaster.getHostId()));
- }
-
- return true;
- } catch (Exception e) {
- throw new InvalidKubernetesMasterException(e.getMessage(), e);
- }
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- }
-
- @Override
- public boolean updateKubernetesHost(KubernetesHost kubernetesHost) throws
- InvalidKubernetesHostException, NonExistingKubernetesHostException {
-
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireKubernetesClusterWriteLock();
- CloudControllerUtil.validateKubernetesHost(kubernetesHost);
- if (log.isInfoEnabled()) {
- log.info("Updating Kubernetes Host: " + kubernetesHost);
- }
-
- try {
- KubernetesCluster kubernetesClusterStored = CloudControllerContext.getInstance().getKubernetesClusterContainingHost(kubernetesHost.getHostId());
- KubernetesHost[] kubernetesHosts = kubernetesClusterStored.getKubernetesHosts();
- for (int i = 0; i < kubernetesHosts.length; i++) {
- if (kubernetesHosts[i].getHostId().equals(kubernetesHost.getHostId())) {
- // Update the information model
- kubernetesHosts[i] = kubernetesHost;
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Kubernetes host updated successfully: [id] %s", kubernetesHost.getHostId()));
- }
-
- CloudControllerContext.getInstance().updateKubernetesCluster(kubernetesClusterStored);
- CloudControllerContext.getInstance().persist();
- return true;
- }
- }
- } catch (Exception e) {
- throw new InvalidKubernetesHostException(e.getMessage(), e);
- }
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- throw new NonExistingKubernetesHostException("Kubernetes host not found [id] " + kubernetesHost.getHostId());
- }
-
- @Override
- public boolean addNetworkPartition(NetworkPartition networkPartition) throws
- NetworkPartitionAlreadyExistsException,
- InvalidNetworkPartitionException {
-
- handleNullObject(networkPartition, "Network Partition is null");
- handleNullObject(networkPartition.getId(), "Network Partition ID is null");
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Adding network partition: [network-partition-id] %s", networkPartition.getId()));
- }
-
- String networkPartitionID = networkPartition.getId();
- if (cloudControllerContext.getNetworkPartition(networkPartitionID) != null) {
- String message = "Network partition already exists: [network-partition-id] " + networkPartitionID;
- log.error(message);
- throw new NetworkPartitionAlreadyExistsException(message);
- }
-
- if (networkPartition.getPartitions() != null && networkPartition.getPartitions().length != 0) {
- for (Partition partition : networkPartition.getPartitions()) {
- if (partition != null) {
- if (log.isInfoEnabled()) {
- log.info(String.format("Validating partition: [network-partition-id] %s [partition-id] %s",
- networkPartition.getId(), partition.getId()));
- }
- // Overwrites partition provider with network partition provider
- partition.setProvider(networkPartition.getProvider());
- try {
- validatePartition(partition);
- } catch (InvalidPartitionException e) {
- //Following message is shown to the end user in all the the API clients(GUI/CLI/Rest API)
- throw new InvalidNetworkPartitionException(String.format("Network partition " +
- " %s, is invalid since the partition %s is invalid",
- networkPartition.getId(), partition.getId()), e);
- }
- if (log.isInfoEnabled()) {
- log.info(String.format("Partition validated successfully: [network-partition-id] %s " +
- "[partition-id] %s", networkPartition.getId(), partition.getId()));
- }
- }
- }
- } else {
- //Following message is shown to the end user in all the the API clients(GUI/CLI/Rest API)
- throw new InvalidNetworkPartitionException(String.format("Network partition: " +
- "%s doesn't not have any partitions ", networkPartition.getId()));
- }
-
- // adding network partition to CC-Context
- CloudControllerContext.getInstance().addNetworkPartition(networkPartition);
- // persisting CC-Context
- CloudControllerContext.getInstance().persist();
- if (log.isInfoEnabled()) {
- log.info(String.format("Network partition added successfully: [network-partition-id] %s",
- networkPartition.getId()));
- }
- return true;
- }
-
- @Override
- public boolean removeNetworkPartition(String networkPartitionId) throws NetworkPartitionNotExistsException {
-
- try {
- if (log.isInfoEnabled()) {
- log.info(String.format("Removing network partition: [network-partition-id] %s", networkPartitionId));
- }
- handleNullObject(networkPartitionId, "Network Partition ID is null");
-
- if (cloudControllerContext.getNetworkPartition(networkPartitionId) == null) {
- String message = "Network partition not found: [network-partition-id] " + networkPartitionId;
- log.error(message);
- throw new NetworkPartitionNotExistsException(message);
- }
- // removing from CC-Context
- CloudControllerContext.getInstance().removeNetworkPartition(networkPartitionId);
- // persisting CC-Context
- CloudControllerContext.getInstance().persist();
- if (log.isInfoEnabled()) {
- log.info(String.format("Network partition removed successfully: [network-partition-id] %s",
- networkPartitionId));
- }
- } catch (Exception e) {
- String message = e.getMessage();
- log.error(message);
- throw new CloudControllerException(message, e);
- }
- return true;
- }
-
- @Override
- public boolean updateNetworkPartition(NetworkPartition networkPartition) throws NetworkPartitionNotExistsException {
- try {
- handleNullObject(networkPartition, "Network Partition is null");
- handleNullObject(networkPartition.getId(), "Network Partition ID is null");
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Updating network partition: [network-partition-id] %s", networkPartition.getId()));
- }
-
- String networkPartitionID = networkPartition.getId();
- if (cloudControllerContext.getNetworkPartition(networkPartitionID) == null) {
- String message = "Network partition not found: [network-partition-id] " + networkPartitionID;
- log.error(message);
- throw new NetworkPartitionNotExistsException(message);
- }
-
- if (networkPartition.getPartitions() != null) {
- for (Partition partition : networkPartition.getPartitions()) {
- if (partition != null) {
- if (log.isInfoEnabled()) {
- log.info(String.format("Validating partition: [network-partition-id] %s [partition-id] %s",
- networkPartition.getId(), partition.getId()));
- }
- // Overwrites partition provider with network partition provider
- partition.setProvider(networkPartition.getProvider());
- validatePartition(partition);
- if (log.isInfoEnabled()) {
- log.info(String.format("Partition validated successfully: [network-partition-id] %s " +
- "[partition-id] %s", networkPartition.getId(), partition.getId()));
- }
- }
- }
- }
-
- // overriding network partition to CC-Context
- CloudControllerContext.getInstance().addNetworkPartition(networkPartition);
- // persisting CC-Context
- CloudControllerContext.getInstance().persist();
- if (log.isInfoEnabled()) {
- log.info(String.format("Network partition updated successfully: [network-partition-id] %s",
- networkPartition.getId()));
- }
- return true;
- } catch (Exception e) {
- String message = e.getMessage();
- log.error(message);
- throw new CloudControllerException(message, e);
- }
- }
-
- @Override
- public NetworkPartition[] getNetworkPartitions() {
- try {
- Collection<NetworkPartition> networkPartitionList = cloudControllerContext.getNetworkPartitions();
- return networkPartitionList.toArray(new NetworkPartition[networkPartitionList.size()]);
- } catch (Exception e) {
- String message = "Could not get network partitions";
- log.error(message);
- throw new CloudControllerException(message, e);
- }
- }
-
- @Override
- public NetworkPartition getNetworkPartition(String networkPartitionId) {
- try {
- return CloudControllerContext.getInstance().getNetworkPartition(networkPartitionId);
- } catch (Exception e) {
- String message = String.format("Could not get network partition: [network-partition-id] %s",
- networkPartitionId);
- log.error(message);
- throw new CloudControllerException(message, e);
- }
- }
-
- @Override
- public String[] getIaasProviders() {
-
- try {
- Collection<IaasProvider> iaasProviders = CloudControllerConfig.getInstance().getIaasProviders();
- List<String> iaases = new ArrayList<String>();
-
- for (IaasProvider iaas : iaasProviders) {
- iaases.add(iaas.getType());
- }
-
- return iaases.toArray(new String[iaases.size()]);
- } catch (Exception e) {
- String message = String.format("Could not get Iaas Providers");
- log.error(message);
- throw new CloudControllerException(message, e);
- }
-
- }
+ private static final Log log = LogFactory.getLog(CloudControllerServiceImpl.class);
+
+ private static final String PERSISTENCE_MAPPING = "PERSISTENCE_MAPPING";
+ public static final String PAYLOAD_PARAMETER = "payload_parameter.";
+
+ private CloudControllerContext cloudControllerContext = CloudControllerContext.getInstance();
+ private ExecutorService executorService;
+
+ public CloudControllerServiceImpl() {
+ executorService = StratosThreadPool.getExecutorService("cloud.controller.instance.manager.thread.pool", 50);
+
+ }
+
+ public boolean addCartridge(Cartridge cartridgeConfig)
+ throws InvalidCartridgeDefinitionException, InvalidIaasProviderException, CartridgeAlreadyExistsException {
+
+ handleNullObject(cartridgeConfig, "Cartridge definition is null");
+
+ if (log.isInfoEnabled()) {
+ log.info("Adding cartridge: [cartridge-type] " + cartridgeConfig.getType());
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Cartridge definition: " + cartridgeConfig.toString());
+ }
+
+ try {
+ CloudControllerUtil.extractIaaSProvidersFromCartridge(cartridgeConfig);
+ } catch (Exception e) {
+ String message = "Invalid cartridge definition: [cartridge-type] " + cartridgeConfig.getType();
+ log.error(message, e);
+ throw new InvalidCartridgeDefinitionException(message, e);
+ }
+
+ String cartridgeType = cartridgeConfig.getType();
+ if (cloudControllerContext.getCartridge(cartridgeType) != null) {
+ String message = "Cartridge already exists: [cartridge-type] " + cartridgeType;
+ log.error(message);
+ throw new CartridgeAlreadyExistsException(message);
+ }
+
+ // Add cartridge to the cloud controller context and persist
+ CloudControllerContext.getInstance().addCartridge(cartridgeConfig);
+ CloudControllerContext.getInstance().persist();
+
+ List<Cartridge> cartridgeList = new ArrayList<Cartridge>();
+ cartridgeList.add(cartridgeConfig);
+
+ TopologyBuilder.handleServiceCreated(cartridgeList);
+
+ if (log.isInfoEnabled()) {
+ log.info("Successfully added cartridge: [cartridge-type] " + cartridgeType);
+ }
+ return true;
+ }
+
+ @Override public boolean updateCartridge(Cartridge cartridge)
+ throws InvalidCartridgeDefinitionException, InvalidIaasProviderException,
+ CartridgeDefinitionNotExistsException {
+
+ handleNullObject(cartridge, "Cartridge definition is null");
+
+ if (log.isInfoEnabled()) {
+ log.info("Updating cartridge: [cartridge-type] " + cartridge.getType());
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Cartridge definition: " + cartridge.toString());
+ }
+
+ try {
+ CloudControllerUtil.extractIaaSProvidersFromCartridge(cartridge);
+ } catch (Exception e) {
+ String msg = "Invalid cartridge definition: [cartridge-type] " + cartridge.getType();
+ log.error(msg, e);
+ throw new InvalidCartridgeDefinitionException(msg, e);
+ }
+
+ String cartridgeType = cartridge.getType();
+ if (cloudControllerContext.getCartridge(cartridgeType) != null) {
+ Cartridge cartridgeToBeRemoved = cloudControllerContext.getCartridge(cartridgeType);
+ try {
+ removeCartridgeFromCC(cartridgeToBeRemoved.getType());
+ } catch (InvalidCartridgeTypeException ignore) {
+ }
+ copyIaasProviders(cartridge, cartridgeToBeRemoved);
+ } else {
+ throw new CartridgeDefinitionNotExistsException("This cartridge definition not exists");
+ }
+
+ // Add cartridge to the cloud controller context and persist
+ CloudControllerContext.getInstance().addCartridge(cartridge);
+ CloudControllerContext.getInstance().persist();
+ // transaction ends
+
+ if (log.isInfoEnabled()) {
+ log.info("Successfully updated cartridge: [cartridge-type] " + cartridgeType);
+ }
+ return true;
+ }
+
+ private void copyIaasProviders(Cartridge destCartridge, Cartridge sourceCartridge) {
+
+ List<IaasProvider> newIaasProviders =
+ CloudControllerContext.getInstance().getIaasProviders(destCartridge.getType());
+
+ Map<String, IaasProvider> iaasProviderMap =
+ CloudControllerContext.getInstance().getPartitionToIaasProvider(sourceCartridge.getType());
+
+ if (iaasProviderMap != null) {
+ for (Entry<String, IaasProvider> entry : iaasProviderMap.entrySet()) {
+ if (entry == null) {
+ continue;
+ }
+ String partitionId = entry.getKey();
+ IaasProvider iaasProvider = entry.getValue();
+ if (newIaasProviders.contains(iaasProvider)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Copying partition from the cartridge that is undeployed, to the new cartridge: " +
+ "[partition-id] " + partitionId + " [cartridge-type] " + destCartridge.getType());
+ }
+ CloudControllerContext.getInstance().addIaasProvider(destCartridge.getType(), partitionId,
+ newIaasProviders.get(newIaasProviders.indexOf(
+ iaasProvider)));
+ }
+ }
+ }
+
+ }
+
+ public boolean removeCartridge(String cartridgeType) throws InvalidCartridgeTypeException {
+ //Removing the cartridge from CC
+ Cartridge cartridge = removeCartridgeFromCC(cartridgeType);
+ //removing the cartridge from Topology
+ removeCartridgeFromTopology(cartridge);
+
+ if (log.isInfoEnabled()) {
+ log.info("Successfully removed cartridge: [cartridge-type] " + cartridgeType);
+ }
+ return true;
+ }
+
+ private Cartridge removeCartridgeFromCC(String cartridgeType) throws InvalidCartridgeTypeException {
+ Cartridge cartridge = null;
+ if ((cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType)) != null) {
+ if (CloudControllerContext.getInstance().getCartridges().remove(cartridge)) {
+ // invalidate partition validation cache
+ CloudControllerContext.getInstance().removeFromCartridgeTypeToPartitionIds(cartridgeType);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Partition cache invalidated for cartridge " + cartridgeType);
+ }
+
+ CloudControllerContext.getInstance().persist();
+
+ if (log.isInfoEnabled()) {
+ log.info("Successfully removed cartridge: [cartridge-type] " + cartridgeType);
+ }
+ return cartridge;
+ }
+ }
+ String msg = "Cartridge not found: [cartridge-type] " + cartridgeType;
+ log.error(msg);
+ throw new InvalidCartridgeTypeException(msg);
+ }
+
+ private void removeCartridgeFromTopology(Cartridge cartridge) throws InvalidCartridgeTypeException {
+ // sends the service removed event
+ List<Cartridge> cartridgeList = new ArrayList<Cartridge>();
+ cartridgeList.add(cartridge);
+ TopologyBuilder.handleServiceRemoved(cartridgeList);
+ }
+
+ public boolean addServiceGroup(ServiceGroup servicegroup) throws InvalidServiceGroupException {
+
+ if (servicegroup == null) {
+ String msg = "Invalid ServiceGroup Definition: Definition is null.";
+ log.error(msg);
+ throw new IllegalArgumentException(msg);
+
+ }
+ CloudControllerContext.getInstance().addServiceGroup(servicegroup);
+ CloudControllerContext.getInstance().persist();
+ return true;
+ }
+
+ public boolean removeServiceGroup(String name) throws InvalidServiceGroupException {
+ if (log.isDebugEnabled()) {
+ log.debug("CloudControllerServiceImpl:removeServiceGroup: " + name);
+ }
+
+ ServiceGroup serviceGroup = null;
+
+ serviceGroup = CloudControllerContext.getInstance().getServiceGroup(name);
+
+ if (serviceGroup != null) {
+ if (CloudControllerContext.getInstance().getServiceGroups().remove(serviceGroup)) {
+ CloudControllerContext.getInstance().persist();
+ if (log.isInfoEnabled()) {
+ log.info("Successfully removed the cartridge group: [group-name] " + serviceGroup);
+ }
+ return true;
+ }
+ }
+
+ String msg = "Cartridge group not found: [group-name] " + name;
+ log.error(msg);
+ throw new InvalidServiceGroupException(msg);
+
+ }
+
+ @Override public ServiceGroup getServiceGroup(String name) throws InvalidServiceGroupException {
+
+ if (log.isDebugEnabled()) {
+ log.debug("getServiceGroupDefinition:" + name);
+ }
+
+ ServiceGroup serviceGroup = CloudControllerContext.getInstance().getServiceGroup(name);
+
+ if (serviceGroup == null) {
+ String message = "Cartridge group not found: [group-name] " + name;
+ if (log.isDebugEnabled()) {
+ log.debug(message);
+ }
+ throw new InvalidServiceGroupException(message);
+ }
+
+ return serviceGroup;
+ }
+
+ public String[] getServiceGroupSubGroups(String name) throws InvalidServiceGroupException {
+ ServiceGroup serviceGroup = this.getServiceGroup(name);
+ if (serviceGroup == null) {
+ throw new InvalidServiceGroupException("Invalid cartridge group: [group-name] " + serviceGroup);
+ }
+
+ return serviceGroup.getSubGroups();
+ }
+
+ /**
+ *
+ */
+ public String[] getServiceGroupCartridges(String name) throws InvalidServiceGroupException {
+ ServiceGroup serviceGroup = this.getServiceGroup(name);
+ if (serviceGroup == null) {
+ throw new InvalidServiceGroupException("Invalid cartridge group: [group-name] " + serviceGroup);
+ }
+ String[] cs = serviceGroup.getCartridges();
+ return cs;
+
+ }
+
+ public Dependencies getServiceGroupDependencies(String name) throws InvalidServiceGroupException {
+ ServiceGroup serviceGroup = this.getServiceGroup(name);
+ if (serviceGroup == null) {
+ throw new InvalidServiceGroupException("Invalid cartridge group: [group-name] " + serviceGroup);
+ }
+ return serviceGroup.getDependencies();
+ }
+
+ @Override public MemberContext[] startInstances(InstanceContext[] instanceContexts)
+ throws CartridgeNotFoundException, InvalidIaasProviderException, CloudControllerException {
+
+ handleNullObject(instanceContexts, "Instance start-up failed, member contexts is null");
+
+ List<MemberContext> memberContextList = new ArrayList<MemberContext>();
+ for (InstanceContext instanceContext : instanceContexts) {
+ if (instanceContext != null) {
+ MemberContext memberContext = startInstance(instanceContext);
+ memberContextList.add(memberContext);
+ }
+ }
+ MemberContext[] memberContextsArray = memberContextList.toArray(new MemberContext[memberContextList.size()]);
+ return memberContextsArray;
+ }
+
+ public MemberContext startInstance(InstanceContext instanceContext)
+ throws CartridgeNotFoundException, InvalidIaasProviderException, CloudControllerException {
+
+ try {
+ // Validate instance context
+ handleNullObject(instanceContext, "Could not start instance, instance context is null");
+ if (log.isDebugEnabled()) {
+ log.debug("Starting up instance: " + instanceContext);
+ }
+
+ // Validate partition
+ Partition partition = instanceContext.getPartition();
+ handleNullObject(partition, "Could not start instance, partition is null");
+
+ // Validate cluster
+ String partitionId = partition.getId();
+ String clusterId = instanceContext.getClusterId();
+ ClusterContext clusterContext = CloudControllerContext.getInstance().getClusterContext(clusterId);
+ handleNullObject(clusterContext,
+ "Could not start instance, cluster context not found: [cluster-id] " + clusterId);
+
+ // Validate cartridge
+ String cartridgeType = clusterContext.getCartridgeType();
+ Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType);
+ if (cartridge == null) {
+ String msg = "Could not startup instance, cartridge not found: [cartridge-type] " + cartridgeType;
+ log.error(msg);
+ throw new CartridgeNotFoundException(msg);
+ }
+
+ // Validate iaas provider
+ IaasProvider iaasProvider =
+ CloudControllerContext.getInstance().getIaasProviderOfPartition(cartridge.getType(), partitionId);
+ if (iaasProvider == null) {
+ String msg = String.format("Could not start instance, " +
+ "IaaS provider not found in cartridge %s for partition %s, " +
+ "partitions found: %s ", cartridgeType, partitionId,
+ CloudControllerContext.getInstance()
+ .getPartitionToIaasProvider(cartridge.getType())
+ .keySet().toString());
+ log.error(msg);
+ throw new InvalidIaasProviderException(msg);
+ }
+
+ // Generate member ID
+ String memberId = generateMemberId(clusterId);
+
+ // Create member context
+ String applicationId = clusterContext.getApplicationId();
+ MemberContext memberContext = createMemberContext(applicationId, cartridgeType, memberId,
+ CloudControllerUtil.getLoadBalancingIPTypeEnumFromString(
+ cartridge.getLoadBalancingIPType()),
+ instanceContext);
+
+ // Prepare payload
+ StringBuilder payload = new StringBuilder(clusterContext.getPayload());
+ addToPayload(payload, "MEMBER_ID", memberId);
+ addToPayload(payload, "INSTANCE_ID", memberContext.getInstanceId());
+ addToPayload(payload, "CLUSTER_INSTANCE_ID", memberContext.getClusterInstanceId());
+ addToPayload(payload, "LB_CLUSTER_ID", memberContext.getLbClusterId());
+ addToPayload(payload, "NETWORK_PARTITION_ID", memberContext.getNetworkPartitionId());
+ addToPayload(payload, "PARTITION_ID", partitionId);
+ addToPayload(payload, "INTERNAL", "false");
+
+ if (memberContext.getProperties() != null) {
+ org.apache.stratos.common.Properties properties = memberContext.getProperties();
+ if (properties != null) {
+ for (Property prop : properties.getProperties()) {
+ addToPayload(payload, prop.getName(), String.valueOf(prop.getValue()));
+ }
+ }
+ }
+
+ NetworkPartition networkPartition =
+ CloudControllerContext.getInstance().getNetworkPartition(memberContext.getNetworkPartitionId());
+
+ if (networkPartition.getProperties() != null) {
+ if (networkPartition.getProperties().getProperties() != null) {
+ for (Property property : networkPartition.getProperties().getProperties()) {
+ // check if a property is related to the payload. Currently
+ // this is done by checking if the
+ // property name starts with 'payload_parameter.' suffix. If
+ // so the payload param name will
+ // be taken as the substring from the index of '.' to the
+ // end of the property name.
+ if (property.getName().startsWith(PAYLOAD_PARAMETER)) {
+ String
<TRUNCATED>
[03/18] stratos git commit: Metering Service Implementation
Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/2fd289b8/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java
----------------------------------------------------------------------
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 f04a11f..d636d7e 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
@@ -31,6 +31,7 @@ import org.apache.stratos.cloud.controller.messaging.publisher.TopologyEventPubl
import org.apache.stratos.cloud.controller.statistics.publisher.BAMUsageDataPublisher;
import org.apache.stratos.cloud.controller.util.CloudControllerUtil;
import org.apache.stratos.common.Property;
+import org.apache.stratos.common.constants.StratosConstants;
import org.apache.stratos.messaging.domain.application.ClusterDataHolder;
import org.apache.stratos.messaging.domain.instance.ClusterInstance;
import org.apache.stratos.messaging.domain.topology.*;
@@ -53,7 +54,6 @@ import java.util.*;
public class TopologyBuilder {
private static final Log log = LogFactory.getLog(TopologyBuilder.class);
-
public static void handleServiceCreated(List<Cartridge> cartridgeList) {
Service service;
Topology topology = TopologyManager.getTopology();
@@ -67,7 +67,8 @@ public class TopologyBuilder {
TopologyManager.acquireWriteLock();
for (Cartridge cartridge : cartridgeList) {
if (!topology.serviceExists(cartridge.getType())) {
- ServiceType serviceType = cartridge.isMultiTenant() ? ServiceType.MultiTenant : ServiceType.SingleTenant;
+ ServiceType serviceType = cartridge.isMultiTenant() ? ServiceType.MultiTenant :
+ ServiceType.SingleTenant;
service = new Service(cartridge.getType(), serviceType);
Properties properties = new Properties();
@@ -99,8 +100,8 @@ public class TopologyBuilder {
Port port;
//adding ports to the event
for (PortMapping portMapping : portMappings) {
- port = new Port(portMapping.getProtocol(),
- portMapping.getPort(), portMapping.getProxyPort());
+ port = new Port(portMapping.getProtocol(), portMapping.getPort(),
+ portMapping.getProxyPort());
service.addPort(port);
}
}
@@ -138,8 +139,8 @@ public class TopologyBuilder {
log.warn(String.format("Service %s does not exist..", cartridge.getType()));
}
} else {
- log.warn("Subscription already exists. Hence not removing the service:" + cartridge.getType()
- + " from the topology");
+ log.warn("Subscription already exists. Hence not removing the service:" +
+ cartridge.getType() + " from the topology");
}
}
}
@@ -153,7 +154,7 @@ public class TopologyBuilder {
Service service = topology.getService(event.getServiceName());
if (service == null) {
log.error("Service " + event.getServiceName() +
- " not found in Topology, unable to update the cluster status to Created");
+ " not found in Topology, unable to update the cluster status to Created");
return;
}
@@ -161,9 +162,9 @@ public class TopologyBuilder {
log.warn("Cluster " + event.getClusterId() + " is already in the Topology ");
return;
} else {
- cluster = new Cluster(event.getServiceName(),
- event.getClusterId(), event.getDeploymentPolicyName(),
- event.getAutosScalePolicyName(), event.getAppId());
+ cluster = new Cluster(event.getServiceName(), event.getClusterId(),
+ event.getDeploymentPolicyName(),
+ event.getAutosScalePolicyName(), event.getAppId());
//cluster.setStatus(Status.Created);
cluster.setHostNames(event.getHostNames());
cluster.setTenantRange(event.getTenantRange());
@@ -186,11 +187,12 @@ public class TopologyBuilder {
for (Cluster cluster : appClusters) {
Service service = topology.getService(cluster.getServiceName());
if (service == null) {
- log.error("Service " + cluster.getServiceName()
- + " not found in Topology, unable to create Application cluster");
+ log.error("Service " + cluster.getServiceName() +
+ " not found in Topology, unable to create Application cluster");
} else {
service.addCluster(cluster);
- log.info("Application Cluster " + cluster.getClusterId() + " created in CC topology");
+ log.info("Application Cluster " + cluster.getClusterId() +
+ " created in CC topology");
}
}
TopologyManager.updateTopology(topology);
@@ -199,17 +201,19 @@ public class TopologyBuilder {
}
log.debug("Creating cluster port mappings: [appication-id] " + appId);
- for(Cluster cluster : appClusters) {
+ for (Cluster cluster : appClusters) {
String cartridgeType = cluster.getServiceName();
Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType);
- if(cartridge == null) {
- throw new CloudControllerException("Cartridge not found: [cartridge-type] " + cartridgeType);
+ if (cartridge == null) {
+ throw new CloudControllerException(
+ "Cartridge not found: [cartridge-type] " + cartridgeType);
}
- for(PortMapping portMapping : cartridge.getPortMappings()) {
- ClusterPortMapping clusterPortMapping = new ClusterPortMapping(appId,
- cluster.getClusterId(), portMapping.getName(), portMapping.getProtocol(), portMapping.getPort(),
- portMapping.getProxyPort());
+ for (PortMapping portMapping : cartridge.getPortMappings()) {
+ ClusterPortMapping clusterPortMapping =
+ new ClusterPortMapping(appId, cluster.getClusterId(), portMapping.getName(),
+ portMapping.getProtocol(), portMapping.getPort(),
+ portMapping.getProxyPort());
CloudControllerContext.getInstance().addClusterPortMapping(clusterPortMapping);
log.debug("Cluster port mapping created: " + clusterPortMapping.toString());
}
@@ -239,13 +243,13 @@ public class TopologyBuilder {
removedClusters.add(aService.removeCluster(aClusterData.getClusterId()));
} else {
log.warn("Service " + aClusterData.getServiceType() + " not found, " +
- "unable to remove Cluster " + aClusterData.getClusterId());
+ "unable to remove Cluster " + aClusterData.getClusterId());
}
// remove runtime data
context.removeClusterContext(aClusterData.getClusterId());
log.info("Removed application [ " + appId + " ]'s Cluster " +
- "[ " + aClusterData.getClusterId() + " ] from the topology");
+ "[ " + aClusterData.getClusterId() + " ] from the topology");
}
// persist runtime data changes
CloudControllerContext.getInstance().persist();
@@ -275,22 +279,23 @@ public class TopologyBuilder {
Service service = topology.getService(event.getServiceName());
if (service == null) {
log.error("Service " + event.getServiceName() +
- " not found in Topology, unable to update the cluster status to Created");
+ " not found in Topology, unable to update the cluster status to Created");
return;
}
Cluster cluster = service.getCluster(event.getClusterId());
if (cluster == null) {
- log.error("Cluster " + event.getClusterId() + " not found in Topology, unable to update " +
- "status to Created");
+ log.error("Cluster " + event.getClusterId() +
+ " not found in Topology, unable to update " +
+ "status to Created");
return;
}
ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
if (context == null) {
log.warn("Cluster Instance Context is not found for [cluster] " +
- event.getClusterId() + " [instance-id] " +
- event.getInstanceId());
+ event.getClusterId() + " [instance-id] " +
+ event.getInstanceId());
return;
}
ClusterStatus status = ClusterStatus.Created;
@@ -299,25 +304,25 @@ public class TopologyBuilder {
log.info("Cluster Created adding status started for" + cluster.getClusterId());
TopologyManager.updateTopology(topology);
//publishing data
- TopologyEventPublisher.sendClusterResetEvent(event.getAppId(), event.getServiceName(),
- event.getClusterId(), event.getInstanceId());
+ TopologyEventPublisher
+ .sendClusterResetEvent(event.getAppId(), event.getServiceName(),
+ event.getClusterId(), event.getInstanceId());
} else {
log.warn(String.format("Cluster state transition is not valid: [cluster-id] %s " +
- " [instance-id] %s [current-status] %s [status-requested] %s",
- event.getClusterId(), event.getInstanceId(),
- context.getStatus(), status));
+ " [instance-id] %s [current-status] %s [status-requested] %s",
+ event.getClusterId(), event.getInstanceId(),
+ context.getStatus(), status));
}
} finally {
TopologyManager.releaseWriteLock();
}
-
}
public static void handleClusterInstanceCreated(String serviceType, String clusterId,
- String alias, String instanceId, String partitionId,
- String networkPartitionId) {
+ String alias, String instanceId,
+ String partitionId, String networkPartitionId) {
TopologyManager.acquireWriteLock();
@@ -326,20 +331,20 @@ public class TopologyBuilder {
Service service = topology.getService(serviceType);
if (service == null) {
log.error("Service " + serviceType +
- " not found in Topology, unable to update the cluster status to Created");
+ " not found in Topology, unable to update the cluster status to Created");
return;
}
Cluster cluster = service.getCluster(clusterId);
if (cluster == null) {
log.error("Cluster " + clusterId + " not found in Topology, unable to update " +
- "status to Created");
+ "status to Created");
return;
}
if (cluster.getInstanceContexts(instanceId) != null) {
log.warn("The Instance context for the cluster already exists for [cluster] " +
- clusterId + " [instance-id] " + instanceId);
+ clusterId + " [instance-id] " + instanceId);
return;
}
@@ -350,8 +355,7 @@ public class TopologyBuilder {
TopologyManager.updateTopology(topology);
ClusterInstanceCreatedEvent clusterInstanceCreatedEvent =
- new ClusterInstanceCreatedEvent(serviceType, clusterId,
- clusterInstance);
+ new ClusterInstanceCreatedEvent(serviceType, clusterId, clusterInstance);
clusterInstanceCreatedEvent.setPartitionId(partitionId);
TopologyEventPublisher.sendClusterInstanceCreatedEvent(clusterInstanceCreatedEvent);
@@ -360,21 +364,18 @@ public class TopologyBuilder {
}
}
-
public static void handleClusterRemoved(ClusterContext ctxt) {
Topology topology = TopologyManager.getTopology();
Service service = topology.getService(ctxt.getCartridgeType());
String deploymentPolicy;
if (service == null) {
- log.warn(String.format("Service %s does not exist",
- ctxt.getCartridgeType()));
+ log.warn(String.format("Service %s does not exist", ctxt.getCartridgeType()));
return;
}
if (!service.clusterExists(ctxt.getClusterId())) {
- log.warn(String.format("Cluster %s does not exist for service %s",
- ctxt.getClusterId(),
- ctxt.getCartridgeType()));
+ log.warn(String.format("Cluster %s does not exist for service %s", ctxt.getClusterId(),
+ ctxt.getCartridgeType()));
return;
}
@@ -407,6 +408,11 @@ public class TopologyBuilder {
String lbClusterId = memberContext.getLbClusterId();
long initTime = memberContext.getInitTime();
+ String autoscalingReason =
+ memberContext.getProperties().getProperty(StratosConstants.SCALING_REASON)
+ .getValue();
+ long scalingTime = Long.parseLong(
+ memberContext.getProperties().getProperty(StratosConstants.SCALING_TIME).getValue());
if (cluster.memberExists(memberId)) {
log.warn(String.format("Member %s already exists", memberId));
return;
@@ -414,13 +420,24 @@ public class TopologyBuilder {
try {
TopologyManager.acquireWriteLock();
- Member member = new Member(service.getServiceName(), clusterId, memberId, clusterInstanceId,
- networkPartitionId, partitionId, memberContext.getLoadBalancingIPType(), initTime);
+ Member member =
+ new Member(service.getServiceName(), clusterId, memberId, clusterInstanceId,
+ networkPartitionId, partitionId,
+ memberContext.getLoadBalancingIPType(), initTime);
member.setStatus(MemberStatus.Created);
member.setLbClusterId(lbClusterId);
- member.setProperties(CloudControllerUtil.toJavaUtilProperties(memberContext.getProperties()));
+ member.setProperties(
+ CloudControllerUtil.toJavaUtilProperties(memberContext.getProperties()));
cluster.addMember(member);
TopologyManager.updateTopology(topology);
+ Long timeStamp = System.currentTimeMillis();
+ //publishing to BAM
+ BAMUsageDataPublisher
+ .publish(memberContext.getMemberId(), memberContext.getPartition().getId(),
+ memberContext.getNetworkPartitionId(), memberContext.getClusterId(),
+ memberContext.getClusterInstanceId(), memberContext.getCartridgeType(),
+ MemberStatus.Created.toString(), timeStamp, autoscalingReason,
+ scalingTime, null);
} finally {
TopologyManager.releaseWriteLock();
}
@@ -437,22 +454,19 @@ public class TopologyBuilder {
Topology topology = TopologyManager.getTopology();
Service service = topology.getService(memberContext.getCartridgeType());
if (service == null) {
- log.warn(String.format("Service %s does not exist",
- memberContext.getCartridgeType()));
+ log.warn(String.format("Service %s does not exist", memberContext.getCartridgeType()));
return;
}
if (!service.clusterExists(memberContext.getClusterId())) {
log.warn(String.format("Cluster %s does not exist in service %s",
- memberContext.getClusterId(),
- memberContext.getCartridgeType()));
+ memberContext.getClusterId(), memberContext.getCartridgeType()));
return;
}
Member member = service.getCluster(memberContext.getClusterId()).
getMember(memberContext.getMemberId());
if (member == null) {
- log.warn(String.format("Member %s does not exist",
- memberContext.getMemberId()));
+ log.warn(String.format("Member %s does not exist", memberContext.getMemberId()));
return;
}
@@ -472,38 +486,39 @@ public class TopologyBuilder {
// try update lifecycle state
if (!member.isStateTransitionValid(MemberStatus.Initialized)) {
log.error("Invalid state transition from " + member.getStatus() + " to " +
- MemberStatus.Initialized);
+ MemberStatus.Initialized);
return;
} else {
member.setStatus(MemberStatus.Initialized);
log.info("Member status updated to initialized");
TopologyManager.updateTopology(topology);
-
+ Long timeStamp = System.currentTimeMillis();
TopologyEventPublisher.sendMemberInitializedEvent(memberContext);
//publishing data
- BAMUsageDataPublisher.publish(memberContext.getMemberId(),
- memberContext.getPartition().getId(),
- memberContext.getNetworkPartitionId(),
- memberContext.getClusterId(),
- memberContext.getCartridgeType(),
- MemberStatus.Initialized.toString(),
- null);
+ BAMUsageDataPublisher
+ .publish(memberContext.getMemberId(), memberContext.getPartition().getId(),
+ memberContext.getNetworkPartitionId(),
+ memberContext.getClusterId(), memberContext.getClusterInstanceId(),
+ memberContext.getCartridgeType(),
+ MemberStatus.Initialized.toString(), timeStamp, null, null, null);
}
} finally {
TopologyManager.releaseWriteLock();
}
}
- private static int findKubernetesServicePort(String clusterId, List<KubernetesService> kubernetesServices,
+ private static int findKubernetesServicePort(String clusterId,
+ List<KubernetesService> kubernetesServices,
PortMapping portMapping) {
for (KubernetesService kubernetesService : kubernetesServices) {
if (kubernetesService.getProtocol().equals(portMapping.getProtocol())) {
return kubernetesService.getPort();
}
}
- throw new RuntimeException("Kubernetes service port not found: [cluster-id] " + clusterId + " [port] "
- + portMapping.getPort());
+ throw new RuntimeException(
+ "Kubernetes service port not found: [cluster-id] " + clusterId + " [port] " +
+ portMapping.getPort());
}
public static void handleMemberStarted(InstanceStartedEvent instanceStartedEvent) {
@@ -512,13 +527,13 @@ public class TopologyBuilder {
Service service = topology.getService(instanceStartedEvent.getServiceName());
if (service == null) {
log.warn(String.format("Service %s does not exist",
- instanceStartedEvent.getServiceName()));
+ instanceStartedEvent.getServiceName()));
return;
}
if (!service.clusterExists(instanceStartedEvent.getClusterId())) {
log.warn(String.format("Cluster %s does not exist in service %s",
- instanceStartedEvent.getClusterId(),
- instanceStartedEvent.getServiceName()));
+ instanceStartedEvent.getClusterId(),
+ instanceStartedEvent.getServiceName()));
return;
}
@@ -526,7 +541,7 @@ public class TopologyBuilder {
Member member = cluster.getMember(instanceStartedEvent.getMemberId());
if (member == null) {
log.warn(String.format("Member %s does not exist",
- instanceStartedEvent.getMemberId()));
+ instanceStartedEvent.getMemberId()));
return;
}
@@ -535,30 +550,33 @@ public class TopologyBuilder {
// try update lifecycle state
if (!member.isStateTransitionValid(MemberStatus.Starting)) {
log.error("Invalid State Transition from " + member.getStatus() + " to " +
- MemberStatus.Starting);
+ MemberStatus.Starting);
return;
} else {
member.setStatus(MemberStatus.Starting);
log.info("member started event adding status started");
TopologyManager.updateTopology(topology);
+ Long timeStamp = System.currentTimeMillis();
//memberStartedEvent.
TopologyEventPublisher.sendMemberStartedEvent(instanceStartedEvent);
//publishing data
BAMUsageDataPublisher.publish(instanceStartedEvent.getMemberId(),
- instanceStartedEvent.getPartitionId(),
- instanceStartedEvent.getNetworkPartitionId(),
- instanceStartedEvent.getClusterId(),
- instanceStartedEvent.getServiceName(),
- MemberStatus.Starting.toString(),
- null);
+ instanceStartedEvent.getPartitionId(),
+ instanceStartedEvent.getNetworkPartitionId(),
+ instanceStartedEvent.getClusterId(),
+ instanceStartedEvent.getClusterInstanceId(),
+ instanceStartedEvent.getServiceName(),
+ MemberStatus.Starting.toString(), timeStamp, null,
+ null, null);
}
} finally {
TopologyManager.releaseWriteLock();
}
} catch (Exception e) {
- String message = String.format("Could not handle member started event: [application-id] %s " +
- "[service-name] %s [member-id] %s", instanceStartedEvent.getApplicationId(),
+ String message = String.format(
+ "Could not handle member started event: [application-id] %s " +
+ "[service-name] %s [member-id] %s", instanceStartedEvent.getApplicationId(),
instanceStartedEvent.getServiceName(), instanceStartedEvent.getMemberId());
log.warn(message, e);
}
@@ -569,31 +587,31 @@ public class TopologyBuilder {
Service service = topology.getService(instanceActivatedEvent.getServiceName());
if (service == null) {
log.warn(String.format("Service %s does not exist",
- instanceActivatedEvent.getServiceName()));
+ instanceActivatedEvent.getServiceName()));
return;
}
Cluster cluster = service.getCluster(instanceActivatedEvent.getClusterId());
if (cluster == null) {
log.warn(String.format("Cluster %s does not exist",
- instanceActivatedEvent.getClusterId()));
+ instanceActivatedEvent.getClusterId()));
return;
}
Member member = cluster.getMember(instanceActivatedEvent.getMemberId());
if (member == null) {
log.warn(String.format("Member %s does not exist",
- instanceActivatedEvent.getMemberId()));
+ instanceActivatedEvent.getMemberId()));
return;
}
- MemberActivatedEvent memberActivatedEvent = new MemberActivatedEvent(
- instanceActivatedEvent.getServiceName(),
- instanceActivatedEvent.getClusterId(),
- instanceActivatedEvent.getClusterInstanceId(),
- instanceActivatedEvent.getMemberId(),
- instanceActivatedEvent.getNetworkPartitionId(),
- instanceActivatedEvent.getPartitionId());
+ MemberActivatedEvent memberActivatedEvent =
+ new MemberActivatedEvent(instanceActivatedEvent.getServiceName(),
+ instanceActivatedEvent.getClusterId(),
+ instanceActivatedEvent.getClusterInstanceId(),
+ instanceActivatedEvent.getMemberId(),
+ instanceActivatedEvent.getNetworkPartitionId(),
+ instanceActivatedEvent.getPartitionId());
// grouping - set grouid
//TODO
@@ -602,39 +620,48 @@ public class TopologyBuilder {
TopologyManager.acquireWriteLock();
// try update lifecycle state
if (!member.isStateTransitionValid(MemberStatus.Active)) {
- log.error("Invalid state transition from [" + member.getStatus() + "] to [" + MemberStatus.Active + "]");
+ log.error("Invalid state transition from [" + member.getStatus() + "] to [" +
+ MemberStatus.Active + "]");
return;
} else {
member.setStatus(MemberStatus.Active);
// Set member ports
try {
- Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(service.getServiceName());
+ Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(
+ service.getServiceName());
if (cartridge == null) {
- throw new RuntimeException(String.format("Cartridge not found: [cartridge-type] %s",
- service.getServiceName()));
+ throw new RuntimeException(
+ String.format("Cartridge not found: [cartridge-type] %s",
+ service.getServiceName()));
}
Port port;
int portValue;
List<PortMapping> portMappings = Arrays.asList(cartridge.getPortMappings());
String clusterId = cluster.getClusterId();
- ClusterContext clusterContext = CloudControllerContext.getInstance().getClusterContext(clusterId);
- List<KubernetesService> kubernetesServices = clusterContext.getKubernetesServices();
+ ClusterContext clusterContext =
+ CloudControllerContext.getInstance().getClusterContext(clusterId);
+ List<KubernetesService> kubernetesServices =
+ clusterContext.getKubernetesServices();
for (PortMapping portMapping : portMappings) {
if (kubernetesServices != null) {
- portValue = findKubernetesServicePort(clusterId, kubernetesServices, portMapping);
+ portValue = findKubernetesServicePort(clusterId, kubernetesServices,
+ portMapping);
} else {
portValue = portMapping.getPort();
}
- port = new Port(portMapping.getProtocol(), portValue, portMapping.getProxyPort());
+ port = new Port(portMapping.getProtocol(), portValue,
+ portMapping.getProxyPort());
member.addPort(port);
memberActivatedEvent.addPort(port);
}
} catch (Exception e) {
- String message = String.format("Could not add member ports: [service-name] %s [member-id] %s",
- memberActivatedEvent.getServiceName(), memberActivatedEvent.getMemberId());
+ String message = String.format(
+ "Could not add member ports: [service-name] %s [member-id] %s",
+ memberActivatedEvent.getServiceName(),
+ memberActivatedEvent.getMemberId());
log.error(message, e);
}
@@ -644,122 +671,126 @@ public class TopologyBuilder {
memberActivatedEvent.setDefaultPublicIP(member.getDefaultPublicIP());
memberActivatedEvent.setMemberPublicIPs(member.getMemberPublicIPs());
TopologyManager.updateTopology(topology);
-
+ Long timeStamp = System.currentTimeMillis();
// Publish member activated event
TopologyEventPublisher.sendMemberActivatedEvent(memberActivatedEvent);
// Publish statistics data
BAMUsageDataPublisher.publish(memberActivatedEvent.getMemberId(),
- memberActivatedEvent.getPartitionId(),
- memberActivatedEvent.getNetworkPartitionId(),
- memberActivatedEvent.getClusterId(),
- memberActivatedEvent.getServiceName(),
- MemberStatus.Active.toString(),
- null);
+ memberActivatedEvent.getPartitionId(),
+ memberActivatedEvent.getNetworkPartitionId(),
+ memberActivatedEvent.getClusterId(),
+ memberActivatedEvent.getClusterInstanceId(),
+ memberActivatedEvent.getServiceName(),
+ MemberStatus.Active.toString(), timeStamp, null, null,
+ null);
}
} finally {
TopologyManager.releaseWriteLock();
}
}
- public static void handleMemberReadyToShutdown(InstanceReadyToShutdownEvent instanceReadyToShutdownEvent)
+ public static void handleMemberReadyToShutdown(
+ InstanceReadyToShutdownEvent instanceReadyToShutdownEvent)
throws InvalidMemberException, InvalidCartridgeTypeException {
Topology topology = TopologyManager.getTopology();
Service service = topology.getService(instanceReadyToShutdownEvent.getServiceName());
//update the status of the member
if (service == null) {
log.warn(String.format("Service %s does not exist",
- instanceReadyToShutdownEvent.getServiceName()));
+ instanceReadyToShutdownEvent.getServiceName()));
return;
}
Cluster cluster = service.getCluster(instanceReadyToShutdownEvent.getClusterId());
if (cluster == null) {
log.warn(String.format("Cluster %s does not exist",
- instanceReadyToShutdownEvent.getClusterId()));
+ instanceReadyToShutdownEvent.getClusterId()));
return;
}
-
+ Long timeStamp = null;
Member member = cluster.getMember(instanceReadyToShutdownEvent.getMemberId());
if (member == null) {
log.warn(String.format("Member %s does not exist",
- instanceReadyToShutdownEvent.getMemberId()));
+ instanceReadyToShutdownEvent.getMemberId()));
return;
}
- MemberReadyToShutdownEvent memberReadyToShutdownEvent = new MemberReadyToShutdownEvent(
- instanceReadyToShutdownEvent.getServiceName(),
- instanceReadyToShutdownEvent.getClusterId(),
- instanceReadyToShutdownEvent.getClusterInstanceId(),
- instanceReadyToShutdownEvent.getMemberId(),
- instanceReadyToShutdownEvent.getNetworkPartitionId(),
- instanceReadyToShutdownEvent.getPartitionId());
+ MemberReadyToShutdownEvent memberReadyToShutdownEvent =
+ new MemberReadyToShutdownEvent(instanceReadyToShutdownEvent.getServiceName(),
+ instanceReadyToShutdownEvent.getClusterId(),
+ instanceReadyToShutdownEvent.getClusterInstanceId(),
+ instanceReadyToShutdownEvent.getMemberId(),
+ instanceReadyToShutdownEvent.getNetworkPartitionId(),
+ instanceReadyToShutdownEvent.getPartitionId());
try {
TopologyManager.acquireWriteLock();
if (!member.isStateTransitionValid(MemberStatus.ReadyToShutDown)) {
log.error("Invalid State Transition from " + member.getStatus() + " to " +
- MemberStatus.ReadyToShutDown);
+ MemberStatus.ReadyToShutDown);
return;
}
member.setStatus(MemberStatus.ReadyToShutDown);
log.info("Member Ready to shut down event adding status started");
TopologyManager.updateTopology(topology);
+ timeStamp = System.currentTimeMillis();
} finally {
TopologyManager.releaseWriteLock();
}
TopologyEventPublisher.sendMemberReadyToShutdownEvent(memberReadyToShutdownEvent);
//publishing data
BAMUsageDataPublisher.publish(instanceReadyToShutdownEvent.getMemberId(),
- instanceReadyToShutdownEvent.getPartitionId(),
- instanceReadyToShutdownEvent.getNetworkPartitionId(),
- instanceReadyToShutdownEvent.getClusterId(),
- instanceReadyToShutdownEvent.getServiceName(),
- MemberStatus.ReadyToShutDown.toString(),
- null);
+ instanceReadyToShutdownEvent.getPartitionId(),
+ instanceReadyToShutdownEvent.getNetworkPartitionId(),
+ instanceReadyToShutdownEvent.getClusterId(),
+ instanceReadyToShutdownEvent.getClusterInstanceId(),
+ instanceReadyToShutdownEvent.getServiceName(),
+ MemberStatus.ReadyToShutDown.toString(), timeStamp, null,
+ null, null);
//termination of particular instance will be handled by autoscaler
}
- public static void handleMemberMaintenance(InstanceMaintenanceModeEvent instanceMaintenanceModeEvent)
+ public static void handleMemberMaintenance(
+ InstanceMaintenanceModeEvent instanceMaintenanceModeEvent)
throws InvalidMemberException, InvalidCartridgeTypeException {
Topology topology = TopologyManager.getTopology();
Service service = topology.getService(instanceMaintenanceModeEvent.getServiceName());
//update the status of the member
if (service == null) {
log.warn(String.format("Service %s does not exist",
- instanceMaintenanceModeEvent.getServiceName()));
+ instanceMaintenanceModeEvent.getServiceName()));
return;
}
Cluster cluster = service.getCluster(instanceMaintenanceModeEvent.getClusterId());
if (cluster == null) {
log.warn(String.format("Cluster %s does not exist",
- instanceMaintenanceModeEvent.getClusterId()));
+ instanceMaintenanceModeEvent.getClusterId()));
return;
}
Member member = cluster.getMember(instanceMaintenanceModeEvent.getMemberId());
if (member == null) {
log.warn(String.format("Member %s does not exist",
- instanceMaintenanceModeEvent.getMemberId()));
+ instanceMaintenanceModeEvent.getMemberId()));
return;
}
-
- MemberMaintenanceModeEvent memberMaintenanceModeEvent = new MemberMaintenanceModeEvent(
- instanceMaintenanceModeEvent.getServiceName(),
- instanceMaintenanceModeEvent.getClusterId(),
- instanceMaintenanceModeEvent.getClusterInstanceId(),
- instanceMaintenanceModeEvent.getMemberId(),
- instanceMaintenanceModeEvent.getNetworkPartitionId(),
- instanceMaintenanceModeEvent.getPartitionId());
+ MemberMaintenanceModeEvent memberMaintenanceModeEvent =
+ new MemberMaintenanceModeEvent(instanceMaintenanceModeEvent.getServiceName(),
+ instanceMaintenanceModeEvent.getClusterId(),
+ instanceMaintenanceModeEvent.getClusterInstanceId(),
+ instanceMaintenanceModeEvent.getMemberId(),
+ instanceMaintenanceModeEvent.getNetworkPartitionId(),
+ instanceMaintenanceModeEvent.getPartitionId());
try {
TopologyManager.acquireWriteLock();
// try update lifecycle state
if (!member.isStateTransitionValid(MemberStatus.In_Maintenance)) {
- log.error("Invalid State Transition from " + member.getStatus() + " to "
- + MemberStatus.In_Maintenance);
+ log.error("Invalid State Transition from " + member.getStatus() + " to " +
+ MemberStatus.In_Maintenance);
return;
}
member.setStatus(MemberStatus.In_Maintenance);
@@ -790,21 +821,18 @@ public class TopologyBuilder {
Service service = topology.getService(serviceName);
Properties properties;
if (service == null) {
- log.warn(String.format("Service %s does not exist",
- serviceName));
+ log.warn(String.format("Service %s does not exist", serviceName));
return;
}
Cluster cluster = service.getCluster(clusterId);
if (cluster == null) {
- log.warn(String.format("Cluster %s does not exist",
- clusterId));
+ log.warn(String.format("Cluster %s does not exist", clusterId));
return;
}
Member member = cluster.getMember(memberId);
if (member == null) {
- log.warn(String.format("Member %s does not exist",
- memberId));
+ log.warn(String.format("Member %s does not exist", memberId));
return;
}
@@ -818,11 +846,11 @@ public class TopologyBuilder {
} finally {
TopologyManager.releaseWriteLock();
}
- /* @TODO leftover from grouping_poc*/
+ /* @TODO leftover from grouping_poc*/
String groupAlias = null;
- TopologyEventPublisher.sendMemberTerminatedEvent(serviceName, clusterId, memberId,
- clusterInstanceId, networkPartitionId,
- partitionId, properties, groupAlias);
+ TopologyEventPublisher
+ .sendMemberTerminatedEvent(serviceName, clusterId, memberId, clusterInstanceId,
+ networkPartitionId, partitionId, properties, groupAlias);
}
public static void handleMemberSuspended() {
@@ -834,48 +862,52 @@ public class TopologyBuilder {
}
}
- public static void handleClusterActivatedEvent(ClusterStatusClusterActivatedEvent clusterStatusClusterActivatedEvent) {
+ public static void handleClusterActivatedEvent(
+ ClusterStatusClusterActivatedEvent clusterStatusClusterActivatedEvent) {
Topology topology = TopologyManager.getTopology();
Service service = topology.getService(clusterStatusClusterActivatedEvent.getServiceName());
//update the status of the cluster
if (service == null) {
log.warn(String.format("Service %s does not exist",
- clusterStatusClusterActivatedEvent.getServiceName()));
+ clusterStatusClusterActivatedEvent.getServiceName()));
return;
}
Cluster cluster = service.getCluster(clusterStatusClusterActivatedEvent.getClusterId());
if (cluster == null) {
log.warn(String.format("Cluster %s does not exist",
- clusterStatusClusterActivatedEvent.getClusterId()));
+ clusterStatusClusterActivatedEvent.getClusterId()));
return;
}
String clusterId = cluster.getClusterId();
- ClusterContext clusterContext = CloudControllerContext.getInstance().getClusterContext(clusterId);
+ ClusterContext clusterContext =
+ CloudControllerContext.getInstance().getClusterContext(clusterId);
if (clusterContext == null) {
log.warn("Cluster context not found: [cluster-id] " + clusterId);
return;
}
ClusterInstanceActivatedEvent clusterInstanceActivatedEvent =
- new ClusterInstanceActivatedEvent(
- clusterStatusClusterActivatedEvent.getAppId(),
- clusterStatusClusterActivatedEvent.getServiceName(),
- clusterStatusClusterActivatedEvent.getClusterId(),
- clusterStatusClusterActivatedEvent.getInstanceId());
+ new ClusterInstanceActivatedEvent(clusterStatusClusterActivatedEvent.getAppId(),
+ clusterStatusClusterActivatedEvent
+ .getServiceName(),
+ clusterStatusClusterActivatedEvent.getClusterId(),
+ clusterStatusClusterActivatedEvent
+ .getInstanceId());
try {
TopologyManager.acquireWriteLock();
List<KubernetesService> kubernetesServices = clusterContext.getKubernetesServices();
cluster.setKubernetesServices(kubernetesServices);
clusterInstanceActivatedEvent.setKubernetesServices(kubernetesServices);
- ClusterInstance context = cluster.getInstanceContexts(clusterStatusClusterActivatedEvent.getInstanceId());
+ ClusterInstance context =
+ cluster.getInstanceContexts(clusterStatusClusterActivatedEvent.getInstanceId());
if (context == null) {
log.warn("Cluster instance context is not found for [cluster] " +
- clusterStatusClusterActivatedEvent.getClusterId() + " [instance-id] " +
- clusterStatusClusterActivatedEvent.getInstanceId());
+ clusterStatusClusterActivatedEvent.getClusterId() + " [instance-id] " +
+ clusterStatusClusterActivatedEvent.getInstanceId());
return;
}
ClusterStatus status = ClusterStatus.Active;
@@ -887,9 +919,10 @@ public class TopologyBuilder {
TopologyEventPublisher.sendClusterActivatedEvent(clusterInstanceActivatedEvent);
} else {
log.error(String.format("Cluster state transition is not valid: [cluster-id] %s " +
- " [instance-id] %s [current-status] %s [status-requested] %s",
- clusterStatusClusterActivatedEvent.getClusterId(), clusterStatusClusterActivatedEvent.getInstanceId(),
- context.getStatus(), status));
+ " [instance-id] %s [current-status] %s [status-requested] %s",
+ clusterStatusClusterActivatedEvent.getClusterId(),
+ clusterStatusClusterActivatedEvent.getInstanceId(),
+ context.getStatus(), status));
return;
}
} finally {
@@ -905,30 +938,30 @@ public class TopologyBuilder {
//update the status of the cluster
if (service == null) {
log.warn(String.format("Service %s does not exist",
- clusterInactivateEvent.getServiceName()));
+ clusterInactivateEvent.getServiceName()));
return;
}
Cluster cluster = service.getCluster(clusterInactivateEvent.getClusterId());
if (cluster == null) {
log.warn(String.format("Cluster %s does not exist",
- clusterInactivateEvent.getClusterId()));
+ clusterInactivateEvent.getClusterId()));
return;
}
ClusterInstanceInactivateEvent clusterInactivatedEvent1 =
- new ClusterInstanceInactivateEvent(
- clusterInactivateEvent.getAppId(),
- clusterInactivateEvent.getServiceName(),
- clusterInactivateEvent.getClusterId(),
- clusterInactivateEvent.getInstanceId());
+ new ClusterInstanceInactivateEvent(clusterInactivateEvent.getAppId(),
+ clusterInactivateEvent.getServiceName(),
+ clusterInactivateEvent.getClusterId(),
+ clusterInactivateEvent.getInstanceId());
try {
TopologyManager.acquireWriteLock();
- ClusterInstance context = cluster.getInstanceContexts(clusterInactivateEvent.getInstanceId());
+ ClusterInstance context =
+ cluster.getInstanceContexts(clusterInactivateEvent.getInstanceId());
if (context == null) {
log.warn("Cluster Instance Context is not found for [cluster] " +
- clusterInactivateEvent.getClusterId() + " [instance-id] " +
- clusterInactivateEvent.getInstanceId());
+ clusterInactivateEvent.getClusterId() + " [instance-id] " +
+ clusterInactivateEvent.getInstanceId());
return;
}
ClusterStatus status = ClusterStatus.Inactive;
@@ -940,9 +973,10 @@ public class TopologyBuilder {
TopologyEventPublisher.sendClusterInactivateEvent(clusterInactivatedEvent1);
} else {
log.error(String.format("Cluster state transition is not valid: [cluster-id] %s " +
- " [instance-id] %s [current-status] %s [status-requested] %s",
- clusterInactivateEvent.getClusterId(), clusterInactivateEvent.getInstanceId(),
- context.getStatus(), status));
+ " [instance-id] %s [current-status] %s [status-requested] %s",
+ clusterInactivateEvent.getClusterId(),
+ clusterInactivateEvent.getInstanceId(), context.getStatus(),
+ status));
return;
}
} finally {
@@ -950,13 +984,15 @@ public class TopologyBuilder {
}
}
-
- private static void deleteAppResourcesFromMetadataService(ApplicationInstanceTerminatedEvent event) {
+ private static void deleteAppResourcesFromMetadataService(
+ ApplicationInstanceTerminatedEvent event) {
try {
MetaDataServiceClient metadataClient = new DefaultMetaDataServiceClient();
metadataClient.deleteApplicationProperties(event.getAppId());
} catch (Exception e) {
- log.error("Error occurred while deleting the application resources frm metadata service ", e);
+ log.error(
+ "Error occurred while deleting the application resources frm metadata service ",
+ e);
}
}
@@ -970,49 +1006,49 @@ public class TopologyBuilder {
//update the status of the cluster
if (service == null) {
- log.warn(String.format("Service %s does not exist",
- event.getServiceName()));
+ log.warn(String.format("Service %s does not exist", event.getServiceName()));
return;
}
Cluster cluster = service.getCluster(event.getClusterId());
if (cluster == null) {
- log.warn(String.format("Cluster %s does not exist",
- event.getClusterId()));
+ log.warn(String.format("Cluster %s does not exist", event.getClusterId()));
return;
}
ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
if (context == null) {
log.warn("Cluster Instance Context is not found for [cluster] " +
- event.getClusterId() + " [instance-id] " +
- event.getInstanceId());
+ event.getClusterId() + " [instance-id] " +
+ event.getInstanceId());
return;
}
ClusterStatus status = ClusterStatus.Terminated;
if (context.isStateTransitionValid(status)) {
context.setStatus(status);
- log.info("Cluster Terminated adding status started for and removing the cluster instance"
- + cluster.getClusterId());
+ log.info(
+ "Cluster Terminated adding status started for and removing the cluster instance" +
+ cluster.getClusterId());
cluster.removeInstanceContext(event.getInstanceId());
TopologyManager.updateTopology(topology);
//publishing data
- ClusterInstanceTerminatedEvent clusterTerminatedEvent = new ClusterInstanceTerminatedEvent(event.getAppId(),
- event.getServiceName(), event.getClusterId(), event.getInstanceId());
+ ClusterInstanceTerminatedEvent clusterTerminatedEvent =
+ new ClusterInstanceTerminatedEvent(event.getAppId(), event.getServiceName(),
+ event.getClusterId(),
+ event.getInstanceId());
TopologyEventPublisher.sendClusterTerminatedEvent(clusterTerminatedEvent);
} else {
log.error(String.format("Cluster state transition is not valid: [cluster-id] %s " +
- " [instance-id] %s [current-status] %s [status-requested] %s",
- event.getClusterId(), event.getInstanceId(),
- context.getStatus(), status));
+ " [instance-id] %s [current-status] %s [status-requested] %s",
+ event.getClusterId(), event.getInstanceId(),
+ context.getStatus(), status));
return;
}
} finally {
TopologyManager.releaseWriteLock();
}
-
}
public static void handleClusterTerminatingEvent(ClusterStatusClusterTerminatingEvent event) {
@@ -1025,14 +1061,16 @@ public class TopologyBuilder {
getCluster(event.getClusterId());
if (!cluster.isStateTransitionValid(ClusterStatus.Terminating, event.getInstanceId())) {
- log.error("Invalid state transfer from " + cluster.getStatus(event.getInstanceId()) + " to " +
+ log.error(
+ "Invalid state transfer from " + cluster.getStatus(event.getInstanceId()) +
+ " to " +
ClusterStatus.Terminating);
}
ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
if (context == null) {
log.warn("Cluster Instance Context is not found for [cluster] " +
- event.getClusterId() + " [instance-id] " +
- event.getInstanceId());
+ event.getClusterId() + " [instance-id] " +
+ event.getInstanceId());
return;
}
ClusterStatus status = ClusterStatus.Terminating;
@@ -1041,22 +1079,26 @@ public class TopologyBuilder {
log.info("Cluster Terminating started for " + cluster.getClusterId());
TopologyManager.updateTopology(topology);
//publishing data
- ClusterInstanceTerminatingEvent clusterTerminaingEvent = new ClusterInstanceTerminatingEvent(event.getAppId(),
- event.getServiceName(), event.getClusterId(), event.getInstanceId());
+ ClusterInstanceTerminatingEvent clusterTerminaingEvent =
+ new ClusterInstanceTerminatingEvent(event.getAppId(),
+ event.getServiceName(),
+ event.getClusterId(),
+ event.getInstanceId());
TopologyEventPublisher.sendClusterTerminatingEvent(clusterTerminaingEvent);
// Remove kubernetes services if available
- ClusterContext clusterContext =
- CloudControllerContext.getInstance().getClusterContext(event.getClusterId());
- if(StringUtils.isNotBlank(clusterContext.getKubernetesClusterId())) {
+ ClusterContext clusterContext = CloudControllerContext.getInstance()
+ .getClusterContext(
+ event.getClusterId());
+ if (StringUtils.isNotBlank(clusterContext.getKubernetesClusterId())) {
KubernetesIaas.removeKubernetesServices(event.getAppId(), event.getClusterId());
}
} else {
log.error(String.format("Cluster state transition is not valid: [cluster-id] %s " +
- " [instance-id] %s [current-status] %s [status-requested] %s",
- event.getClusterId(), event.getInstanceId(),
- context.getStatus(), status));
+ " [instance-id] %s [current-status] %s [status-requested] %s",
+ event.getClusterId(), event.getInstanceId(),
+ context.getStatus(), status));
}
} finally {
TopologyManager.releaseWriteLock();
http://git-wip-us.apache.org/repos/asf/stratos/blob/2fd289b8/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
index 4d51cc1..70cd79b 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
@@ -447,13 +447,14 @@ public class CloudControllerServiceImpl implements CloudControllerService {
clusterContext.setVolumes(volumes);
}
- // Handle member created event
- TopologyBuilder.handleMemberCreatedEvent(memberContext);
-
// Persist member context
CloudControllerContext.getInstance().addMemberContext(memberContext);
CloudControllerContext.getInstance().persist();
+ // Handle member created event
+ TopologyBuilder.handleMemberCreatedEvent(memberContext);
+
+
// Start instance in a new thread
if (log.isDebugEnabled()) {
log.debug(String.format("Starting instance creator thread: [cluster] %s [cluster-instance] %s " +
http://git-wip-us.apache.org/repos/asf/stratos/blob/2fd289b8/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java
index 37580eb..97c3ed1 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java
@@ -66,14 +66,15 @@ public class CloudControllerServiceUtil {
memberContext.getClusterId(), memberContext.getNetworkPartitionId(),
partitionId, memberContext.getMemberId());
+ Long timeStamp = System.currentTimeMillis();
// Publish statistics to BAM
BAMUsageDataPublisher.publish(memberContext.getMemberId(),
- partitionId,
- memberContext.getNetworkPartitionId(),
- memberContext.getClusterId(),
- memberContext.getCartridgeType(),
- MemberStatus.Terminated.toString(),
- null);
+ partitionId,
+ memberContext.getNetworkPartitionId(),
+ memberContext.getClusterId(),memberContext.getClusterInstanceId(),
+ memberContext.getCartridgeType(),
+ MemberStatus.Terminated.toString(),timeStamp,
+ null,null,null);
// Remove member context
CloudControllerContext.getInstance().removeMemberContext(memberContext.getClusterId(), memberContext.getMemberId());
http://git-wip-us.apache.org/repos/asf/stratos/blob/2fd289b8/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/InstanceCreator.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/InstanceCreator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/InstanceCreator.java
index 77cfea2..3730a9d 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/InstanceCreator.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/InstanceCreator.java
@@ -27,8 +27,6 @@ import org.apache.stratos.cloud.controller.domain.*;
import org.apache.stratos.cloud.controller.exception.CartridgeNotFoundException;
import org.apache.stratos.cloud.controller.iaases.Iaas;
import org.apache.stratos.cloud.controller.messaging.topology.TopologyBuilder;
-import org.apache.stratos.cloud.controller.statistics.publisher.BAMUsageDataPublisher;
-import org.apache.stratos.messaging.domain.topology.MemberStatus;
import java.util.concurrent.locks.Lock;
@@ -37,114 +35,115 @@ import java.util.concurrent.locks.Lock;
*/
public class InstanceCreator implements Runnable {
- private static final Log log = LogFactory.getLog(InstanceCreator.class);
-
- private MemberContext memberContext;
- private IaasProvider iaasProvider;
- private byte[] payload;
-
- public InstanceCreator(MemberContext memberContext, IaasProvider iaasProvider, byte[] payload) {
- this.memberContext = memberContext;
- this.iaasProvider = iaasProvider;
- this.payload = payload;
- }
-
- @Override
- public void run() {
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireMemberContextWriteLock();
-
- String clusterId = memberContext.getClusterId();
- Partition partition = memberContext.getPartition();
- ClusterContext clusterContext = CloudControllerContext.getInstance().getClusterContext(clusterId);
- Iaas iaas = iaasProvider.getIaas();
-
- if (log.isDebugEnabled()) {
-
- log.debug(String.format("Payload passed to instance created, [member] %s [payload] %s",
- memberContext.getMemberId(), new String(payload)));
- }
- memberContext = startInstance(iaas, memberContext, payload);
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Instance started successfully: [cartridge-type] %s [cluster-id] %s [instance-id] %s " +
- "[default-private-ip] %s [default-public-ip] %s",
- memberContext.getCartridgeType(), memberContext.getClusterId(),
- memberContext.getInstanceId(), memberContext.getDefaultPrivateIP(),
- memberContext.getDefaultPublicIP()));
- }
-
- if (clusterContext.isVolumeRequired()) {
- attachVolumes(iaas, clusterContext, memberContext);
- }
-
- // Allocate IP addresses
- iaas.allocateIpAddresses(clusterId, memberContext, partition);
-
- // Update topology
- TopologyBuilder.handleMemberInitializedEvent(memberContext);
-
- // Publish instance creation statistics to BAM
- BAMUsageDataPublisher.publish(
- memberContext.getMemberId(),
- memberContext.getPartition().getId(),
- memberContext.getNetworkPartitionId(),
- memberContext.getClusterId(),
- memberContext.getCartridgeType(),
- MemberStatus.Initialized.toString(),
- memberContext.getInstanceMetadata());
- } catch (Exception e) {
- String message = String.format("Could not start instance: [cartridge-type] %s [cluster-id] %s",
- memberContext.getCartridgeType(), memberContext.getClusterId());
- log.error(message, e);
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- }
-
- private MemberContext startInstance(Iaas iaas, MemberContext memberContext, byte[] payload) throws CartridgeNotFoundException {
- memberContext = iaas.startInstance(memberContext, payload);
-
- // Validate instance id
- String instanceId = memberContext.getInstanceId();
- if (StringUtils.isBlank(instanceId)) {
- String msg = String.format("Instance id not found in started member: [cartridge-type] %s [member-id] %s",
- memberContext.getCartridgeType(), memberContext.getMemberId());
- log.error(msg);
- throw new IllegalStateException(msg);
- }
-
- // Update member context and persist changes
- CloudControllerContext.getInstance().updateMemberContext(memberContext);
- CloudControllerContext.getInstance().persist();
-
- if (log.isDebugEnabled()) {
- log.debug(String.format("Member context updated: [application] %s [cartridge] %s [member] %s",
- memberContext.getApplicationId(), memberContext.getCartridgeType(), memberContext.getMemberId()));
- }
-
- return memberContext;
- }
-
- public void attachVolumes(Iaas iaas, ClusterContext clusterContext, MemberContext memberContext) {
- // attach volumes
- if (clusterContext.isVolumeRequired()) {
- // remove region prefix
- if (clusterContext.getVolumes() != null) {
- for (Volume volume : clusterContext.getVolumes()) {
- try {
- iaas.attachVolume(memberContext.getInstanceId(), volume.getId(), volume.getDevice());
- } catch (Exception e) {
- // continue without throwing an exception, since
- // there is an instance already running
- log.error(String.format("Could not attach volume, [instance] %s [volume] %s ",
- memberContext.getInstanceId(), volume.toString()), e);
- }
- }
- }
- }
- }
+ private static final Log log = LogFactory.getLog(InstanceCreator.class);
+
+ private MemberContext memberContext;
+ private IaasProvider iaasProvider;
+ private byte[] payload;
+
+ public InstanceCreator(MemberContext memberContext, IaasProvider iaasProvider, byte[] payload) {
+ this.memberContext = memberContext;
+ this.iaasProvider = iaasProvider;
+ this.payload = payload;
+ }
+
+ @Override public void run() {
+ Lock lock = null;
+ try {
+ lock = CloudControllerContext.getInstance().acquireMemberContextWriteLock();
+
+ String clusterId = memberContext.getClusterId();
+ Partition partition = memberContext.getPartition();
+ ClusterContext clusterContext =
+ CloudControllerContext.getInstance().getClusterContext(clusterId);
+ Iaas iaas = iaasProvider.getIaas();
+
+ if (log.isDebugEnabled()) {
+
+ log.debug(String.format(
+ "Payload passed to instance created, [member] %s [payload] %s",
+ memberContext.getMemberId(), new String(payload)));
+ }
+ memberContext = startInstance(iaas, memberContext, payload);
+
+ if (log.isInfoEnabled()) {
+ log.info(String.format(
+ "Instance started successfully: [cartridge-type] %s [cluster-id] %s [instance-id] %s " +
+ "[default-private-ip] %s [default-public-ip] %s",
+ memberContext.getCartridgeType(), memberContext.getClusterId(),
+ memberContext.getInstanceId(), memberContext.getDefaultPrivateIP(),
+ memberContext.getDefaultPublicIP()));
+ }
+
+ if (clusterContext.isVolumeRequired()) {
+ attachVolumes(iaas, clusterContext, memberContext);
+ }
+
+ // Allocate IP addresses
+ iaas.allocateIpAddresses(clusterId, memberContext, partition);
+
+ // Update topology
+ TopologyBuilder.handleMemberInitializedEvent(memberContext);
+
+ } catch (Exception e) {
+ String message =
+ String.format("Could not start instance: [cartridge-type] %s [cluster-id] %s",
+ memberContext.getCartridgeType(), memberContext.getClusterId());
+ log.error(message, e);
+ } finally {
+ if (lock != null) {
+ CloudControllerContext.getInstance().releaseWriteLock(lock);
+ }
+ }
+ }
+
+ private MemberContext startInstance(Iaas iaas, MemberContext memberContext, byte[] payload)
+ throws CartridgeNotFoundException {
+ memberContext = iaas.startInstance(memberContext, payload);
+
+ // Validate instance id
+ String instanceId = memberContext.getInstanceId();
+ if (StringUtils.isBlank(instanceId)) {
+ String msg = String.format(
+ "Instance id not found in started member: [cartridge-type] %s [member-id] %s",
+ memberContext.getCartridgeType(), memberContext.getMemberId());
+ log.error(msg);
+ throw new IllegalStateException(msg);
+ }
+
+ // Update member context and persist changes
+ CloudControllerContext.getInstance().updateMemberContext(memberContext);
+ CloudControllerContext.getInstance().persist();
+
+ if (log.isDebugEnabled()) {
+ log.debug(String.format(
+ "Member context updated: [application] %s [cartridge] %s [member] %s",
+ memberContext.getApplicationId(), memberContext.getCartridgeType(),
+ memberContext.getMemberId()));
+ }
+
+ return memberContext;
+ }
+
+ public void attachVolumes(Iaas iaas, ClusterContext clusterContext,
+ MemberContext memberContext) {
+ // attach volumes
+ if (clusterContext.isVolumeRequired()) {
+ // remove region prefix
+ if (clusterContext.getVolumes() != null) {
+ for (Volume volume : clusterContext.getVolumes()) {
+ try {
+ iaas.attachVolume(memberContext.getInstanceId(), volume.getId(),
+ volume.getDevice());
+ } catch (Exception e) {
+ // continue without throwing an exception, since
+ // there is an instance already running
+ log.error(
+ String.format("Could not attach volume, [instance] %s [volume] %s ",
+ memberContext.getInstanceId(), volume.toString()), e);
+ }
+ }
+ }
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/2fd289b8/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/statistics/publisher/BAMUsageDataPublisher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/statistics/publisher/BAMUsageDataPublisher.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/statistics/publisher/BAMUsageDataPublisher.java
index d5aabbd..26106d7 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/statistics/publisher/BAMUsageDataPublisher.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/statistics/publisher/BAMUsageDataPublisher.java
@@ -56,8 +56,12 @@ public class BAMUsageDataPublisher {
String partitionId,
String networkId,
String clusterId,
+ String clusterInstanceId,
String serviceName,
String status,
+ Long timeStamp,
+ String autoscalingReason,
+ Long scalingTime,
InstanceMetadata metadata) {
if (!CloudControllerConfig.getInstance().isBAMDataPublisherEnabled()) {
return;
@@ -75,20 +79,24 @@ public class BAMUsageDataPublisher {
return;
}
}
-
MemberContext memberContext = CloudControllerContext.getInstance().getMemberContextOfMemberId(memberId);
String cartridgeType = memberContext.getCartridgeType();
Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType);
-
+ String instanceType = CloudControllerContext.getInstance().getIaasProviderOfPartition(cartridgeType, partitionId).getProperty(CloudControllerConstants.INSTANCE_TYPE);
//Construct the data to be published
List<Object> payload = new ArrayList<Object>();
// Payload values
+ payload.add(timeStamp);
payload.add(memberId);
payload.add(serviceName);
payload.add(clusterId);
+ payload.add(clusterInstanceId);
payload.add(handleNull(memberContext.getLbClusterId()));
payload.add(handleNull(partitionId));
payload.add(handleNull(networkId));
+ payload.add(handleNull(instanceType));
+ payload.add(handleNull(autoscalingReason));
+ payload.add(handleNull(scalingTime));
if (cartridge != null) {
payload.add(handleNull(String.valueOf(cartridge.isMultiTenant())));
} else {
@@ -151,12 +159,17 @@ public class BAMUsageDataPublisher {
streamDefinition.setDescription("Instances booted up by the Cloud Controller");
// Payload definition
List<Attribute> payloadData = new ArrayList<Attribute>();
+ payloadData.add(new Attribute(CloudControllerConstants.TIME_STAMP, AttributeType.LONG));
payloadData.add(new Attribute(CloudControllerConstants.MEMBER_ID_COL, AttributeType.STRING));
payloadData.add(new Attribute(CloudControllerConstants.CARTRIDGE_TYPE_COL, AttributeType.STRING));
payloadData.add(new Attribute(CloudControllerConstants.CLUSTER_ID_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.CLUSTER_INSTANCE_ID_COL, AttributeType.STRING));
payloadData.add(new Attribute(CloudControllerConstants.LB_CLUSTER_ID_COL, AttributeType.STRING));
payloadData.add(new Attribute(CloudControllerConstants.PARTITION_ID_COL, AttributeType.STRING));
payloadData.add(new Attribute(CloudControllerConstants.NETWORK_ID_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.INSTANCE_TYPE, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.SCALING_REASON, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.SCALING_TIME, AttributeType.LONG));
payloadData.add(new Attribute(CloudControllerConstants.IS_MULTI_TENANT_COL, AttributeType.STRING));
payloadData.add(new Attribute(CloudControllerConstants.IAAS_COL, AttributeType.STRING));
payloadData.add(new Attribute(CloudControllerConstants.STATUS_COL, AttributeType.STRING));
@@ -198,7 +211,7 @@ public class BAMUsageDataPublisher {
dataPublisher.addStreamDefinition(streamDefinition);
} catch (Exception e) {
String msg = "Unable to create a data publisher to " + bamServerUrl +
- ". Usage Agent will not function properly. ";
+ ". Usage Agent will not function properly. ";
log.error(msg, e);
throw new CloudControllerException(msg, e);
}
@@ -210,4 +223,11 @@ public class BAMUsageDataPublisher {
}
return val;
}
+
+ private static Long handleNull(Long val) {
+ if (val == null) {
+ return -1L;
+ }
+ return val;
+ }
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/2fd289b8/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
index 5e6115f..5730475 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
@@ -103,6 +103,7 @@ public final class CloudControllerConstants {
public static final String MEMBER_ID_COL = "memberId";
public static final String CARTRIDGE_TYPE_COL = "cartridgeType";
public static final String CLUSTER_ID_COL = "clusterId";
+ public static final String CLUSTER_INSTANCE_ID_COL = "clusterInstanceId";
public static final String PARTITION_ID_COL = "partitionId";
public static final String NETWORK_ID_COL = "networkId";
public static final String ALIAS_COL = "alias";
@@ -122,6 +123,9 @@ public final class CloudControllerConstants {
public static final String PRIV_IP_COL = "privateIPAddresses";
public static final String PUB_IP_COL = "publicIPAddresses";
public static final String ALLOCATE_IP_COL = "allocateIPAddresses";
+ public static final String TIME_STAMP = "timeStamp";
+ public static final String SCALING_REASON = "scalingReason";
+ public static final String SCALING_TIME = "scalingTime";
/**
* Properties
@@ -148,59 +152,59 @@ public final class CloudControllerConstants {
* XPath expressions
*/
public static final String IAAS_PROVIDER_XPATH = "/"
- + CLOUD_CONTROLLER_ELEMENT + "/" + IAAS_PROVIDERS_ELEMENT + "/"
- + IAAS_PROVIDER_ELEMENT;
+ + CLOUD_CONTROLLER_ELEMENT + "/" + IAAS_PROVIDERS_ELEMENT + "/"
+ + IAAS_PROVIDER_ELEMENT;
public static final String PARTITION_XPATH = "/" + CLOUD_CONTROLLER_ELEMENT
- + "/" + PARTITIONS_ELEMENT + "/" + PARTITION_ELEMENT;
+ + "/" + PARTITIONS_ELEMENT + "/" + PARTITION_ELEMENT;
public static final String REGION_XPATH = "/" + CLOUD_CONTROLLER_ELEMENT
- + "/" + IAAS_PROVIDERS_ELEMENT + "/" + IAAS_PROVIDER_ELEMENT + "/"
- + REGION_ELEMENT;
+ + "/" + IAAS_PROVIDERS_ELEMENT + "/" + IAAS_PROVIDER_ELEMENT + "/"
+ + REGION_ELEMENT;
public static final String ZONE_XPATH = "/" + CLOUD_CONTROLLER_ELEMENT
- + "/" + IAAS_PROVIDERS_ELEMENT + "/" + IAAS_PROVIDER_ELEMENT + "/"
- + REGION_ELEMENT + "/" + ZONE_ELEMENT;
+ + "/" + IAAS_PROVIDERS_ELEMENT + "/" + IAAS_PROVIDER_ELEMENT + "/"
+ + REGION_ELEMENT + "/" + ZONE_ELEMENT;
public static final String HOST_XPATH = "/" + CLOUD_CONTROLLER_ELEMENT
- + "/" + IAAS_PROVIDERS_ELEMENT + "/" + IAAS_PROVIDER_ELEMENT + "/"
- + REGION_ELEMENT + "/" + ZONE_ELEMENT + "/" + HOST_ELEMENT;
+ + "/" + IAAS_PROVIDERS_ELEMENT + "/" + IAAS_PROVIDER_ELEMENT + "/"
+ + REGION_ELEMENT + "/" + ZONE_ELEMENT + "/" + HOST_ELEMENT;
public static final String PROPERTY_ELEMENT_XPATH = "/" + PROPERTY_ELEMENT;
public static final String IMAGE_ID_ELEMENT_XPATH = "/" + IMAGE_ID_ELEMENT;
public static final String SCALE_UP_ORDER_ELEMENT_XPATH = "/"
- + SCALE_UP_ORDER_ELEMENT;
+ + SCALE_UP_ORDER_ELEMENT;
public static final String SCALE_DOWN_ORDER_ELEMENT_XPATH = "/"
- + SCALE_DOWN_ORDER_ELEMENT;
+ + SCALE_DOWN_ORDER_ELEMENT;
public static final String PROVIDER_ELEMENT_XPATH = "/" + PROPERTY_ELEMENT;
public static final String IDENTITY_ELEMENT_XPATH = "/" + IDENTITY_ELEMENT;
public static final String CREDENTIAL_ELEMENT_XPATH = "/"
- + CREDENTIAL_ELEMENT;
+ + CREDENTIAL_ELEMENT;
public static final String SERVICES_ELEMENT_XPATH = "/" + SERVICES_ELEMENT
- + "/" + SERVICE_ELEMENT;
+ + "/" + SERVICE_ELEMENT;
public static final String SERVICE_ELEMENT_XPATH = "/" + SERVICE_ELEMENT;
public static final String CARTRIDGE_ELEMENT_XPATH = "/"
- + CARTRIDGE_ELEMENT;
+ + CARTRIDGE_ELEMENT;
public static final String PAYLOAD_ELEMENT_XPATH = "/" + PAYLOAD_ELEMENT;
public static final String HOST_ELEMENT_XPATH = "/" + HOST_ELEMENT;
public static final String CARTRIDGES_ELEMENT_XPATH = "/"
- + CARTRIDGES_ELEMENT + "/" + CARTRIDGE_ELEMENT;
+ + CARTRIDGES_ELEMENT + "/" + CARTRIDGE_ELEMENT;
public static final String IAAS_PROVIDER_ELEMENT_XPATH = "/"
- + IAAS_PROVIDER_ELEMENT;
+ + IAAS_PROVIDER_ELEMENT;
public static final String DEPLOYMENT_ELEMENT_XPATH = "/"
- + DEPLOYMENT_ELEMENT;
+ + DEPLOYMENT_ELEMENT;
public static final String PORT_MAPPING_ELEMENT_XPATH = "/"
- + PORT_MAPPING_ELEMENT;
+ + PORT_MAPPING_ELEMENT;
public static final String APP_TYPES_ELEMENT_XPATH = "/"
- + APP_TYPES_ELEMENT;
+ + APP_TYPES_ELEMENT;
public static final String DATA_PUBLISHER_XPATH = "/"
- + CLOUD_CONTROLLER_ELEMENT + "/" + DATA_PUBLISHER_ELEMENT;
+ + CLOUD_CONTROLLER_ELEMENT + "/" + DATA_PUBLISHER_ELEMENT;
public static final String TOPOLOGY_SYNC_XPATH = "/"
- + CLOUD_CONTROLLER_ELEMENT + "/" + TOPOLOGY_SYNC_ELEMENT;
+ + CLOUD_CONTROLLER_ELEMENT + "/" + TOPOLOGY_SYNC_ELEMENT;
public static final String DATA_PUBLISHER_CRON_XPATH = "/"
- + CLOUD_CONTROLLER_ELEMENT + "/" + CRON_ELEMENT;
+ + CLOUD_CONTROLLER_ELEMENT + "/" + CRON_ELEMENT;
public static final String BAM_SERVER_ADMIN_USERNAME_XPATH = "/"
- + CLOUD_CONTROLLER_ELEMENT + "/"
- + BAM_SERVER_ADMIN_USERNAME_ELEMENT;
+ + CLOUD_CONTROLLER_ELEMENT + "/"
+ + BAM_SERVER_ADMIN_USERNAME_ELEMENT;
public static final String BAM_SERVER_ADMIN_PASSWORD_XPATH = "/"
- + CLOUD_CONTROLLER_ELEMENT + "/"
- + BAM_SERVER_ADMIN_PASSWORD_ELEMENT;
+ + CLOUD_CONTROLLER_ELEMENT + "/"
+ + BAM_SERVER_ADMIN_PASSWORD_ELEMENT;
// public static final String CASSANDRA_HOST_ADDRESS_XPATH =
// "/"+CLOUD_CONTROLLER_ELEMENT+
// "/"+CASSANDRA_HOST_ADDRESS;
@@ -240,15 +244,15 @@ public final class CloudControllerConstants {
* Directories
*/
public static final String SERVICES_DIR = CarbonUtils.getCarbonRepository()
- + File.separator + "services" + File.separator;
+ + File.separator + "services" + File.separator;
/**
* Topology sync related constants
*/
public static final String TOPOLOGY_FILE_PATH = CarbonUtils
- .getCarbonConfigDirPath()
- + File.separator
- + "service-topology.conf";
+ .getCarbonConfigDirPath()
+ + File.separator
+ + "service-topology.conf";
public static final String TOPOLOGY_SYNC_CRON = "1 * * * * ? *";
public static final String TOPOLOGY_SYNC_TASK_NAME = "TOPOLOGY_SYNC_TASK";
public static final String TOPOLOGY_SYNC_TASK_TYPE = "TOPOLOGY_SYNC_TASK_TYPE";
[15/18] stratos git commit: Formatting the code
Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/218b5fdc/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
index 6518607..d7a5916 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
@@ -55,1585 +55,1616 @@ import java.util.concurrent.locks.Lock;
*/
public class CloudControllerServiceImpl implements CloudControllerService {
- private static final Log log = LogFactory.getLog(CloudControllerServiceImpl.class);
-
- private static final String PERSISTENCE_MAPPING = "PERSISTENCE_MAPPING";
- public static final String PAYLOAD_PARAMETER = "payload_parameter.";
-
- private CloudControllerContext cloudControllerContext = CloudControllerContext.getInstance();
- private ExecutorService executorService;
-
- public CloudControllerServiceImpl() {
- executorService = StratosThreadPool.getExecutorService("cloud.controller.instance.manager.thread.pool", 50);
-
- }
-
- public boolean addCartridge(Cartridge cartridgeConfig)
- throws InvalidCartridgeDefinitionException, InvalidIaasProviderException, CartridgeAlreadyExistsException {
-
- handleNullObject(cartridgeConfig, "Cartridge definition is null");
-
- if (log.isInfoEnabled()) {
- log.info("Adding cartridge: [cartridge-type] " + cartridgeConfig.getType());
- }
- if (log.isDebugEnabled()) {
- log.debug("Cartridge definition: " + cartridgeConfig.toString());
- }
-
- try {
- CloudControllerUtil.extractIaaSProvidersFromCartridge(cartridgeConfig);
- } catch (Exception e) {
- String message = "Invalid cartridge definition: [cartridge-type] " + cartridgeConfig.getType();
- log.error(message, e);
- throw new InvalidCartridgeDefinitionException(message, e);
- }
-
- String cartridgeType = cartridgeConfig.getType();
- if (cloudControllerContext.getCartridge(cartridgeType) != null) {
- String message = "Cartridge already exists: [cartridge-type] " + cartridgeType;
- log.error(message);
- throw new CartridgeAlreadyExistsException(message);
- }
-
- // Add cartridge to the cloud controller context and persist
- CloudControllerContext.getInstance().addCartridge(cartridgeConfig);
- CloudControllerContext.getInstance().persist();
-
- List<Cartridge> cartridgeList = new ArrayList<Cartridge>();
- cartridgeList.add(cartridgeConfig);
-
- TopologyBuilder.handleServiceCreated(cartridgeList);
-
- if (log.isInfoEnabled()) {
- log.info("Successfully added cartridge: [cartridge-type] " + cartridgeType);
- }
- return true;
- }
-
- @Override public boolean updateCartridge(Cartridge cartridge)
- throws InvalidCartridgeDefinitionException, InvalidIaasProviderException,
- CartridgeDefinitionNotExistsException {
-
- handleNullObject(cartridge, "Cartridge definition is null");
-
- if (log.isInfoEnabled()) {
- log.info("Updating cartridge: [cartridge-type] " + cartridge.getType());
- }
- if (log.isDebugEnabled()) {
- log.debug("Cartridge definition: " + cartridge.toString());
- }
-
- try {
- CloudControllerUtil.extractIaaSProvidersFromCartridge(cartridge);
- } catch (Exception e) {
- String msg = "Invalid cartridge definition: [cartridge-type] " + cartridge.getType();
- log.error(msg, e);
- throw new InvalidCartridgeDefinitionException(msg, e);
- }
-
- String cartridgeType = cartridge.getType();
- if (cloudControllerContext.getCartridge(cartridgeType) != null) {
- Cartridge cartridgeToBeRemoved = cloudControllerContext.getCartridge(cartridgeType);
- try {
- removeCartridgeFromCC(cartridgeToBeRemoved.getType());
- } catch (InvalidCartridgeTypeException ignore) {
- }
- copyIaasProviders(cartridge, cartridgeToBeRemoved);
- } else {
- throw new CartridgeDefinitionNotExistsException("This cartridge definition not exists");
- }
-
- // Add cartridge to the cloud controller context and persist
- CloudControllerContext.getInstance().addCartridge(cartridge);
- CloudControllerContext.getInstance().persist();
- // transaction ends
-
- if (log.isInfoEnabled()) {
- log.info("Successfully updated cartridge: [cartridge-type] " + cartridgeType);
- }
- return true;
- }
-
- private void copyIaasProviders(Cartridge destCartridge, Cartridge sourceCartridge) {
-
- List<IaasProvider> newIaasProviders =
- CloudControllerContext.getInstance().getIaasProviders(destCartridge.getType());
-
- Map<String, IaasProvider> iaasProviderMap =
- CloudControllerContext.getInstance().getPartitionToIaasProvider(sourceCartridge.getType());
-
- if (iaasProviderMap != null) {
- for (Entry<String, IaasProvider> entry : iaasProviderMap.entrySet()) {
- if (entry == null) {
- continue;
- }
- String partitionId = entry.getKey();
- IaasProvider iaasProvider = entry.getValue();
- if (newIaasProviders.contains(iaasProvider)) {
- if (log.isDebugEnabled()) {
- log.debug("Copying partition from the cartridge that is undeployed, to the new cartridge: " +
- "[partition-id] " + partitionId + " [cartridge-type] " + destCartridge.getType());
- }
- CloudControllerContext.getInstance().addIaasProvider(destCartridge.getType(), partitionId,
- newIaasProviders.get(newIaasProviders.indexOf(
- iaasProvider)));
- }
- }
- }
-
- }
-
- public boolean removeCartridge(String cartridgeType) throws InvalidCartridgeTypeException {
- //Removing the cartridge from CC
- Cartridge cartridge = removeCartridgeFromCC(cartridgeType);
- //removing the cartridge from Topology
- removeCartridgeFromTopology(cartridge);
-
- if (log.isInfoEnabled()) {
- log.info("Successfully removed cartridge: [cartridge-type] " + cartridgeType);
- }
- return true;
- }
-
- private Cartridge removeCartridgeFromCC(String cartridgeType) throws InvalidCartridgeTypeException {
- Cartridge cartridge = null;
- if ((cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType)) != null) {
- if (CloudControllerContext.getInstance().getCartridges().remove(cartridge)) {
- // invalidate partition validation cache
- CloudControllerContext.getInstance().removeFromCartridgeTypeToPartitionIds(cartridgeType);
-
- if (log.isDebugEnabled()) {
- log.debug("Partition cache invalidated for cartridge " + cartridgeType);
- }
-
- CloudControllerContext.getInstance().persist();
-
- if (log.isInfoEnabled()) {
- log.info("Successfully removed cartridge: [cartridge-type] " + cartridgeType);
- }
- return cartridge;
- }
- }
- String msg = "Cartridge not found: [cartridge-type] " + cartridgeType;
- log.error(msg);
- throw new InvalidCartridgeTypeException(msg);
- }
-
- private void removeCartridgeFromTopology(Cartridge cartridge) throws InvalidCartridgeTypeException {
- // sends the service removed event
- List<Cartridge> cartridgeList = new ArrayList<Cartridge>();
- cartridgeList.add(cartridge);
- TopologyBuilder.handleServiceRemoved(cartridgeList);
- }
-
- public boolean addServiceGroup(ServiceGroup servicegroup) throws InvalidServiceGroupException {
-
- if (servicegroup == null) {
- String msg = "Invalid ServiceGroup Definition: Definition is null.";
- log.error(msg);
- throw new IllegalArgumentException(msg);
-
- }
- CloudControllerContext.getInstance().addServiceGroup(servicegroup);
- CloudControllerContext.getInstance().persist();
- return true;
- }
-
- public boolean removeServiceGroup(String name) throws InvalidServiceGroupException {
- if (log.isDebugEnabled()) {
- log.debug("CloudControllerServiceImpl:removeServiceGroup: " + name);
- }
-
- ServiceGroup serviceGroup = null;
-
- serviceGroup = CloudControllerContext.getInstance().getServiceGroup(name);
-
- if (serviceGroup != null) {
- if (CloudControllerContext.getInstance().getServiceGroups().remove(serviceGroup)) {
- CloudControllerContext.getInstance().persist();
- if (log.isInfoEnabled()) {
- log.info("Successfully removed the cartridge group: [group-name] " + serviceGroup);
- }
- return true;
- }
- }
-
- String msg = "Cartridge group not found: [group-name] " + name;
- log.error(msg);
- throw new InvalidServiceGroupException(msg);
-
- }
-
- @Override public ServiceGroup getServiceGroup(String name) throws InvalidServiceGroupException {
-
- if (log.isDebugEnabled()) {
- log.debug("getServiceGroupDefinition:" + name);
- }
-
- ServiceGroup serviceGroup = CloudControllerContext.getInstance().getServiceGroup(name);
-
- if (serviceGroup == null) {
- String message = "Cartridge group not found: [group-name] " + name;
- if (log.isDebugEnabled()) {
- log.debug(message);
- }
- throw new InvalidServiceGroupException(message);
- }
-
- return serviceGroup;
- }
-
- public String[] getServiceGroupSubGroups(String name) throws InvalidServiceGroupException {
- ServiceGroup serviceGroup = this.getServiceGroup(name);
- if (serviceGroup == null) {
- throw new InvalidServiceGroupException("Invalid cartridge group: [group-name] " + serviceGroup);
- }
-
- return serviceGroup.getSubGroups();
- }
-
- /**
- *
- */
- public String[] getServiceGroupCartridges(String name) throws InvalidServiceGroupException {
- ServiceGroup serviceGroup = this.getServiceGroup(name);
- if (serviceGroup == null) {
- throw new InvalidServiceGroupException("Invalid cartridge group: [group-name] " + serviceGroup);
- }
- String[] cs = serviceGroup.getCartridges();
- return cs;
-
- }
-
- public Dependencies getServiceGroupDependencies(String name) throws InvalidServiceGroupException {
- ServiceGroup serviceGroup = this.getServiceGroup(name);
- if (serviceGroup == null) {
- throw new InvalidServiceGroupException("Invalid cartridge group: [group-name] " + serviceGroup);
- }
- return serviceGroup.getDependencies();
- }
-
- @Override public MemberContext[] startInstances(InstanceContext[] instanceContexts)
- throws CartridgeNotFoundException, InvalidIaasProviderException, CloudControllerException {
-
- handleNullObject(instanceContexts, "Instance start-up failed, member contexts is null");
-
- List<MemberContext> memberContextList = new ArrayList<MemberContext>();
- for (InstanceContext instanceContext : instanceContexts) {
- if (instanceContext != null) {
- MemberContext memberContext = startInstance(instanceContext);
- memberContextList.add(memberContext);
- }
- }
- MemberContext[] memberContextsArray = memberContextList.toArray(new MemberContext[memberContextList.size()]);
- return memberContextsArray;
- }
-
- public MemberContext startInstance(InstanceContext instanceContext)
- throws CartridgeNotFoundException, InvalidIaasProviderException, CloudControllerException {
-
- try {
- // Validate instance context
- handleNullObject(instanceContext, "Could not start instance, instance context is null");
- if (log.isDebugEnabled()) {
- log.debug("Starting up instance: " + instanceContext);
- }
-
- // Validate partition
- Partition partition = instanceContext.getPartition();
- handleNullObject(partition, "Could not start instance, partition is null");
-
- // Validate cluster
- String partitionId = partition.getId();
- String clusterId = instanceContext.getClusterId();
- ClusterContext clusterContext = CloudControllerContext.getInstance().getClusterContext(clusterId);
- handleNullObject(clusterContext,
- "Could not start instance, cluster context not found: [cluster-id] " + clusterId);
-
- // Validate cartridge
- String cartridgeType = clusterContext.getCartridgeType();
- Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType);
- if (cartridge == null) {
- String msg = "Could not startup instance, cartridge not found: [cartridge-type] " + cartridgeType;
- log.error(msg);
- throw new CartridgeNotFoundException(msg);
- }
-
- // Validate iaas provider
- IaasProvider iaasProvider =
- CloudControllerContext.getInstance().getIaasProviderOfPartition(cartridge.getType(), partitionId);
- if (iaasProvider == null) {
- String msg = String.format("Could not start instance, " +
- "IaaS provider not found in cartridge %s for partition %s, " +
- "partitions found: %s ", cartridgeType, partitionId,
- CloudControllerContext.getInstance()
- .getPartitionToIaasProvider(cartridge.getType())
- .keySet().toString());
- log.error(msg);
- throw new InvalidIaasProviderException(msg);
- }
-
- // Generate member ID
- String memberId = generateMemberId(clusterId);
-
- // Create member context
- String applicationId = clusterContext.getApplicationId();
- MemberContext memberContext = createMemberContext(applicationId, cartridgeType, memberId,
- CloudControllerUtil.getLoadBalancingIPTypeEnumFromString(
- cartridge.getLoadBalancingIPType()),
- instanceContext);
-
- // Prepare payload
- StringBuilder payload = new StringBuilder(clusterContext.getPayload());
- addToPayload(payload, "MEMBER_ID", memberId);
- addToPayload(payload, "INSTANCE_ID", memberContext.getInstanceId());
- addToPayload(payload, "CLUSTER_INSTANCE_ID", memberContext.getClusterInstanceId());
- addToPayload(payload, "LB_CLUSTER_ID", memberContext.getLbClusterId());
- addToPayload(payload, "NETWORK_PARTITION_ID", memberContext.getNetworkPartitionId());
- addToPayload(payload, "PARTITION_ID", partitionId);
- addToPayload(payload, "INTERNAL", "false");
-
- if (memberContext.getProperties() != null) {
- org.apache.stratos.common.Properties properties = memberContext.getProperties();
- if (properties != null) {
- for (Property prop : properties.getProperties()) {
- addToPayload(payload, prop.getName(), String.valueOf(prop.getValue()));
- }
- }
- }
-
- NetworkPartition networkPartition =
- CloudControllerContext.getInstance().getNetworkPartition(memberContext.getNetworkPartitionId());
-
- if (networkPartition.getProperties() != null) {
- if (networkPartition.getProperties().getProperties() != null) {
- for (Property property : networkPartition.getProperties().getProperties()) {
- // check if a property is related to the payload. Currently
- // this is done by checking if the
- // property name starts with 'payload_parameter.' suffix. If
- // so the payload param name will
- // be taken as the substring from the index of '.' to the
- // end of the property name.
- if (property.getName().startsWith(PAYLOAD_PARAMETER)) {
- String propertyName = property.getName();
- String payloadParamName = propertyName.substring(propertyName.indexOf(".") + 1);
- if (payload.toString().contains(payloadParamName)) {
- replaceInPayload(payloadParamName, payload, payloadParamName, property.getValue());
- } else {
- addToPayload(payload, payloadParamName, property.getValue());
- }
- }
- }
- }
- }
-
- Iaas iaas = iaasProvider.getIaas();
- if (clusterContext.isVolumeRequired()) {
- addToPayload(payload, PERSISTENCE_MAPPING, getPersistencePayload(clusterContext, iaas).toString());
- }
-
- if (log.isDebugEnabled()) {
- log.debug("Payload: " + payload.toString());
- }
-
- if (clusterContext.isVolumeRequired()) {
-
- Volume[] volumes = clusterContext.getVolumes();
- if (volumes != null) {
- for (int i = 0; i < volumes.length; i++) {
-
- if (volumes[i].getId() == null) {
- // Create a new volume
- volumes[i] = createVolumeAndSetInClusterContext(volumes[i], iaasProvider);
- }
- }
- }
- clusterContext.setVolumes(volumes);
- }
-
- // Persist member context
- CloudControllerContext.getInstance().addMemberContext(memberContext);
- CloudControllerContext.getInstance().persist();
-
- // Handle member created event
- TopologyBuilder.handleMemberCreatedEvent(memberContext);
-
- // Start instance in a new thread
- if (log.isDebugEnabled()) {
- log.debug(String.format("Starting instance creator thread: [cluster] %s [cluster-instance] %s " +
- "[member] %s [application-id] %s", instanceContext.getClusterId(),
- instanceContext.getClusterInstanceId(), memberId, applicationId));
- }
- executorService.execute(new InstanceCreator(memberContext, iaasProvider, payload.toString().getBytes()));
-
- return memberContext;
- } catch (Exception e) {
- String msg = String.format("Could not start instance: [cluster] %s [cluster-instance] %s",
- instanceContext.getClusterId(), instanceContext.getClusterInstanceId());
- log.error(msg, e);
- throw new CloudControllerException(msg, e);
- }
- }
-
- private MemberContext createMemberContext(String applicationId, String cartridgeType, String memberId,
- LoadBalancingIPType loadBalancingIPType,
- InstanceContext instanceContext) {
- MemberContext memberContext =
- new MemberContext(applicationId, cartridgeType, instanceContext.getClusterId(), memberId);
-
- memberContext.setClusterInstanceId(instanceContext.getClusterInstanceId());
- memberContext.setNetworkPartitionId(instanceContext.getNetworkPartitionId());
- memberContext.setPartition(cloudControllerContext.getNetworkPartition(instanceContext.getNetworkPartitionId()).
- getPartition(instanceContext.getPartition().getId()));
- memberContext.setInitTime(instanceContext.getInitTime());
- memberContext.setProperties(instanceContext.getProperties());
- memberContext.setLoadBalancingIPType(loadBalancingIPType);
- memberContext.setInitTime(System.currentTimeMillis());
- memberContext.setObsoleteExpiryTime(instanceContext.getObsoleteExpiryTime());
-
- return memberContext;
- }
-
- private Volume createVolumeAndSetInClusterContext(Volume volume, IaasProvider iaasProvider) {
- // iaas cannot be null at this state #startInstance method
- Iaas iaas = iaasProvider.getIaas();
- int sizeGB = volume.getSize();
- String snapshotId = volume.getSnapshotId();
- if (StringUtils.isNotEmpty(volume.getVolumeId())) {
- // volumeID is specified, so not creating additional volumes
- if (log.isDebugEnabled()) {
- log.debug("Volume creation is skipping since a volume ID is specified. [Volume ID] " +
- volume.getVolumeId());
- }
- volume.setId(volume.getVolumeId());
- } else {
- String volumeId = iaas.createVolume(sizeGB, snapshotId);
- volume.setId(volumeId);
- }
-
- volume.setIaasType(iaasProvider.getType());
-
- return volume;
- }
-
- private StringBuilder getPersistencePayload(ClusterContext ctx, Iaas iaas) {
- StringBuilder persistencePayload = new StringBuilder();
- if (isPersistenceMappingAvailable(ctx)) {
- for (Volume volume : ctx.getVolumes()) {
- if (log.isDebugEnabled()) {
- log.debug("Adding persistence mapping " + volume.toString());
- }
- if (persistencePayload.length() != 0) {
- persistencePayload.append("|");
- }
-
- persistencePayload.append(iaas.getIaasDevice(volume.getDevice()));
- persistencePayload.append("|");
- persistencePayload.append(volume.getId());
- persistencePayload.append("|");
- persistencePayload.append(volume.getMappingPath());
- }
- }
- if (log.isDebugEnabled()) {
- log.debug("Persistence payload: " + persistencePayload.toString());
- }
- return persistencePayload;
- }
-
- private boolean isPersistenceMappingAvailable(ClusterContext ctx) {
- return ctx.getVolumes() != null && ctx.isVolumeRequired();
- }
-
- private void addToPayload(StringBuilder payload, String name, String value) {
- payload.append(",");
- payload.append(name + "=" + value);
- }
-
- private void replaceInPayload(String payloadParamName, StringBuilder payload, String name, String value) {
-
- payload.replace(payload.indexOf(payloadParamName), payload.indexOf(",", payload.indexOf(payloadParamName)),
- "," + name + "=" + value);
- }
-
- private String generateMemberId(String clusterId) {
- UUID memberId = UUID.randomUUID();
- return clusterId + memberId.toString();
- }
-
- public boolean terminateInstanceForcefully(String memberId) {
-
- log.info(String.format("Starting to forcefully terminate the member " + memberId));
- boolean memberTerminated = true;
- try {
- this.terminateInstance(memberId);
- } catch (InvalidMemberException e) {
- memberTerminated = false;
- } catch (CloudControllerException e) {
- memberTerminated = false;
- } catch (InvalidCartridgeTypeException e) {
- memberTerminated = false;
- }
-
- if (memberTerminated) {
- log.info(String.format("Member terminated [member-id] %s ", memberId));
- } else {
- log.warn(String.format("Stratos could not terminate the member [member-id] %s. This may due to a issue " +
- "in the underlying IaaS, Please terminate the member manually if it is available",
- memberId));
- MemberContext memberContext = CloudControllerContext.getInstance().getMemberContextOfMemberId(memberId);
- CloudControllerServiceUtil.executeMemberTerminationPostProcess(memberContext);
- }
- return true;
- }
-
- @Override public boolean terminateInstance(String memberId)
- throws InvalidMemberException, InvalidCartridgeTypeException, CloudControllerException {
-
- try {
- handleNullObject(memberId, "Could not terminate instance, member id is null.");
-
- MemberContext memberContext = CloudControllerContext.getInstance().getMemberContextOfMemberId(memberId);
- if (memberContext == null) {
- String msg = "Could not terminate instance, member context not found: [member-id] " + memberId;
- log.error(msg);
- throw new InvalidMemberException(msg);
- }
-
- if (StringUtils.isBlank(memberContext.getInstanceId())) {
- if (log.isErrorEnabled()) {
- log.error(String.format("Could not terminate instance, instance id is blank: [member-id] %s " +
- ", removing member from topology...", memberContext.getMemberId()));
- }
- CloudControllerServiceUtil.executeMemberTerminationPostProcess(memberContext);
- }
-
- // check if status == active, if true, then this is a termination on member faulty
- TopologyManager.acquireWriteLock();
- Topology topology = TopologyManager.getTopology();
- org.apache.stratos.messaging.domain.topology.Service service =
- topology.getService(memberContext.getCartridgeType());
-
- if (service != null) {
- Cluster cluster = service.getCluster(memberContext.getClusterId());
- if (cluster != null) {
- Member member = cluster.getMember(memberId);
- if (member != null) {
-
- // check if ready to shutdown member is expired and send
- // member terminated if it is.
- if (isMemberExpired(member, memberContext.getObsoleteInitTime(),
- memberContext.getObsoleteExpiryTime())) {
- if (log.isInfoEnabled()) {
- log.info(String.format(
- "Member pending termination in ReadyToShutdown state exceeded expiry time. " +
- "This member has to be manually deleted: %s", memberContext.getMemberId()));
- }
-
- CloudControllerServiceUtil.executeMemberTerminationPostProcess(memberContext);
- return false;
- }
- }
- }
- }
-
- executorService.execute(new InstanceTerminator(memberContext));
- } catch (InvalidMemberException e) {
- String message = "Could not terminate instance: [member-id] " + memberId;
- log.error(message, e);
- throw e;
- } catch (Exception e) {
- String message = "Could not terminate instance: [member-id] " + memberId;
- log.error(message, e);
- throw new CloudControllerException(message, e);
- } finally {
- TopologyManager.releaseWriteLock();
- }
- return true;
- }
-
- /**
- * Check if a member has been in the ReadyToShutdown status for a specified expiry time
- *
- * @param member
- * @param initTime
- * @param expiryTime
- * @return
- */
- private boolean isMemberExpired(Member member, long initTime, long expiryTime) {
- if (member.getStatus() == MemberStatus.ReadyToShutDown) {
- if (initTime == 0) {
- // obsolete init time hasn't been set, i.e. not a member detected faulty.
- // this is a graceful shutdown
- return false;
- }
-
- // member detected faulty, calculate ready to shutdown waiting period
- long timeInReadyToShutdownStatus = System.currentTimeMillis() - initTime;
- return timeInReadyToShutdownStatus >= expiryTime;
- }
-
- return false;
- }
-
- @Override public boolean terminateInstances(String clusterId) throws InvalidClusterException {
-
- log.info("Starting to terminate all instances of cluster : " + clusterId);
-
- handleNullObject(clusterId, "Instance termination failed. Cluster id is null.");
-
- List<MemberContext> memberContexts =
- CloudControllerContext.getInstance().getMemberContextsOfClusterId(clusterId);
- if (memberContexts == null) {
- String msg = "Instance termination failed. No members found for cluster id: " + clusterId;
- log.warn(msg);
- return false;
- }
-
- for (MemberContext memberContext : memberContexts) {
- executorService.execute(new InstanceTerminator(memberContext));
- }
- return true;
- }
-
- @Override public boolean registerService(Registrant registrant) throws CartridgeNotFoundException {
-
- String cartridgeType = registrant.getCartridgeType();
- handleNullObject(cartridgeType, "Service registration failed, cartridge Type is null.");
-
- String clusterId = registrant.getClusterId();
- handleNullObject(clusterId, "Service registration failed, cluster id is null.");
-
- String payload = registrant.getPayload();
- handleNullObject(payload, "Service registration failed, payload is null.");
-
- String hostName = registrant.getHostName();
- handleNullObject(hostName, "Service registration failed, hostname is null.");
-
- Cartridge cartridge = null;
- if ((cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType)) == null) {
- String msg = "Registration of cluster: " + clusterId +
- " failed, cartridge not found: [cartridge-type] " + cartridgeType;
- log.error(msg);
- throw new CartridgeNotFoundException(msg);
- }
-
- CloudControllerContext.getInstance().persist();
-
- log.info("Successfully registered service: " + registrant);
- return true;
- }
-
- @Override public String[] getCartridges() {
- // get the list of cartridges registered
- Collection<Cartridge> cartridges = CloudControllerContext.getInstance().getCartridges();
-
- if (cartridges == null) {
- log.info("No registered Cartridge found.");
- return new String[0];
- }
-
- String[] cartridgeTypes = new String[cartridges.size()];
- int i = 0;
-
- if (log.isDebugEnabled()) {
- log.debug("Registered Cartridges : \n");
- }
- for (Cartridge cartridge : cartridges) {
- if (log.isDebugEnabled()) {
- log.debug(cartridge);
- }
- cartridgeTypes[i] = cartridge.getType();
- i++;
- }
-
- return cartridgeTypes;
- }
-
- @Override public Cartridge getCartridge(String cartridgeType) throws CartridgeNotFoundException {
- Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType);
- if (cartridge != null) {
- return cartridge;
- }
-
- String msg = "Could not find cartridge: [cartridge-type] " + cartridgeType;
- throw new CartridgeNotFoundException(msg);
- }
-
- @Override public boolean unregisterService(String clusterId) throws UnregisteredClusterException {
- final String clusterId_ = clusterId;
-
- ClusterContext ctxt = CloudControllerContext.getInstance().getClusterContext(clusterId_);
- handleNullObject(ctxt, "Service unregistration failed. Invalid cluster id: " + clusterId);
-
- final String cartridgeType = ctxt.getCartridgeType();
- Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType);
-
- if (cartridge == null) {
- String msg = String.format(
- "Service unregistration failed. No matching cartridge found: [cartridge-type] %s " +
- "[application-id] %s", cartridgeType, ctxt.getApplicationId());
- log.error(msg);
- throw new UnregisteredClusterException(msg);
- }
-
- Runnable terminateInTimeout = new Runnable() {
- @Override public void run() {
- ClusterContext ctxt = CloudControllerContext.getInstance().getClusterContext(clusterId_);
- if (ctxt == null) {
- String msg = String.format("Service unregistration failed. Cluster not found: [cluster-id] %s " +
- "[application-id] %s", clusterId_, ctxt.getApplicationId());
- log.error(msg);
- return;
- }
- Collection<Member> members = TopologyManager.getTopology().
- getService(ctxt.getCartridgeType()).getCluster(clusterId_).getMembers();
- //finding the responding members from the existing members in the topology.
- int sizeOfRespondingMembers = 0;
- for (Member member : members) {
- if (member.getStatus().getCode() >= MemberStatus.Active.getCode()) {
- sizeOfRespondingMembers++;
- }
- }
-
- long endTime = System.currentTimeMillis() + ctxt.getTimeoutInMillis() * sizeOfRespondingMembers;
- while (System.currentTimeMillis() < endTime) {
- CloudControllerUtil.sleep(1000);
-
- }
-
- // if there are still alive members
- if (members.size() > 0) {
- //forcefully terminate them
- for (Member member : members) {
-
- try {
- terminateInstance(member.getMemberId());
- } catch (Exception e) {
- // we are not gonna stop the execution due to errors.
- log.warn((String.format(
- "Instance termination failed of member [member-id] %s " + "[application-id] %s",
- member.getMemberId(), ctxt.getApplicationId())), e);
-
- }
- }
- }
- }
- };
- Runnable unregister = new Runnable() {
- public void run() {
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireClusterContextWriteLock();
- ClusterContext ctxt = CloudControllerContext.getInstance().getClusterContext(clusterId_);
- if (ctxt == null) {
- String msg = String.format(
- "Service unregistration failed. Cluster not found: [cluster-id] %s " +
- "[application-id] %s ", clusterId_, ctxt.getApplicationId());
- log.error(msg);
- return;
- }
- Collection<Member> members = TopologyManager.getTopology().
- getService(ctxt.getCartridgeType()).getCluster(clusterId_).getMembers();
-
- while (members.size() > 0) {
- //waiting until all the members got removed from the Topology/ timed out
- CloudControllerUtil.sleep(1000);
- }
-
- log.info(String.format("Unregistration of service cluster: [cluster-id] %s [application-id]",
- clusterId_, ctxt.getApplicationId()));
- deleteVolumes(ctxt);
- onClusterRemoval(clusterId_);
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- }
-
- private void deleteVolumes(ClusterContext ctxt) {
- if (ctxt.isVolumeRequired()) {
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireCartridgesWriteLock();
-
- Cartridge cartridge =
- CloudControllerContext.getInstance().getCartridge(ctxt.getCartridgeType());
- if (cartridge != null &&
- CloudControllerContext.getInstance().getIaasProviders(cartridge.getType()) != null &&
- ctxt.getVolumes() != null) {
- for (Volume volume : ctxt.getVolumes()) {
- if (volume.getId() != null) {
- String iaasType = volume.getIaasType();
- Iaas iaas = CloudControllerContext.getInstance()
- .getIaasProvider(cartridge.getType(), iaasType)
- .getIaas();
- if (iaas != null) {
- try {
- // delete the volumes if remove on unsubscription is true.
- if (volume.isRemoveOntermination()) {
- iaas.deleteVolume(volume.getId());
- volume.setId(null);
- }
- } catch (Exception ignore) {
- if (log.isErrorEnabled()) {
- log.error((String.format("Error while deleting volume [id] %s " +
- "[application-id]", volume.getId(),
- ctxt.getApplicationId())), ignore);
- }
- }
- }
- }
- }
- CloudControllerContext.getInstance().updateCartridge(cartridge);
- }
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- }
- }
- };
- new Thread(terminateInTimeout).start();
- new Thread(unregister).start();
- return true;
- }
-
- /**
- * FIXME: A validate method shouldn't persist data
- */
- @Override public boolean validateDeploymentPolicyNetworkPartition(String cartridgeType, String networkPartitionId)
- throws InvalidPartitionException, InvalidCartridgeTypeException {
-
- NetworkPartition networkPartition =
- CloudControllerContext.getInstance().getNetworkPartition(networkPartitionId);
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireCartridgesWriteLock();
-
- List<String> validatedPartitions = CloudControllerContext.getInstance().getPartitionIds(cartridgeType);
- if (validatedPartitions != null) {
- // cache hit for this cartridge
- // get list of partitions
- if (log.isDebugEnabled()) {
- log.debug("Partition validation cache hit for cartridge type: " + cartridgeType);
- }
- }
-
- Map<String, IaasProvider> partitionToIaasProviders = new ConcurrentHashMap<String, IaasProvider>();
-
- if (log.isDebugEnabled()) {
- log.debug("Deployment policy validation started for cartridge type: " + cartridgeType);
- }
-
- Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType);
- if (cartridge == null) {
- String msg = "Cartridge not found: " + cartridgeType;
- log.error(msg);
- throw new InvalidCartridgeTypeException(msg);
- }
-
- Map<String, Future<IaasProvider>> jobList = new HashMap<String, Future<IaasProvider>>();
- for (Partition partition : networkPartition.getPartitions()) {
- if (validatedPartitions != null && validatedPartitions.contains(partition.getId())) {
- // partition cache hit
- String provider = partition.getProvider();
- IaasProvider iaasProvider =
- CloudControllerContext.getInstance().getIaasProvider(cartridge.getType(), provider);
- partitionToIaasProviders.put(partition.getId(), iaasProvider);
- continue;
- }
-
- Callable<IaasProvider> worker = new PartitionValidatorCallable(partition, cartridge);
- Future<IaasProvider> job = CloudControllerContext.getInstance().getExecutorService().submit(worker);
- jobList.put(partition.getId(), job);
- }
-
- // Retrieve the results of the concurrently performed sanity checks.
- for (Entry<String, Future<IaasProvider>> entry : jobList.entrySet()) {
- if (entry == null) {
- continue;
- }
- String partitionId = entry.getKey();
- Future<IaasProvider> job = entry.getValue();
- try {
- // add to a temporary Map
- IaasProvider iaasProvider = job.get();
- if (iaasProvider != null) {
- partitionToIaasProviders.put(partitionId, iaasProvider);
- }
-
- // add to cache
- CloudControllerContext.getInstance().addToCartridgeTypeToPartitionIdMap(cartridgeType, partitionId);
-
- if (log.isDebugEnabled()) {
- log.debug("Partition " + partitionId + " added to the cache against cartridge: " +
- "[cartridge-type] " + cartridgeType);
- }
- } catch (Exception e) {
- String message =
- "Could not cache partitions against the cartridge: [cartridge-type] " + cartridgeType;
- log.error(message, e);
- throw new InvalidPartitionException(message, e);
- }
- }
-
- // if and only if the deployment policy valid
- CloudControllerContext.getInstance().addIaasProviders(cartridgeType, partitionToIaasProviders);
- CloudControllerContext.getInstance().updateCartridge(cartridge);
-
- // persist data
- CloudControllerContext.getInstance().persist();
-
- log.info("All partitions [" + CloudControllerUtil.getPartitionIds(networkPartition.getPartitions()) + "]" +
- " were validated successfully, against the cartridge: " + cartridgeType);
-
- return true;
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- }
-
- private void onClusterRemoval(final String clusterId) {
- ClusterContext ctxt = CloudControllerContext.getInstance().getClusterContext(clusterId);
- TopologyBuilder.handleClusterRemoved(ctxt);
- CloudControllerContext.getInstance().removeClusterContext(clusterId);
- CloudControllerContext.getInstance().removeMemberContextsOfCluster(clusterId);
- CloudControllerContext.getInstance().persist();
- }
-
- @Override public boolean validatePartition(Partition partition) throws InvalidPartitionException {
- handleNullObject(partition, "Partition validation failed. Partition is null.");
-
- String provider = partition.getProvider();
- String partitionId = partition.getId();
-
- handleNullObject(provider, "Partition [" + partitionId + "] validation failed. Partition provider is null.");
- IaasProvider iaasProvider = CloudControllerConfig.getInstance().getIaasProvider(provider);
-
- return CloudControllerServiceUtil.validatePartition(partition, iaasProvider);
- }
-
- public ClusterContext getClusterContext(String clusterId) {
- return CloudControllerContext.getInstance().getClusterContext(clusterId);
- }
-
- @Override public boolean updateClusterStatus(String serviceName, String clusterId, String instanceId,
- ClusterStatus status) {
- //TODO
- return true;
- }
-
- private void handleNullObject(Object obj, String errorMsg) {
- if (obj == null) {
- log.error(errorMsg);
- throw new CloudControllerException(errorMsg);
- }
- }
-
- @Override public boolean createApplicationClusters(String appId, ApplicationClusterContext[] appClustersContexts)
- throws ApplicationClusterRegistrationException {
- if (appClustersContexts == null || appClustersContexts.length == 0) {
- String errorMsg = "No application cluster information found, unable to create clusters: " +
- "[application-id] " + appId;
- log.error(errorMsg);
- throw new ApplicationClusterRegistrationException(errorMsg);
- }
-
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireClusterContextWriteLock();
-
- // Create a Cluster Context obj. for each of the Clusters in the Application
- List<Cluster> clusters = new ArrayList<Cluster>();
- Map<String, List<String>> accessUrls = new HashMap<String, List<String>>();
-
- for (ApplicationClusterContext appClusterCtxt : appClustersContexts) {
- String clusterId = appClusterCtxt.getClusterId();
- if (appClusterCtxt.isLbCluster()) {
- String[] dependencyClusterIDs = appClusterCtxt.getDependencyClusterIds();
- if (dependencyClusterIDs != null) {
- for (int i = 0; i < dependencyClusterIDs.length; i++) {
-
- List<String> accessUrlPerCluster = new ArrayList();
- Collection<ClusterPortMapping> clusterPortMappings =
- CloudControllerContext.getInstance().getClusterPortMappings(appId, clusterId);
-
- for (ClusterPortMapping clusterPortMapping : clusterPortMappings) {
- try {
- if (clusterPortMapping.isKubernetes()) {
- URL accessUrl =
- new URL(clusterPortMapping.getProtocol(), appClusterCtxt.getHostName(),
- clusterPortMapping.getKubernetesServicePort(), "");
- accessUrlPerCluster.add(accessUrl.toString());
- } else {
- URL accessUrl =
- new URL(clusterPortMapping.getProtocol(), appClusterCtxt.getHostName(),
- clusterPortMapping.getProxyPort(), "");
- accessUrlPerCluster.add(accessUrl.toString());
- }
- } catch (MalformedURLException e) {
- String message = "Could not generate access URL";
- log.error(message, e);
- throw new ApplicationClusterRegistrationException(message, e);
- }
- }
- accessUrls.put(dependencyClusterIDs[i], accessUrlPerCluster);
- }
- }
- }
- }
-
- for (ApplicationClusterContext appClusterCtxt : appClustersContexts) {
- ClusterContext clusterContext =
- new ClusterContext(appId, appClusterCtxt.getCartridgeType(), appClusterCtxt.getClusterId(),
- appClusterCtxt.getTextPayload(), appClusterCtxt.getHostName(),
- appClusterCtxt.isLbCluster(), appClusterCtxt.getProperties());
-
- if (appClusterCtxt.isVolumeRequired()) {
- clusterContext.setVolumeRequired(true);
- clusterContext.setVolumes(appClusterCtxt.getVolumes());
- }
- CloudControllerContext.getInstance().addClusterContext(clusterContext);
-
- // Create cluster object
- Cluster cluster = new Cluster(appClusterCtxt.getCartridgeType(), appClusterCtxt.getClusterId(),
- appClusterCtxt.getDeploymentPolicyName(),
- appClusterCtxt.getAutoscalePolicyName(), appId);
- cluster.setLbCluster(false);
- cluster.setTenantRange(appClusterCtxt.getTenantRange());
- cluster.setHostNames(Arrays.asList(appClusterCtxt.getHostName()));
- cluster.setAccessUrls(accessUrls.get(appClusterCtxt.getClusterId()));
-
- if (appClusterCtxt.getProperties() != null) {
- Properties properties = CloudControllerUtil.toJavaUtilProperties(appClusterCtxt.getProperties());
- cluster.setProperties(properties);
- }
-
- clusters.add(cluster);
- }
- TopologyBuilder.handleApplicationClustersCreated(appId, clusters);
- CloudControllerContext.getInstance().persist();
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- return true;
- }
-
- public boolean createClusterInstance(String serviceType, String clusterId, String alias, String instanceId,
- String partitionId, String networkPartitionId)
- throws ClusterInstanceCreationException {
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireClusterContextWriteLock();
- TopologyBuilder.handleClusterInstanceCreated(serviceType, clusterId, alias, instanceId, partitionId,
- networkPartitionId);
-
- CloudControllerContext.getInstance().persist();
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- return true;
- }
-
- @Override public KubernetesCluster[] getKubernetesClusters() {
- return CloudControllerContext.getInstance().getKubernetesClusters();
- }
-
- @Override public KubernetesCluster getKubernetesCluster(String kubernetesClusterId)
- throws NonExistingKubernetesClusterException {
- return CloudControllerContext.getInstance().getKubernetesCluster(kubernetesClusterId);
- }
-
- @Override public KubernetesMaster getMasterForKubernetesCluster(String kubernetesClusterId)
- throws NonExistingKubernetesClusterException {
- return CloudControllerContext.getInstance().getKubernetesMasterInGroup(kubernetesClusterId);
- }
-
- @Override public KubernetesHost[] getHostsForKubernetesCluster(String kubernetesClusterId)
- throws NonExistingKubernetesClusterException {
- return CloudControllerContext.getInstance().getKubernetesHostsInGroup(kubernetesClusterId);
- }
-
- @Override public boolean addKubernetesCluster(KubernetesCluster kubernetesCluster)
- throws InvalidKubernetesClusterException, KubernetesClusterAlreadyExistsException {
- if (kubernetesCluster == null) {
- throw new InvalidKubernetesClusterException("Kubernetes cluster cannot be null");
- }
-
- try {
- if (CloudControllerContext.getInstance().getKubernetesCluster(kubernetesCluster.getClusterId()) != null) {
- throw new KubernetesClusterAlreadyExistsException("Kubernetes cluster already exists");
- }
- } catch (NonExistingKubernetesClusterException ignore) {
- }
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireKubernetesClusterWriteLock();
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Adding kubernetes cluster: [kubernetes-cluster-id] %s",
- kubernetesCluster.getClusterId()));
- }
- CloudControllerUtil.validateKubernetesCluster(kubernetesCluster);
-
- // Add to information model
- CloudControllerContext.getInstance().addKubernetesCluster(kubernetesCluster);
- CloudControllerContext.getInstance().persist();
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Kubernetes cluster added successfully: [kubernetes-cluster-id] %s",
- kubernetesCluster.getClusterId()));
- }
- return true;
- } catch (Exception e) {
- throw new InvalidKubernetesClusterException(e.getMessage(), e);
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- }
-
- @Override public boolean updateKubernetesCluster(KubernetesCluster kubernetesCluster)
- throws InvalidKubernetesClusterException {
- if (kubernetesCluster == null) {
- throw new InvalidKubernetesClusterException("Kubernetes cluster cannot be null");
- }
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireKubernetesClusterWriteLock();
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Updating kubernetes cluster: [kubernetes-cluster-id] %s",
- kubernetesCluster.getClusterId()));
- }
- CloudControllerUtil.validateKubernetesCluster(kubernetesCluster);
-
- // Updating the information model
- CloudControllerContext.getInstance().updateKubernetesCluster(kubernetesCluster);
- CloudControllerContext.getInstance().persist();
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Kubernetes cluster updated successfully: [kubernetes-cluster-id] %s",
- kubernetesCluster.getClusterId()));
- }
- return true;
- } catch (Exception e) {
- throw new InvalidKubernetesClusterException(e.getMessage(), e);
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- }
-
- @Override public boolean addKubernetesHost(String kubernetesClusterId, KubernetesHost kubernetesHost)
- throws InvalidKubernetesHostException, NonExistingKubernetesClusterException {
- if (kubernetesHost == null) {
- throw new InvalidKubernetesHostException("Kubernetes host cannot be null");
- }
- if (StringUtils.isEmpty(kubernetesClusterId)) {
- throw new NonExistingKubernetesClusterException("Kubernetes cluster id cannot be null");
- }
-
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireKubernetesClusterWriteLock();
-
- if (log.isInfoEnabled()) {
- log.info(String.format(
- "Adding kubernetes host for kubernetes cluster: [kubernetes-cluster-id] %s " + "[hostname] %s",
- kubernetesClusterId, kubernetesHost.getHostname()));
- }
- CloudControllerUtil.validateKubernetesHost(kubernetesHost);
-
- KubernetesCluster kubernetesCluster = getKubernetesCluster(kubernetesClusterId);
- ArrayList<KubernetesHost> kubernetesHostArrayList;
-
- if (kubernetesCluster.getKubernetesHosts() == null) {
- kubernetesHostArrayList = new ArrayList<KubernetesHost>();
- } else {
- if (CloudControllerContext.getInstance().kubernetesHostExists(kubernetesHost.getHostId())) {
- throw new InvalidKubernetesHostException(
- "Kubernetes host already exists: [hostname] " + kubernetesHost.getHostId());
- }
- kubernetesHostArrayList =
- new ArrayList<KubernetesHost>(Arrays.asList(kubernetesCluster.getKubernetesHosts()));
- }
- kubernetesHostArrayList.add(kubernetesHost);
-
- // Update information model
- kubernetesCluster.setKubernetesHosts(
- kubernetesHostArrayList.toArray(new KubernetesHost[kubernetesHostArrayList.size()]));
- CloudControllerContext.getInstance().updateKubernetesCluster(kubernetesCluster);
- CloudControllerContext.getInstance().persist();
-
- if (log.isInfoEnabled()) {
- log.info(
- String.format("Kubernetes host added successfully: [id] %s", kubernetesCluster.getClusterId()));
- }
-
- return true;
- } catch (Exception e) {
- throw new InvalidKubernetesHostException(e.getMessage(), e);
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- }
-
- @Override public boolean removeKubernetesCluster(String kubernetesClusterId)
- throws NonExistingKubernetesClusterException {
- if (StringUtils.isEmpty(kubernetesClusterId)) {
- throw new NonExistingKubernetesClusterException("Kubernetes cluster id cannot be empty");
- }
-
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireKubernetesClusterWriteLock();
-
- if (log.isInfoEnabled()) {
- log.info("Removing Kubernetes cluster: " + kubernetesClusterId);
- }
- // Remove entry from information model
- CloudControllerContext.getInstance().removeKubernetesCluster(kubernetesClusterId);
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Kubernetes cluster removed successfully: [id] %s", kubernetesClusterId));
- }
-
- CloudControllerContext.getInstance().persist();
-
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- return true;
- }
-
- @Override public boolean removeKubernetesHost(String kubernetesHostId) throws NonExistingKubernetesHostException {
- if (kubernetesHostId == null) {
- throw new NonExistingKubernetesHostException("Kubernetes host id cannot be null");
- }
-
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireKubernetesClusterWriteLock();
-
- if (log.isInfoEnabled()) {
- log.info("Removing Kubernetes Host: " + kubernetesHostId);
- }
- try {
- KubernetesCluster kubernetesClusterStored =
- CloudControllerContext.getInstance().getKubernetesClusterContainingHost(kubernetesHostId);
-
- // Kubernetes master cannot be removed
- if (kubernetesClusterStored.getKubernetesMaster().getHostId().equals(kubernetesHostId)) {
- throw new NonExistingKubernetesHostException(
- "Kubernetes master is not allowed to be removed [id] " + kubernetesHostId);
- }
-
- List<KubernetesHost> kubernetesHostList = new ArrayList<KubernetesHost>();
- for (KubernetesHost kubernetesHost : kubernetesClusterStored.getKubernetesHosts()) {
- if (!kubernetesHost.getHostId().equals(kubernetesHostId)) {
- kubernetesHostList.add(kubernetesHost);
- }
- }
- // member count will be equal only when host object was not found
- if (kubernetesHostList.size() == kubernetesClusterStored.getKubernetesHosts().length) {
- throw new NonExistingKubernetesHostException(
- "Kubernetes host not found for [id] " + kubernetesHostId);
- }
- KubernetesHost[] kubernetesHostsArray = new KubernetesHost[kubernetesHostList.size()];
- kubernetesHostList.toArray(kubernetesHostsArray);
-
- // Update information model
- kubernetesClusterStored.setKubernetesHosts(kubernetesHostsArray);
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Kubernetes host removed successfully: [id] %s", kubernetesHostId));
- }
-
- CloudControllerContext.getInstance().persist();
-
- return true;
- } catch (Exception e) {
- throw new NonExistingKubernetesHostException(e.getMessage(), e);
- }
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- }
-
- @Override public boolean updateKubernetesMaster(KubernetesMaster kubernetesMaster)
- throws InvalidKubernetesMasterException, NonExistingKubernetesMasterException {
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireKubernetesClusterWriteLock();
- CloudControllerUtil.validateKubernetesMaster(kubernetesMaster);
- if (log.isInfoEnabled()) {
- log.info("Updating Kubernetes master: " + kubernetesMaster);
- }
- try {
- KubernetesCluster kubernetesClusterStored = CloudControllerContext.getInstance()
- .getKubernetesClusterContainingHost(
- kubernetesMaster.getHostId());
-
- // Update information model
- kubernetesClusterStored.setKubernetesMaster(kubernetesMaster);
-
- CloudControllerContext.getInstance().persist();
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Kubernetes master updated successfully: [id] %s",
- kubernetesMaster.getHostId()));
- }
-
- return true;
- } catch (Exception e) {
- throw new InvalidKubernetesMasterException(e.getMessage(), e);
- }
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- }
-
- @Override public boolean updateKubernetesHost(KubernetesHost kubernetesHost)
- throws InvalidKubernetesHostException, NonExistingKubernetesHostException {
-
- Lock lock = null;
- try {
- lock = CloudControllerContext.getInstance().acquireKubernetesClusterWriteLock();
- CloudControllerUtil.validateKubernetesHost(kubernetesHost);
- if (log.isInfoEnabled()) {
- log.info("Updating Kubernetes Host: " + kubernetesHost);
- }
-
- try {
- KubernetesCluster kubernetesClusterStored = CloudControllerContext.getInstance()
- .getKubernetesClusterContainingHost(
- kubernetesHost.getHostId());
- KubernetesHost[] kubernetesHosts = kubernetesClusterStored.getKubernetesHosts();
- for (int i = 0; i < kubernetesHosts.length; i++) {
- if (kubernetesHosts[i].getHostId().equals(kubernetesHost.getHostId())) {
- // Update the information model
- kubernetesHosts[i] = kubernetesHost;
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Kubernetes host updated successfully: [id] %s",
- kubernetesHost.getHostId()));
- }
-
- CloudControllerContext.getInstance().updateKubernetesCluster(kubernetesClusterStored);
- CloudControllerContext.getInstance().persist();
- return true;
- }
- }
- } catch (Exception e) {
- throw new InvalidKubernetesHostException(e.getMessage(), e);
- }
- } finally {
- if (lock != null) {
- CloudControllerContext.getInstance().releaseWriteLock(lock);
- }
- }
- throw new NonExistingKubernetesHostException("Kubernetes host not found [id] " + kubernetesHost.getHostId());
- }
-
- @Override public boolean addNetworkPartition(NetworkPartition networkPartition)
- throws NetworkPartitionAlreadyExistsException, InvalidNetworkPartitionException {
-
- handleNullObject(networkPartition, "Network Partition is null");
- handleNullObject(networkPartition.getId(), "Network Partition ID is null");
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Adding network partition: [network-partition-id] %s", networkPartition.getId()));
- }
-
- String networkPartitionID = networkPartition.getId();
- if (cloudControllerContext.getNetworkPartition(networkPartitionID) != null) {
- String message = "Network partition already exists: [network-partition-id] " + networkPartitionID;
- log.error(message);
- throw new NetworkPartitionAlreadyExistsException(message);
- }
-
- if (networkPartition.getPartitions() != null && networkPartition.getPartitions().length != 0) {
- for (Partition partition : networkPartition.getPartitions()) {
- if (partition != null) {
- if (log.isInfoEnabled()) {
- log.info(String.format("Validating partition: [network-partition-id] %s [partition-id] %s",
- networkPartition.getId(), partition.getId()));
- }
- // Overwrites partition provider with network partition provider
- partition.setProvider(networkPartition.getProvider());
- try {
- validatePartition(partition);
- } catch (InvalidPartitionException e) {
- //Following message is shown to the end user in all the the API clients(GUI/CLI/Rest API)
- throw new InvalidNetworkPartitionException(String.format(
- "Network partition " + " %s, is invalid since the partition %s is invalid",
- networkPartition.getId(), partition.getId()), e);
- }
- if (log.isInfoEnabled()) {
- log.info(String.format(
- "Partition validated successfully: [network-partition-id] %s " + "[partition-id] %s",
- networkPartition.getId(), partition.getId()));
- }
- }
- }
- } else {
- //Following message is shown to the end user in all the the API clients(GUI/CLI/Rest API)
- throw new InvalidNetworkPartitionException(
- String.format("Network partition: " + "%s doesn't not have any partitions ",
- networkPartition.getId()));
- }
-
- // adding network partition to CC-Context
- CloudControllerContext.getInstance().addNetworkPartition(networkPartition);
- // persisting CC-Context
- CloudControllerContext.getInstance().persist();
- if (log.isInfoEnabled()) {
- log.info(String.format("Network partition added successfully: [network-partition-id] %s",
- networkPartition.getId()));
- }
- return true;
- }
-
- @Override public boolean removeNetworkPartition(String networkPartitionId)
- throws NetworkPartitionNotExistsException {
-
- try {
- if (log.isInfoEnabled()) {
- log.info(String.format("Removing network partition: [network-partition-id] %s", networkPartitionId));
- }
- handleNullObject(networkPartitionId, "Network Partition ID is null");
-
- if (cloudControllerContext.getNetworkPartition(networkPartitionId) == null) {
- String message = "Network partition not found: [network-partition-id] " + networkPartitionId;
- log.error(message);
- throw new NetworkPartitionNotExistsException(message);
- }
- // removing from CC-Context
- CloudControllerContext.getInstance().removeNetworkPartition(networkPartitionId);
- // persisting CC-Context
- CloudControllerContext.getInstance().persist();
- if (log.isInfoEnabled()) {
- log.info(String.format("Network partition removed successfully: [network-partition-id] %s",
- networkPartitionId));
- }
- } catch (Exception e) {
- String message = e.getMessage();
- log.error(message);
- throw new CloudControllerException(message, e);
- }
- return true;
- }
-
- @Override public boolean updateNetworkPartition(NetworkPartition networkPartition)
- throws NetworkPartitionNotExistsException {
- try {
- handleNullObject(networkPartition, "Network Partition is null");
- handleNullObject(networkPartition.getId(), "Network Partition ID is null");
-
- if (log.isInfoEnabled()) {
- log.info(String.format("Updating network partition: [network-partition-id] %s",
- networkPartition.getId()));
- }
-
- String networkPartitionID = networkPartition.getId();
- if (cloudControllerContext.getNetworkPartition(networkPartitionID) == null) {
- String message = "Network partition not found: [network-partition-id] " + networkPartitionID;
- log.error(message);
- throw new NetworkPartitionNotExistsException(message);
- }
-
- if (networkPartition.getPartitions() != null) {
- for (Partition partition : networkPartition.getPartitions()) {
- if (partition != null) {
- if (log.isInfoEnabled()) {
- log.info(String.format("Validating partition: [network-partition-id] %s [partition-id] %s",
- networkPartition.getId(), partition.getId()));
- }
- // Overwrites partition provider with network partition provider
- partition.setProvider(networkPartition.getProvider());
- validatePartition(partition);
- if (log.isInfoEnabled()) {
- log.info(String.format("Partition validated successfully: [network-partition-id] %s " +
- "[partition-id] %s", networkPartition.getId(), partition.getId()));
- }
- }
- }
- }
-
- // overriding network partition to CC-Context
- CloudControllerContext.getInstance().addNetworkPartition(networkPartition);
- // persisting CC-Context
- CloudControllerContext.getInstance().persist();
- if (log.isInfoEnabled()) {
- log.info(String.format("Network partition updated successfully: [network-partition-id] %s",
- networkPartition.getId()));
- }
- return true;
- } catch (Exception e) {
- String message = e.getMessage();
- log.error(message);
- throw new CloudControllerException(message, e);
- }
- }
-
- @Override public NetworkPartition[] getNetworkPartitions() {
- try {
- Collection<NetworkPartition> networkPartitionList = cloudControllerContext.getNetworkPartitions();
- return networkPartitionList.toArray(new NetworkPartition[networkPartitionList.size()]);
- } catch (Exception e) {
- String message = "Could not get network partitions";
- log.error(message);
- throw new CloudControllerException(message, e);
- }
- }
-
- @Override public NetworkPartition getNetworkPartition(String networkPartitionId) {
- try {
- return CloudControllerContext.getInstance().getNetworkPartition(networkPartitionId);
- } catch (Exception e) {
- String message =
- String.format("Could not get network partition: [network-partition-id] %s", networkPartitionId);
- log.error(message);
- throw new CloudControllerException(message, e);
- }
- }
-
- @Override public String[] getIaasProviders() {
-
- try {
- Collection<IaasProvider> iaasProviders = CloudControllerConfig.getInstance().getIaasProviders();
- List<String> iaases = new ArrayList<String>();
-
- for (IaasProvider iaas : iaasProviders) {
- iaases.add(iaas.getType());
- }
-
- return iaases.toArray(new String[iaases.size()]);
- } catch (Exception e) {
- String message = String.format("Could not get Iaas Providers");
- log.error(message);
- throw new CloudControllerException(message, e);
- }
-
- }
+ private static final Log log = LogFactory.getLog(CloudControllerServiceImpl.class);
+
+ private static final String PERSISTENCE_MAPPING = "PERSISTENCE_MAPPING";
+ public static final String PAYLOAD_PARAMETER = "payload_parameter.";
+
+ private CloudControllerContext cloudControllerContext = CloudControllerContext.getInstance();
+ private ExecutorService executorService;
+
+ public CloudControllerServiceImpl() {
+ executorService = StratosThreadPool.getExecutorService("cloud.controller.instance.manager.thread.pool", 50);
+
+ }
+
+ public boolean addCartridge(Cartridge cartridgeConfig)
+ throws InvalidCartridgeDefinitionException, InvalidIaasProviderException, CartridgeAlreadyExistsException {
+
+ handleNullObject(cartridgeConfig, "Cartridge definition is null");
+
+ if (log.isInfoEnabled()) {
+ log.info("Adding cartridge: [cartridge-type] " + cartridgeConfig.getType());
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Cartridge definition: " + cartridgeConfig.toString());
+ }
+
+ try {
+ CloudControllerUtil.extractIaaSProvidersFromCartridge(cartridgeConfig);
+ } catch (Exception e) {
+ String message = "Invalid cartridge definition: [cartridge-type] " + cartridgeConfig.getType();
+ log.error(message, e);
+ throw new InvalidCartridgeDefinitionException(message, e);
+ }
+
+ String cartridgeType = cartridgeConfig.getType();
+ if (cloudControllerContext.getCartridge(cartridgeType) != null) {
+ String message = "Cartridge already exists: [cartridge-type] " + cartridgeType;
+ log.error(message);
+ throw new CartridgeAlreadyExistsException(message);
+ }
+
+ // Add cartridge to the cloud controller context and persist
+ CloudControllerContext.getInstance().addCartridge(cartridgeConfig);
+ CloudControllerContext.getInstance().persist();
+
+ List<Cartridge> cartridgeList = new ArrayList<Cartridge>();
+ cartridgeList.add(cartridgeConfig);
+
+ TopologyBuilder.handleServiceCreated(cartridgeList);
+
+ if (log.isInfoEnabled()) {
+ log.info("Successfully added cartridge: [cartridge-type] " + cartridgeType);
+ }
+ return true;
+ }
+
+ @Override
+ public boolean updateCartridge(Cartridge cartridge)
+ throws InvalidCartridgeDefinitionException, InvalidIaasProviderException,
+ CartridgeDefinitionNotExistsException {
+
+ handleNullObject(cartridge, "Cartridge definition is null");
+
+ if (log.isInfoEnabled()) {
+ log.info("Updating cartridge: [cartridge-type] " + cartridge.getType());
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Cartridge definition: " + cartridge.toString());
+ }
+
+ try {
+ CloudControllerUtil.extractIaaSProvidersFromCartridge(cartridge);
+ } catch (Exception e) {
+ String msg = "Invalid cartridge definition: [cartridge-type] " + cartridge.getType();
+ log.error(msg, e);
+ throw new InvalidCartridgeDefinitionException(msg, e);
+ }
+
+ String cartridgeType = cartridge.getType();
+ if (cloudControllerContext.getCartridge(cartridgeType) != null) {
+ Cartridge cartridgeToBeRemoved = cloudControllerContext.getCartridge(cartridgeType);
+ try {
+ removeCartridgeFromCC(cartridgeToBeRemoved.getType());
+ } catch (InvalidCartridgeTypeException ignore) {
+ }
+ copyIaasProviders(cartridge, cartridgeToBeRemoved);
+ } else {
+ throw new CartridgeDefinitionNotExistsException("This cartridge definition not exists");
+ }
+
+ // Add cartridge to the cloud controller context and persist
+ CloudControllerContext.getInstance().addCartridge(cartridge);
+ CloudControllerContext.getInstance().persist();
+ // transaction ends
+
+ if (log.isInfoEnabled()) {
+ log.info("Successfully updated cartridge: [cartridge-type] " + cartridgeType);
+ }
+ return true;
+ }
+
+ private void copyIaasProviders(Cartridge destCartridge, Cartridge sourceCartridge) {
+
+ List<IaasProvider> newIaasProviders =
+ CloudControllerContext.getInstance().getIaasProviders(destCartridge.getType());
+
+ Map<String, IaasProvider> iaasProviderMap =
+ CloudControllerContext.getInstance().getPartitionToIaasProvider(sourceCartridge.getType());
+
+ if (iaasProviderMap != null) {
+ for (Entry<String, IaasProvider> entry : iaasProviderMap.entrySet()) {
+ if (entry == null) {
+ continue;
+ }
+ String partitionId = entry.getKey();
+ IaasProvider iaasProvider = entry.getValue();
+ if (newIaasProviders.contains(iaasProvider)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Copying partition from the cartridge that is undeployed, to the new cartridge: " +
+ "[partition-id] " + partitionId + " [cartridge-type] " + destCartridge.getType());
+ }
+ CloudControllerContext.getInstance().addIaasProvider(destCartridge.getType(), partitionId,
+ newIaasProviders.get(newIaasProviders.indexOf(
+ iaasProvider)));
+ }
+ }
+ }
+
+ }
+
+ public boolean removeCartridge(String cartridgeType) throws InvalidCartridgeTypeException {
+ //Removing the cartridge from CC
+ Cartridge cartridge = removeCartridgeFromCC(cartridgeType);
+ //removing the cartridge from Topology
+ removeCartridgeFromTopology(cartridge);
+
+ if (log.isInfoEnabled()) {
+ log.info("Successfully removed cartridge: [cartridge-type] " + cartridgeType);
+ }
+ return true;
+ }
+
+ private Cartridge removeCartridgeFromCC(String cartridgeType) throws InvalidCartridgeTypeException {
+ Cartridge cartridge = null;
+ if ((cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType)) != null) {
+ if (CloudControllerContext.getInstance().getCartridges().remove(cartridge)) {
+ // invalidate partition validation cache
+ CloudControllerContext.getInstance().removeFromCartridgeTypeToPartitionIds(cartridgeType);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Partition cache invalidated for cartridge " + cartridgeType);
+ }
+
+ CloudControllerContext.getInstance().persist();
+
+ if (log.isInfoEnabled()) {
+ log.info("Successfully removed cartridge: [cartridge-type] " + cartridgeType);
+ }
+ return cartridge;
+ }
+ }
+ String msg = "Cartridge not found: [cartridge-type] " + cartridgeType;
+ log.error(msg);
+ throw new InvalidCartridgeTypeException(msg);
+ }
+
+ private void removeCartridgeFromTopology(Cartridge cartridge) throws InvalidCartridgeTypeException {
+ // sends the service removed event
+ List<Cartridge> cartridgeList = new ArrayList<Cartridge>();
+ cartridgeList.add(cartridge);
+ TopologyBuilder.handleServiceRemoved(cartridgeList);
+ }
+
+ public boolean addServiceGroup(ServiceGroup servicegroup) throws InvalidServiceGroupException {
+
+ if (servicegroup == null) {
+ String msg = "Invalid ServiceGroup Definition: Definition is null.";
+ log.error(msg);
+ throw new IllegalArgumentException(msg);
+
+ }
+ CloudControllerContext.getInstance().addServiceGroup(servicegroup);
+ CloudControllerContext.getInstance().persist();
+ return true;
+ }
+
+ public boolean removeServiceGroup(String name) throws InvalidServiceGroupException {
+ if (log.isDebugEnabled()) {
+ log.debug("CloudControllerServiceImpl:removeServiceGroup: " + name);
+ }
+
+ ServiceGroup serviceGroup = null;
+
+ serviceGroup = CloudControllerContext.getInstance().getServiceGroup(name);
+
+ if (serviceGroup != null) {
+ if (CloudControllerContext.getInstance().getServiceGroups().remove(serviceGroup)) {
+ CloudControllerContext.getInstance().persist();
+ if (log.isInfoEnabled()) {
+ log.info("Successfully removed the cartridge group: [group-name] " + serviceGroup);
+ }
+ return true;
+ }
+ }
+
+ String msg = "Cartridge group not found: [group-name] " + name;
+ log.error(msg);
+ throw new InvalidServiceGroupException(msg);
+
+ }
+
+ @Override
+ public ServiceGroup getServiceGroup(String name) throws InvalidServiceGroupException {
+
+ if (log.isDebugEnabled()) {
+ log.debug("getServiceGroupDefinition:" + name);
+ }
+
+ ServiceGroup serviceGroup = CloudControllerContext.getInstance().getServiceGroup(name);
+
+ if (serviceGroup == null) {
+ String message = "Cartridge group not found: [group-name] " + name;
+ if (log.isDebugEnabled()) {
+ log.debug(message);
+ }
+ throw new InvalidServiceGroupException(message);
+ }
+
+ return serviceGroup;
+ }
+
+ public String[] getServiceGroupSubGroups(String name) throws InvalidServiceGroupException {
+ ServiceGroup serviceGroup = this.getServiceGroup(name);
+ if (serviceGroup == null) {
+ throw new InvalidServiceGroupException("Invalid cartridge group: [group-name] " + serviceGroup);
+ }
+
+ return serviceGroup.getSubGroups();
+ }
+
+ /**
+ *
+ */
+ public String[] getServiceGroupCartridges(String name) throws InvalidServiceGroupException {
+ ServiceGroup serviceGroup = this.getServiceGroup(name);
+ if (serviceGroup == null) {
+ throw new InvalidServiceGroupException("Invalid cartridge group: [group-name] " + serviceGroup);
+ }
+ String[] cs = serviceGroup.getCartridges();
+ return cs;
+
+ }
+
+ public Dependencies getServiceGroupDependencies(String name) throws InvalidServiceGroupException {
+ ServiceGroup serviceGroup = this.getServiceGroup(name);
+ if (serviceGroup == null) {
+ throw new InvalidServiceGroupException("Invalid cartridge group: [group-name] " + serviceGroup);
+ }
+ return serviceGroup.getDependencies();
+ }
+
+ @Override
+ public MemberContext[] startInstances(InstanceContext[] instanceContexts)
+ throws CartridgeNotFoundException, InvalidIaasProviderException, CloudControllerException {
+
+ handleNullObject(instanceContexts, "Instance start-up failed, member contexts is null");
+
+ List<MemberContext> memberContextList = new ArrayList<MemberContext>();
+ for (InstanceContext instanceContext : instanceContexts) {
+ if (instanceContext != null) {
+ MemberContext memberContext = startInstance(instanceContext);
+ memberContextList.add(memberContext);
+ }
+ }
+ MemberContext[] memberContextsArray = memberContextList.toArray(new MemberContext[memberContextList.size()]);
+ return memberContextsArray;
+ }
+
+ public MemberContext startInstance(InstanceContext instanceContext)
+ throws CartridgeNotFoundException, InvalidIaasProviderException, CloudControllerException {
+
+ try {
+ // Validate instance context
+ handleNullObject(instanceContext, "Could not start instance, instance context is null");
+ if (log.isDebugEnabled()) {
+ log.debug("Starting up instance: " + instanceContext);
+ }
+
+ // Validate partition
+ Partition partition = instanceContext.getPartition();
+ handleNullObject(partition, "Could not start instance, partition is null");
+
+ // Validate cluster
+ String partitionId = partition.getId();
+ String clusterId = instanceContext.getClusterId();
+ ClusterContext clusterContext = CloudControllerContext.getInstance().getClusterContext(clusterId);
+ handleNullObject(clusterContext,
+ "Could not start instance, cluster context not found: [cluster-id] " + clusterId);
+
+ // Validate cartridge
+ String cartridgeType = clusterContext.getCartridgeType();
+ Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType);
+ if (cartridge == null) {
+ String msg = "Could not startup instance, cartridge not found: [cartridge-type] " + cartridgeType;
+ log.error(msg);
+ throw new CartridgeNotFoundException(msg);
+ }
+
+ // Validate iaas provider
+ IaasProvider iaasProvider =
+ CloudControllerContext.getInstance().getIaasProviderOfPartition(cartridge.getType(), partitionId);
+ if (iaasProvider == null) {
+ String msg = String.format("Could not start instance, " +
+ "IaaS provider not found in cartridge %s for partition %s, " +
+ "partitions found: %s ", cartridgeType, partitionId,
+ CloudControllerContext.getInstance()
+ .getPartitionToIaasProvider(cartridge.getType())
+ .keySet().toString());
+ log.error(msg);
+ throw new InvalidIaasProviderException(msg);
+ }
+
+ // Generate member ID
+ String memberId = generateMemberId(clusterId);
+
+ // Create member context
+ String applicationId = clusterContext.getApplicationId();
+ MemberContext memberContext = createMemberContext(applicationId, cartridgeType, memberId,
+ CloudControllerUtil.getLoadBalancingIPTypeEnumFromString(
+ cartridge.getLoadBalancingIPType()),
+ instanceContext);
+
+ // Prepare payload
+ StringBuilder payload = new StringBuilder(clusterContext.getPayload());
+ addToPayload(payload, "MEMBER_ID", memberId);
+ addToPayload(payload, "INSTANCE_ID", memberContext.getInstanceId());
+ addToPayload(payload, "CLUSTER_INSTANCE_ID", memberContext.getClusterInstanceId());
+ addToPayload(payload, "LB_CLUSTER_ID", memberContext.getLbClusterId());
+ addToPayload(payload, "NETWORK_PARTITION_ID", memberContext.getNetworkPartitionId());
+ addToPayload(payload, "PARTITION_ID", partitionId);
+ addToPayload(payload, "INTERNAL", "false");
+
+ if (memberContext.getProperties() != null) {
+ org.apache.stratos.common.Properties properties = memberContext.getProperties();
+ if (properties != null) {
+ for (Property prop : properties.getProperties()) {
+ addToPayload(payload, prop.getName(), String.valueOf(prop.getValue()));
+ }
+ }
+ }
+
+ NetworkPartition networkPartition =
+ CloudControllerContext.getInstance().getNetworkPartition(memberContext.getNetworkPartitionId());
+
+ if (networkPartition.getProperties() != null) {
+ if (networkPartition.getProperties().getProperties() != null) {
+ for (Property property : networkPartition.getProperties().getProperties()) {
+ // check if a property is related to the payload. Currently
+ // this is done by checking if the
+ // property name starts with 'payload_parameter.' suffix. If
+ // so the payload param name will
+ // be taken as the substring from the index of '.' to the
+ // end of the property name.
+ if (property.getName().startsWith(PAYLOAD_PARAMETER)) {
+ String propertyName = property.getName();
+ String payloadParamName = propertyName.substring(propertyName.indexOf(".") + 1);
+ if (payload.toString().contains(payloadParamName)) {
+ replaceInPayload(payloadParamName, payload, payloadParamName, property.getValue());
+ } else {
+ addToPayload(payload, payloadParamName, property.getValue());
+ }
+ }
+ }
+ }
+ }
+
+ Iaas iaas = iaasProvider.getIaas();
+ if (clusterContext.isVolumeRequired()) {
+ addToPayload(payload, PERSISTENCE_MAPPING, getPersistencePayload(clusterContext, iaas).toString());
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Payload: " + payload.toString());
+ }
+
+ if (clusterContext.isVolumeRequired()) {
+
+ Volume[] volumes = clusterContext.getVolumes();
+ if (volumes != null) {
+ for (int i = 0; i < volumes.length; i++) {
+
+ if (volumes[i].getId() == null) {
+ // Create a new volume
+ volumes[i] = createVolumeAndSetInClusterContext(volumes[i], iaasProvider);
+ }
+ }
+ }
+ clusterContext.setVolumes(volumes);
+ }
+
+ // Persist member context
+ CloudControllerContext.getInstance().addMemberContext(memberContext);
+ CloudControllerContext.getInstance().persist();
+
+ // Handle member created event
+ TopologyBuilder.handleMemberCreatedEvent(memberContext);
+
+ // Start instance in a new thread
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Starting instance creator thread: [cluster] %s [cluster-instance] %s " +
+ "[member] %s [application-id] %s", instanceContext.getClusterId(),
+ instanceContext.getClusterInstanceId(), memberId, applicationId));
+ }
+ executorService.execute(new InstanceCreator(memberContext, iaasProvider, payload.toString().getBytes()));
+
+ return memberContext;
+ } catch (Exception e) {
+ String msg = String.format("Could not start instance: [cluster] %s [cluster-instance] %s",
+ instanceContext.getClusterId(), instanceContext.getClusterInstanceId());
+ log.error(msg, e);
+ throw new CloudControllerException(msg, e);
+ }
+ }
+
+ private MemberContext createMemberContext(String applicationId, String cartridgeType, String memberId,
+ LoadBalancingIPType loadBalancingIPType,
+ InstanceContext instanceContext) {
+ MemberContext memberContext =
+ new MemberContext(applicationId, cartridgeType, instanceContext.getClusterId(), memberId);
+
+ memberContext.setClusterInstanceId(instanceContext.getClusterInstanceId());
+ memberContext.setNetworkPartitionId(instanceContext.getNetworkPartitionId());
+ memberContext.setPartition(cloudControllerContext.getNetworkPartition(instanceContext.getNetworkPartitionId()).
+ getPartition(instanceContext.getPartition().getId()));
+ memberContext.setInitTime(instanceContext.getInitTime());
+ memberContext.setProperties(instanceContext.getProperties());
+ memberContext.setLoadBalancingIPType(loadBalancingIPType);
+ memberContext.setInitTime(System.currentTimeMillis());
+ memberContext.setObsoleteExpiryTime(instanceContext.getObsoleteExpiryTime());
+
+ return memberContext;
+ }
+
+ private Volume createVolumeAndSetInClusterContext(Volume volume, IaasProvider iaasProvider) {
+ // iaas cannot be null at this state #startInstance method
+ Iaas iaas = iaasProvider.getIaas();
+ int sizeGB = volume.getSize();
+ String snapshotId = volume.getSnapshotId();
+ if (StringUtils.isNotEmpty(volume.getVolumeId())) {
+ // volumeID is specified, so not creating additional volumes
+ if (log.isDebugEnabled()) {
+ log.debug("Volume creation is skipping since a volume ID is specified. [Volume ID] " +
+ volume.getVolumeId());
+ }
+ volume.setId(volume.getVolumeId());
+ } else {
+ String volumeId = iaas.createVolume(sizeGB, snapshotId);
+ volume.setId(volumeId);
+ }
+
+ volume.setIaasType(iaasProvider.getType());
+
+ return volume;
+ }
+
+ private StringBuilder getPersistencePayload(ClusterContext ctx, Iaas iaas) {
+ StringBuilder persistencePayload = new StringBuilder();
+ if (isPersistenceMappingAvailable(ctx)) {
+ for (Volume volume : ctx.getVolumes()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Adding persistence mapping " + volume.toString());
+ }
+ if (persistencePayload.length() != 0) {
+ persistencePayload.append("|");
+ }
+
+ persistencePayload.append(iaas.getIaasDevice(volume.getDevice()));
+ persistencePayload.append("|");
+ persistencePayload.append(volume.getId());
+ persistencePayload.append("|");
+ persistencePayload.append(volume.getMappingPath());
+ }
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Persistence payload: " + persistencePayload.toString());
+ }
+ return persistencePayload;
+ }
+
+ private boolean isPersistenceMappingAvailable(ClusterContext ctx) {
+ return ctx.getVolumes() != null && ctx.isVolumeRequired();
+ }
+
+ private void addToPayload(StringBuilder payload, String name, String value) {
+ payload.append(",");
+ payload.append(name + "=" + value);
+ }
+
+ private void replaceInPayload(String payloadParamName, StringBuilder payload, String name, String value) {
+
+ payload.replace(payload.indexOf(payloadParamName), payload.indexOf(",", payload.indexOf(payloadParamName)),
+ "," + name + "=" + value);
+ }
+
+ private String generateMemberId(String clusterId) {
+ UUID memberId = UUID.randomUUID();
+ return clusterId + memberId.toString();
+ }
+
+ public boolean terminateInstanceForcefully(String memberId) {
+
+ log.info(String.format("Starting to forcefully terminate the member " + memberId));
+ boolean memberTerminated = true;
+ try {
+ this.terminateInstance(memberId);
+ } catch (InvalidMemberException e) {
+ memberTerminated = false;
+ } catch (CloudControllerException e) {
+ memberTerminated = false;
+ } catch (InvalidCartridgeTypeException e) {
+ memberTerminated = false;
+ }
+
+ if (memberTerminated) {
+ log.info(String.format("Member terminated [member-id] %s ", memberId));
+ } else {
+ log.warn(String.format("Stratos could not terminate the member [member-id] %s. This may due to a issue " +
+ "in the underlying IaaS, Please terminate the member manually if it is available",
+ memberId));
+ MemberContext memberContext = CloudControllerContext.getInstance().getMemberContextOfMemberId(memberId);
+ CloudControllerServiceUtil.executeMemberTerminationPostProcess(memberContext);
+ }
+ return true;
+ }
+
+ @Override
+ public boolean terminateInstance(String memberId)
+ throws InvalidMemberException, InvalidCartridgeTypeException, CloudControllerException {
+
+ try {
+ handleNullObject(memberId, "Could not terminate instance, member id is null.");
+
+ MemberContext memberContext = CloudControllerContext.getInstance().getMemberContextOfMemberId(memberId);
+ if (memberContext == null) {
+ String msg = "Could not terminate instance, member context not found: [member-id] " + memberId;
+ log.error(msg);
+ throw new InvalidMemberException(msg);
+ }
+
+ if (StringUtils.isBlank(memberContext.getInstanceId())) {
+ if (log.isErrorEnabled()) {
+ log.error(String.format("Could not terminate instance, instance id is blank: [member-id] %s " +
+ ", removing member from topology...", memberContext.getMemberId()));
+ }
+ CloudControllerServiceUtil.executeMemberTerminationPostProcess(memberContext);
+ }
+
+ // check if status == active, if true, then this is a termination on member faulty
+ TopologyManager.acquireWriteLock();
+ Topology topology = TopologyManager.getTopology();
+ org.apache.stratos.messaging.domain.topology.Service service =
+ topology.getService(memberContext.getCartridgeType());
+
+ if (service != null) {
+ Cluster cluster = service.getCluster(memberContext.getClusterId());
+ if (cluster != null) {
+
<TRUNCATED>
[02/18] stratos git commit: Metering Service Implementation
Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/2fd289b8/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java
index 1275f5c..2a7e5d8 100644
--- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java
+++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java
@@ -18,197 +18,211 @@
*/
package org.apache.stratos.common.constants;
-
public class StratosConstants {
- public static final String CLOUD_SERVICE_IS_ACTIVE_PROP_KEY = "active";
-
- public static final String CLOUD_SERVICE_INFO_STORE_PATH =
- "/repository/components/org.apache.stratos/cloud-manager/cloud-services";
-
- public static final String TENANT_USER_VALIDATION_STORE_PATH =
- "/repository/components/org.wso2.carbon.validations";
- public static final String ADMIN_EMAIL_VERIFICATION_FLAG_PATH =
- "/repository/components/org.wso2.carbon.email-confirmation-flag";
- public static final String TENANT_DOMAIN_VERIFICATION_FLAG_PATH =
- "/repository/components/org.wso2.carbon.domain-confirmation-flag";
-
- public static final String DOMAIN_VALIDATOR_INFO_PATH =
- "/repository/components/org.wso2.carbon.domain-validator-info";
-
- public static final String TENANT_CREATION_THEME_PAGE_TOKEN =
- "/repository/components/org.wso2.carbon.theme-page-token";
-
- public static final String TENANT_PACKAGE_INFO_PATH =
- "/repository/components/org.wso2.carbon.package-info";
-
- public static final String ALL_THEMES_PATH =
- "/repository/components/org.wso2.carbon.all-themes";
-
- public static final String THROTTLING_RULES_PATH =
- "/repository/components/org.wso2.carbon.throttling-rules";
-
- public static final String ORIGINATED_SERVICE_PATH =
- "/repository/components/org.wso2.carbon.originated-service";
-
- public static final String PATH_SEPARATOR = "/";
-
- public static final String CLOUD_SERVICE_ICONS_STORE_PATH =
- "/repository/components/org.wso2.carbon.cloud-manager/" +
- "cloud-services-icons";
-
- public static final String VALIDATION_KEY_RESOURCE_NAME = "validation-key";
- public static final String INCOMING_PATH_DIR = "incoming";
- public static final String OUTGOING_PATH_DIR = "outgoing";
- public static final String MULTITENANCY_SCHEDULED_TASK_ID = "multitenancyScheduledTask";
- public static final String MULTITENANCY_VIEWING_TASK_ID = "multitenancyViewingTask";
-
- public static final String INVALID_TENANT = "invalidTenant";
- public static final String INACTIVE_TENANT = "inactiveTenant";
- public static final String ACTIVE_TENANT = "activeTenant";
- public static final String IS_EMAIL_VALIDATED = "isEmailValidated";
- public static final String IS_CREDENTIALS_ALREADY_RESET = "isCredentialsReset";
- public static final String TENANT_ADMIN = "tenantAdminUsername";
-
- public static final String CLOUD_MANAGER_SERVICE = "Apache Stratos Controller";
- public static final String CLOUD_IDENTITY_SERVICE = "WSO2 Stratos Identity";
- public static final String CLOUD_GOVERNANCE_SERVICE = "WSO2 Stratos Governance";
- public static final String CLOUD_ESB_SERVICE = "WSO2 Stratos Enterprise Service Bus";
-
- // keystore mgt related Constants
- public static final String TENANT_KS = "/repository/security/key-stores/";
- public static final String TENANT_PUB_KEY = "/repository/security/pub-key";
- public static final String PROP_TENANT_KS_TYPE = "key-store-type";
- public static final String PROP_TENANT_KS_PASSWD = "key-store-password";
- public static final String PROP_TENANT_KS_PRIV_KEY_PASSWD = "priv-key-password";
- public static final String PROP_TENANT_KS_ALIAS = "alias";
-
- // constants related to redirection
-
- public static final String UNVERIFIED_ACCOUNT_DOMAIN_SUFFIX = "-unverified";
- public static final String TENANT_SPECIFIC_URL_RESOLVED = "tenant-sepcific-url-resolved";
- public static final String SUFFIXED_UNVERIFIED_SESSION_FLAG = "temp-suffixed-unverified";
-
- // metering constants
- public static final String THROTTLING_ALL_ACTION = "all_actions";
- public static final String THROTTLING_IN_DATA_ACTION = "in_data_action"; //this covers registry capacity + registry bandwidth
- public static final String THROTTLING_OUT_DATA_ACTION = "out_data_action"; //this covers registry bandwidth
- public static final String THROTTLING_ADD_USER_ACTION = "add_user_action";
- public static final String THROTTLING_SERVICE_IN_BANDWIDTH_ACTION = "service_in_bandwith_action";
- public static final String THROTTLING_SERVICE_OUT_BANDWIDTH_ACTION = "service_out_bandwith_action";
- public static final String THROTTLING_WEBAPP_IN_BANDWIDTH_ACTION = "webapp_in_bandwith_action";
- public static final String THROTTLING_WEBAPP_OUT_BANDWIDTH_ACTION = "webapp_out_bandwith_action";
- public static final String THROTTLING_SERVICE_REQUEST_ACTION = "service_request_action";
- public static final String THROTTLING_SERVICE_RESPONSE_ACTION = "service_response_action";
-
- // the session attribute to keep track whether the registry action validated
- // and the usage persisted
- public static final String REGISTRY_ACTION_VALIDATED_SESSION_ATTR = "registryActionValidated";
- public static final String REGISTRY_USAGE_PERSISTED_SESSION_ATTR = "usagePersited";
-
- // Metering servlet attributes
- public static final String SERVICE_NAME_SERVLET_ATTR = "meteringServiceName";
- public static final String TENANT_ID_SERVLET_ATTR = "tenantId";
- public static final String ADMIN_SERVICE_SERVLET_ATTR = "adminService";
-
- // * as a Service impl related constants
- public static final String ORIGINATED_SERVICE = "originatedService";
-
- // Configuration file name
- public static final String STRATOS_CONF_FILE = "stratos.xml";
- //public static final String STRATOS_CONF_LOC = "repository/conf/";
- //public static final String STRATOS_CONF_FILE_WITH_PATH = STRATOS_CONF_LOC + STRATOS_CONF_FILE;
-
- // EULA location
- public static final String STRATOS_EULA = "eula.xml";
-
- // EULA default text.
- public static final String STRATOS_EULA_DEFAULT_TEXT =
- "Please refer to: " + StratosConstants.STRATOS_TERMS_OF_USAGE +
- " for terms and usage and " + StratosConstants.STRATOS_PRIVACY_POLICY +
- " for privacy policy of WSO2 Stratos.";
-
- // Web location of Terms of Usage and privacy policy
- public static final String STRATOS_TERMS_OF_USAGE =
- "http://wso2.com/cloud/services/terms-of-use/";
- public static final String STRATOS_PRIVACY_POLICY =
- "http://wso2.com/cloud/services/privacy-policy/";
- public static final String MULTITENANCY_FREE_PLAN = "Demo";
- public static final String MULTITENANCY_SMALL_PLAN = "SMB";
- public static final String MULTITENANCY_MEDIUM_PLAN = "Professional";
- public static final String MULTITENANCY_LARGE_PLAN = "Enterprise";
- public static final String EMAIL_CONFIG = "email";
- public static final String MULTITENANCY_CONFIG_FOLDER = "multitenancy";
-
- // Cloud controller - payload
- public static final String MEMBER_ID = "MEMBER_ID";
- public static final String LB_CLUSTER_ID = "LB_CLUSTER_ID";
- public static final String NETWORK_PARTITION_ID = "NETWORK_PARTITION_ID";
-
- // Kubernetes related constants
- public static final String KUBERNETES_CLUSTER_ID = "KUBERNETES_CLUSTER_ID";
- public static final String KUBERNETES_MASTER_PORT = "KUBERNETES_MASTER_PORT";
- public static final String KUBERNETES_MASTER_DEFAULT_PORT = "8080";
-
- //drools related constants
- public static final String DROOLS_DIR_NAME = "drools";
- public static final String SCALE_CHECK_DROOL_FILE = "scaling.drl";
- public static final String DEPENDENT_SCALE_CHECK_DROOL_FILE = "dependent-scaling.drl";
- public static final String MIN_CHECK_DROOL_FILE = "mincheck.drl";
- public static final String MAX_CHECK_DROOL_FILE = "maxcheck.drl";
- public static final String OBSOLETE_CHECK_DROOL_FILE = "obsoletecheck.drl";
- public static final String MIN_COUNT = "MIN_COUNT";
-
- // Policy and definition related constants
- public static final int PUBLIC_DEFINITION = 0;
-
- // member expiry timeout constants
- public static final String PENDING_MEMBER_EXPIRY_TIMEOUT = "autoscaler.member.pendingMemberExpiryTimeout";
- public static final String OBSOLETED_MEMBER_EXPIRY_TIMEOUT = "autoscaler.member.obsoletedMemberExpiryTimeout";
- public static final String PENDING_TERMINATION_MEMBER_EXPIRY_TIMEOUT = "autoscaler.member.pendingTerminationMemberExpiryTimeout";
-
- public static final String FILTER_VALUE_SEPARATOR = ",";
- public static final String TOPOLOGY_APPLICATION_FILTER = "stratos.topology.application.filter";
- public static final String TOPOLOGY_SERVICE_FILTER = "stratos.topology.service.filter";
- public static final String TOPOLOGY_CLUSTER_FILTER = "stratos.topology.cluster.filter";
- public static final String TOPOLOGY_MEMBER_FILTER = "stratos.topology.member.filter";
- public static final String TOPOLOGY_NETWORK_PARTITION_FILTER = "stratos.topology.network.partition.filter";
-
- // to identify a lb cluster
- public static final String LOAD_BALANCER_REF = "load.balancer.ref";
- public static final String SERVICE_AWARE_LOAD_BALANCER = "service.aware.load.balancer";
- public static final String DEFAULT_LOAD_BALANCER = "default.load.balancer";
- public static final String NO_LOAD_BALANCER = "no.load.balancer";
- public static final String EXISTING_LOAD_BALANCERS = "existing.load.balancers";
-
- public static final long HAZELCAST_INSTANCE_INIT_TIMEOUT = 300000; // 5 min
-
- public static final String AUTOSCALER_SERVICE_URL = "autoscaler.service.url";
- public static final String CLOUD_CONTROLLER_SERVICE_URL = "cloud.controller.service.url";
- public static final String STRATOS_MANAGER_SERVICE_URL = "stratos.manager.service.url";
-
- public static final String CLOUD_CONTROLLER_CLIENT_SOCKET_TIMEOUT = "cc.socket.timeout";
- public static final String CLOUD_CONTROLLER_CLIENT_CONNECTION_TIMEOUT = "cc.connection.timeout";
- public static final String AUTOSCALER_CLIENT_SOCKET_TIMEOUT = "autoscaler.socket.timeout";
- public static final String AUTOSCALER_CLIENT_CONNECTION_TIMEOUT = "autoscaler.connection.timeout";
- public static final String STRATOS_MANAGER_CLIENT_SOCKET_TIMEOUT = "stratos.manager.socket.timeout";
- public static final String STRATOS_MANAGER_CLIENT_CONNECTION_TIMEOUT = "stratos.manager.connection.timeout";
-
- public static final String DEFAULT_CLIENT_SOCKET_TIMEOUT = "300000";
- public static final String DEFAULT_CLIENT_CONNECTION_TIMEOUT = "300000";
-
- // partition algorithm id constants
- public static final String PARTITION_ROUND_ROBIN_ALGORITHM_ID = "round-robin";
- public static final String PARTITION_WEIGHTED_ROUND_ROBIN_ALGORITHM_ID = "weighted-round-robin";
- public static final String PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID = "one-after-another";
- // network partition algorithm id constants
- public static final String NETWORK_PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID = "one-after-another";
- public static final String NETWORK_PARTITION_ALL_AT_ONCE_ALGORITHM_ID = "all-at-once";
- public static final String APPLICATION_POLICY_NETWORK_PARTITION_GROUPS = "networkPartitionGroups";
- public static final String APPLICATION_POLICY_NETWORK_PARTITIONS_SPLITTER = "\\|";
- public static final String APPLICATION_POLICY_NETWORK_PARTITION_GROUPS_SPLITTER = ",";
-
- public static final String NOT_DEFINED = "not-defined";
- public static final String CLUSTER_INSTANCE_ID = "cluster.instance.id";
+ public static final String CLOUD_SERVICE_IS_ACTIVE_PROP_KEY = "active";
+
+ public static final String CLOUD_SERVICE_INFO_STORE_PATH =
+ "/repository/components/org.apache.stratos/cloud-manager/cloud-services";
+
+ public static final String TENANT_USER_VALIDATION_STORE_PATH =
+ "/repository/components/org.wso2.carbon.validations";
+ public static final String ADMIN_EMAIL_VERIFICATION_FLAG_PATH =
+ "/repository/components/org.wso2.carbon.email-confirmation-flag";
+ public static final String TENANT_DOMAIN_VERIFICATION_FLAG_PATH =
+ "/repository/components/org.wso2.carbon.domain-confirmation-flag";
+
+ public static final String DOMAIN_VALIDATOR_INFO_PATH =
+ "/repository/components/org.wso2.carbon.domain-validator-info";
+
+ public static final String TENANT_CREATION_THEME_PAGE_TOKEN =
+ "/repository/components/org.wso2.carbon.theme-page-token";
+
+ public static final String TENANT_PACKAGE_INFO_PATH =
+ "/repository/components/org.wso2.carbon.package-info";
+
+ public static final String ALL_THEMES_PATH =
+ "/repository/components/org.wso2.carbon.all-themes";
+
+ public static final String THROTTLING_RULES_PATH =
+ "/repository/components/org.wso2.carbon.throttling-rules";
+
+ public static final String ORIGINATED_SERVICE_PATH =
+ "/repository/components/org.wso2.carbon.originated-service";
+
+ public static final String PATH_SEPARATOR = "/";
+
+ public static final String CLOUD_SERVICE_ICONS_STORE_PATH =
+ "/repository/components/org.wso2.carbon.cloud-manager/" + "cloud-services-icons";
+
+ public static final String VALIDATION_KEY_RESOURCE_NAME = "validation-key";
+ public static final String INCOMING_PATH_DIR = "incoming";
+ public static final String OUTGOING_PATH_DIR = "outgoing";
+ public static final String MULTITENANCY_SCHEDULED_TASK_ID = "multitenancyScheduledTask";
+ public static final String MULTITENANCY_VIEWING_TASK_ID = "multitenancyViewingTask";
+
+ public static final String INVALID_TENANT = "invalidTenant";
+ public static final String INACTIVE_TENANT = "inactiveTenant";
+ public static final String ACTIVE_TENANT = "activeTenant";
+ public static final String IS_EMAIL_VALIDATED = "isEmailValidated";
+ public static final String IS_CREDENTIALS_ALREADY_RESET = "isCredentialsReset";
+ public static final String TENANT_ADMIN = "tenantAdminUsername";
+
+ public static final String CLOUD_MANAGER_SERVICE = "Apache Stratos Controller";
+ public static final String CLOUD_IDENTITY_SERVICE = "WSO2 Stratos Identity";
+ public static final String CLOUD_GOVERNANCE_SERVICE = "WSO2 Stratos Governance";
+ public static final String CLOUD_ESB_SERVICE = "WSO2 Stratos Enterprise Service Bus";
+
+ // keystore mgt related Constants
+ public static final String TENANT_KS = "/repository/security/key-stores/";
+ public static final String TENANT_PUB_KEY = "/repository/security/pub-key";
+ public static final String PROP_TENANT_KS_TYPE = "key-store-type";
+ public static final String PROP_TENANT_KS_PASSWD = "key-store-password";
+ public static final String PROP_TENANT_KS_PRIV_KEY_PASSWD = "priv-key-password";
+ public static final String PROP_TENANT_KS_ALIAS = "alias";
+
+ // constants related to redirection
+
+ public static final String UNVERIFIED_ACCOUNT_DOMAIN_SUFFIX = "-unverified";
+ public static final String TENANT_SPECIFIC_URL_RESOLVED = "tenant-sepcific-url-resolved";
+ public static final String SUFFIXED_UNVERIFIED_SESSION_FLAG = "temp-suffixed-unverified";
+
+ // metering constants
+ public static final String THROTTLING_ALL_ACTION = "all_actions";
+ public static final String THROTTLING_IN_DATA_ACTION = "in_data_action";
+ //this covers registry capacity + registry bandwidth
+ public static final String THROTTLING_OUT_DATA_ACTION = "out_data_action";
+ //this covers registry bandwidth
+ public static final String THROTTLING_ADD_USER_ACTION = "add_user_action";
+ public static final String THROTTLING_SERVICE_IN_BANDWIDTH_ACTION =
+ "service_in_bandwith_action";
+ public static final String THROTTLING_SERVICE_OUT_BANDWIDTH_ACTION =
+ "service_out_bandwith_action";
+ public static final String THROTTLING_WEBAPP_IN_BANDWIDTH_ACTION = "webapp_in_bandwith_action";
+ public static final String THROTTLING_WEBAPP_OUT_BANDWIDTH_ACTION =
+ "webapp_out_bandwith_action";
+ public static final String THROTTLING_SERVICE_REQUEST_ACTION = "service_request_action";
+ public static final String THROTTLING_SERVICE_RESPONSE_ACTION = "service_response_action";
+
+ // the session attribute to keep track whether the registry action validated
+ // and the usage persisted
+ public static final String REGISTRY_ACTION_VALIDATED_SESSION_ATTR = "registryActionValidated";
+ public static final String REGISTRY_USAGE_PERSISTED_SESSION_ATTR = "usagePersited";
+
+ // Metering servlet attributes
+ public static final String SERVICE_NAME_SERVLET_ATTR = "meteringServiceName";
+ public static final String TENANT_ID_SERVLET_ATTR = "tenantId";
+ public static final String ADMIN_SERVICE_SERVLET_ATTR = "adminService";
+
+ // * as a Service impl related constants
+ public static final String ORIGINATED_SERVICE = "originatedService";
+
+ // Configuration file name
+ public static final String STRATOS_CONF_FILE = "stratos.xml";
+ //public static final String STRATOS_CONF_LOC = "repository/conf/";
+ //public static final String STRATOS_CONF_FILE_WITH_PATH = STRATOS_CONF_LOC + STRATOS_CONF_FILE;
+
+ // EULA location
+ public static final String STRATOS_EULA = "eula.xml";
+
+ // EULA default text.
+ public static final String STRATOS_EULA_DEFAULT_TEXT =
+ "Please refer to: " + StratosConstants.STRATOS_TERMS_OF_USAGE +
+ " for terms and usage and " + StratosConstants.STRATOS_PRIVACY_POLICY +
+ " for privacy policy of WSO2 Stratos.";
+
+ // Web location of Terms of Usage and privacy policy
+ public static final String STRATOS_TERMS_OF_USAGE =
+ "http://wso2.com/cloud/services/terms-of-use/";
+ public static final String STRATOS_PRIVACY_POLICY =
+ "http://wso2.com/cloud/services/privacy-policy/";
+ public static final String MULTITENANCY_FREE_PLAN = "Demo";
+ public static final String MULTITENANCY_SMALL_PLAN = "SMB";
+ public static final String MULTITENANCY_MEDIUM_PLAN = "Professional";
+ public static final String MULTITENANCY_LARGE_PLAN = "Enterprise";
+ public static final String EMAIL_CONFIG = "email";
+ public static final String MULTITENANCY_CONFIG_FOLDER = "multitenancy";
+
+ // Cloud controller - payload
+ public static final String MEMBER_ID = "MEMBER_ID";
+ public static final String LB_CLUSTER_ID = "LB_CLUSTER_ID";
+ public static final String NETWORK_PARTITION_ID = "NETWORK_PARTITION_ID";
+
+ // Kubernetes related constants
+ public static final String KUBERNETES_CLUSTER_ID = "KUBERNETES_CLUSTER_ID";
+ public static final String KUBERNETES_MASTER_PORT = "KUBERNETES_MASTER_PORT";
+ public static final String KUBERNETES_MASTER_DEFAULT_PORT = "8080";
+
+ //drools related constants
+ public static final String DROOLS_DIR_NAME = "drools";
+ public static final String SCALE_CHECK_DROOL_FILE = "scaling.drl";
+ public static final String DEPENDENT_SCALE_CHECK_DROOL_FILE = "dependent-scaling.drl";
+ public static final String MIN_CHECK_DROOL_FILE = "mincheck.drl";
+ public static final String MAX_CHECK_DROOL_FILE = "maxcheck.drl";
+ public static final String OBSOLETE_CHECK_DROOL_FILE = "obsoletecheck.drl";
+ public static final String MIN_COUNT = "MIN_COUNT";
+ public static final String SCALING_REASON = "SCALING_REASON";
+ public static final String SCALING_TIME = "SCALING_TIME";
+
+ // Policy and definition related constants
+ public static final int PUBLIC_DEFINITION = 0;
+
+ // member expiry timeout constants
+ public static final String PENDING_MEMBER_EXPIRY_TIMEOUT =
+ "autoscaler.member.pendingMemberExpiryTimeout";
+ public static final String OBSOLETED_MEMBER_EXPIRY_TIMEOUT =
+ "autoscaler.member.obsoletedMemberExpiryTimeout";
+ public static final String PENDING_TERMINATION_MEMBER_EXPIRY_TIMEOUT =
+ "autoscaler.member.pendingTerminationMemberExpiryTimeout";
+
+ public static final String FILTER_VALUE_SEPARATOR = ",";
+ public static final String TOPOLOGY_APPLICATION_FILTER = "stratos.topology.application.filter";
+ public static final String TOPOLOGY_SERVICE_FILTER = "stratos.topology.service.filter";
+ public static final String TOPOLOGY_CLUSTER_FILTER = "stratos.topology.cluster.filter";
+ public static final String TOPOLOGY_MEMBER_FILTER = "stratos.topology.member.filter";
+ public static final String TOPOLOGY_NETWORK_PARTITION_FILTER =
+ "stratos.topology.network.partition.filter";
+
+ // to identify a lb cluster
+ public static final String LOAD_BALANCER_REF = "load.balancer.ref";
+ public static final String SERVICE_AWARE_LOAD_BALANCER = "service.aware.load.balancer";
+ public static final String DEFAULT_LOAD_BALANCER = "default.load.balancer";
+ public static final String NO_LOAD_BALANCER = "no.load.balancer";
+ public static final String EXISTING_LOAD_BALANCERS = "existing.load.balancers";
+
+ public static final long HAZELCAST_INSTANCE_INIT_TIMEOUT = 300000; // 5 min
+
+ public static final String AUTOSCALER_SERVICE_URL = "autoscaler.service.url";
+ public static final String CLOUD_CONTROLLER_SERVICE_URL = "cloud.controller.service.url";
+ public static final String STRATOS_MANAGER_SERVICE_URL = "stratos.manager.service.url";
+
+ public static final String CLOUD_CONTROLLER_CLIENT_SOCKET_TIMEOUT = "cc.socket.timeout";
+ public static final String CLOUD_CONTROLLER_CLIENT_CONNECTION_TIMEOUT = "cc.connection.timeout";
+ public static final String AUTOSCALER_CLIENT_SOCKET_TIMEOUT = "autoscaler.socket.timeout";
+ public static final String AUTOSCALER_CLIENT_CONNECTION_TIMEOUT =
+ "autoscaler.connection.timeout";
+ public static final String STRATOS_MANAGER_CLIENT_SOCKET_TIMEOUT =
+ "stratos.manager.socket.timeout";
+ public static final String STRATOS_MANAGER_CLIENT_CONNECTION_TIMEOUT =
+ "stratos.manager.connection.timeout";
+
+ public static final String DEFAULT_CLIENT_SOCKET_TIMEOUT = "300000";
+ public static final String DEFAULT_CLIENT_CONNECTION_TIMEOUT = "300000";
+
+ // partition algorithm id constants
+ public static final String PARTITION_ROUND_ROBIN_ALGORITHM_ID = "round-robin";
+ public static final String PARTITION_WEIGHTED_ROUND_ROBIN_ALGORITHM_ID = "weighted-round-robin";
+ public static final String PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID = "one-after-another";
+ // network partition algorithm id constants
+ public static final String NETWORK_PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID =
+ "one-after-another";
+ public static final String NETWORK_PARTITION_ALL_AT_ONCE_ALGORITHM_ID = "all-at-once";
+ public static final String APPLICATION_POLICY_NETWORK_PARTITION_GROUPS =
+ "networkPartitionGroups";
+ public static final String APPLICATION_POLICY_NETWORK_PARTITIONS_SPLITTER = "\\|";
+ public static final String APPLICATION_POLICY_NETWORK_PARTITION_GROUPS_SPLITTER = ",";
+
+ public static final String NOT_DEFINED = "not-defined";
+ public static final String CLUSTER_INSTANCE_ID = "cluster.instance.id";
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/2fd289b8/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/healthstatspublisher/healthstats.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/healthstatspublisher/healthstats.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/healthstatspublisher/healthstats.py
index 9753c3e..711fe43 100644
--- a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/healthstatspublisher/healthstats.py
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/healthstatspublisher/healthstats.py
@@ -17,7 +17,7 @@
from threading import Thread
import multiprocessing
-
+import time
import psutil
from abstracthealthstatisticspublisher import *
@@ -124,6 +124,8 @@ class HealthStatisticsPublisher:
stream_def.description = HealthStatisticsPublisherManager.STREAM_DESCRIPTION
# stream_def.add_payloaddata_attribute()
+
+ #stream_def.add_payloaddata_attribute("time_stamp", StreamDefinition.LONG)
stream_def.add_payloaddata_attribute("cluster_id", StreamDefinition.STRING)
stream_def.add_payloaddata_attribute("cluster_instance_id", StreamDefinition.STRING)
stream_def.add_payloaddata_attribute("network_partition_id", StreamDefinition.STRING)
@@ -141,6 +143,7 @@ class HealthStatisticsPublisher:
"""
event = ThriftEvent()
+ #event.payloadData.append(int(round(time.time() * 1000)))
event.payloadData.append(self.cartridge_agent_config.cluster_id)
event.payloadData.append(self.cartridge_agent_config.cluster_instance_id)
event.payloadData.append(self.cartridge_agent_config.network_partition_id)
@@ -159,6 +162,7 @@ class HealthStatisticsPublisher:
"""
event = ThriftEvent()
+ #Sevent.payloadData.append(int(round(time.time() * 1000)))
event.payloadData.append(self.cartridge_agent_config.cluster_id)
event.payloadData.append(self.cartridge_agent_config.cluster_instance_id)
event.payloadData.append(self.cartridge_agent_config.network_partition_id)
http://git-wip-us.apache.org/repos/asf/stratos/blob/2fd289b8/extensions/cep/artifacts/streamdefinitions/stream-manager-config.xml
----------------------------------------------------------------------
diff --git a/extensions/cep/artifacts/streamdefinitions/stream-manager-config.xml b/extensions/cep/artifacts/streamdefinitions/stream-manager-config.xml
index 4c4c7e0..39fc4f3 100644
--- a/extensions/cep/artifacts/streamdefinitions/stream-manager-config.xml
+++ b/extensions/cep/artifacts/streamdefinitions/stream-manager-config.xml
@@ -23,287 +23,289 @@
<streamManagerConfiguration xmlns="http://wso2.org/carbon/streammanager">
<!-- in-flight requests stream definitions start -->
<streamDefinition name="in_flight_requests" version="1.0.0">
- <description>in-flight request count</description>
- <nickName>in-flight requests</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String"/>
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="in_flight_request_count" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>in-flight request count</description>
+ <nickName>in-flight requests</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <!-- <property name="time_stamp" type="long"/>-->
+ <property name="cluster_id" type="String"/>
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="in_flight_request_count" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="gradient_in_flight_requests" version="1.0.0">
- <description>gradient of in flight request count</description>
- <nickName>gradient in flight requests</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String"/>
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="count" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>gradient of in flight request count</description>
+ <nickName>gradient in flight requests</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="cluster_id" type="String"/>
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="count" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="average_in_flight_requests" version="1.0.0">
- <description>average of in-flight request count</description>
- <nickName>average in-flight requests</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String"/>
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="count" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>average of in-flight request count</description>
+ <nickName>average in-flight requests</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="cluster_id" type="String"/>
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="count" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="second_derivative_in_flight_requests" version="1.0.0">
- <description>second derivative of in-flight request count</description>
- <nickName>second derivative in-flight requests</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String"/>
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="count" type="double"/>
- </payloadData>
+ <description>second derivative of in-flight request count</description>
+ <nickName>second derivative in-flight requests</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="cluster_id" type="String"/>
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="count" type="double"/>
+ </payloadData>
</streamDefinition>
<!-- in-flight requests stream definitions end -->
<!-- cartridge agent health stats stream definitions start -->
<streamDefinition name="cartridge_agent_health_stats" version="1.0.0">
- <description>agent health stats</description>
- <nickName>agent health stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="member_id" type="String" />
- <property name="partition_id" type="String" />
- <property name="health_description" type="String"/>
- <property name="value" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>agent health stats</description>
+ <nickName>agent health stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <!--<property name="time_stamp" type="long"/>-->
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="member_id" type="String" />
+ <property name="partition_id" type="String" />
+ <property name="health_description" type="String"/>
+ <property name="value" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="average_load_average_stats" version="1.0.0">
- <description>average load average stats</description>
- <nickName>average load average stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="average_load_average" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>average load average stats</description>
+ <nickName>average load average stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="average_load_average" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="average_memory_consumption_stats" version="1.0.0">
- <description>average memory consumption stats</description>
- <nickName>average memory consumption stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String"/>
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="average_memory_consumption" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>average memory consumption stats</description>
+ <nickName>average memory consumption stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="cluster_id" type="String"/>
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="average_memory_consumption" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="gradient_load_average_stats" version="1.0.0">
- <description>gradient load average stats</description>
- <nickName>gradient load average stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="gradient_load_average" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>gradient load average stats</description>
+ <nickName>gradient load average stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="gradient_load_average" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="gradient_memory_consumption_stats" version="1.0.0">
- <description>gradient memoryconsumption stats</description>
- <nickName>gradient memoryconsumption stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="gradient_memory_consumption" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>gradient memoryconsumption stats</description>
+ <nickName>gradient memoryconsumption stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="gradient_memory_consumption" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="second_derivative_memory_consumption_stats" version="1.0.0">
- <description>second derivative memory consumption stats</description>
- <nickName>second derivative memory consumption stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="second_derivative_memory_consumption" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>second derivative memory consumption stats</description>
+ <nickName>second derivative memory consumption stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="second_derivative_memory_consumption" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="second_derivative_load_average_stats" version="1.0.0">
- <description>second derivative load average stats</description>
- <nickName>second derivative load average stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="second_derivative_load_average" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>second derivative load average stats</description>
+ <nickName>second derivative load average stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="second_derivative_load_average" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="fault_message" version="1.0.0">
- <description>fault message</description>
- <nickName>fault message</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="cluster_id" type="String"/>
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="member_id" type="String"/>
- <property name="partition_id" type="String"/>
- </payloadData>
+ <description>fault message</description>
+ <nickName>fault message</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="cluster_id" type="String"/>
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="member_id" type="String"/>
+ <property name="partition_id" type="String"/>
+ </payloadData>
</streamDefinition>
<!-- cartridge agent health stats stream definitions end -->
<!-- This is for member_id wise grouping-->
<streamDefinition name="member_average_load_average_stats" version="1.0.0">
- <description>average load average stats</description>
- <nickName>average load average stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="member_id" type="String" />
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="member_average_load_average" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>average load average stats</description>
+ <nickName>average load average stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="member_id" type="String" />
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="member_average_load_average" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="member_average_memory_consumption_stats" version="1.0.0">
- <description>average memory consumption stats</description>
- <nickName>average memory consumption stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="member_id" type="String"/>
- <property name="cluster_id" type="String"/>
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="member_average_memory_consumption" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>average memory consumption stats</description>
+ <nickName>average memory consumption stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="member_id" type="String"/>
+ <property name="cluster_id" type="String"/>
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="member_average_memory_consumption" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="member_gradient_load_average_stats" version="1.0.0">
- <description>gradient load average stats</description>
- <nickName>gradient load average stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="member_id" type="String" />
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="member_gradient_load_average" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>gradient load average stats</description>
+ <nickName>gradient load average stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="member_id" type="String" />
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="member_gradient_load_average" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="member_gradient_memory_consumption_stats" version="1.0.0">
- <description>gradient memoryconsumption stats</description>
- <nickName>gradient memoryconsumption stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="member_id" type="String" />
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="member_gradient_memory_consumption" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>gradient memoryconsumption stats</description>
+ <nickName>gradient memoryconsumption stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="member_id" type="String" />
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="member_gradient_memory_consumption" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="member_second_derivative_memory_consumption_stats" version="1.0.0">
- <description>second derivative memory consumption stats</description>
- <nickName>second derivative memory consumption stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="member_id" type="String" />
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="member_second_derivative_memory_consumption" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>second derivative memory consumption stats</description>
+ <nickName>second derivative memory consumption stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="member_id" type="String" />
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="member_second_derivative_memory_consumption" type="double"/>
+ </payloadData>
+ </streamDefinition>
<streamDefinition name="member_second_derivative_load_average_stats" version="1.0.0">
- <description>second derivative load average stats</description>
- <nickName>second derivative load average stats</nickName>
- <metaData>
- </metaData>
- <correlationData>
- </correlationData>
- <payloadData>
- <property name="member_id" type="String" />
- <property name="cluster_id" type="String" />
- <property name="cluster_instance_id" type="String"/>
- <property name="network_partition_id" type="String"/>
- <property name="member_second_derivative_load_average" type="double"/>
- </payloadData>
- </streamDefinition>
+ <description>second derivative load average stats</description>
+ <nickName>second derivative load average stats</nickName>
+ <metaData>
+ </metaData>
+ <correlationData>
+ </correlationData>
+ <payloadData>
+ <property name="member_id" type="String" />
+ <property name="cluster_id" type="String" />
+ <property name="cluster_instance_id" type="String"/>
+ <property name="network_partition_id" type="String"/>
+ <property name="member_second_derivative_load_average" type="double"/>
+ </payloadData>
+ </streamDefinition>
</streamManagerConfiguration>
http://git-wip-us.apache.org/repos/asf/stratos/blob/2fd289b8/products/stratos/modules/distribution/src/main/conf/drools/dependent-scaling.drl
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/conf/drools/dependent-scaling.drl b/products/stratos/modules/distribution/src/main/conf/drools/dependent-scaling.drl
index 56e9164..3d373bb 100644
--- a/products/stratos/modules/distribution/src/main/conf/drools/dependent-scaling.drl
+++ b/products/stratos/modules/distribution/src/main/conf/drools/dependent-scaling.drl
@@ -84,7 +84,9 @@ dialect "mvel"
log.info("[dependency-scale] [scale-up] Partition available, hence trying to spawn an instance to scale up!" );
log.debug("[dependency-scale] [scale-up] " + " [partition] " + partitionContext.getPartitionId() + " [cluster] " + clusterId );
- delegator.delegateSpawn(partitionContext, clusterId, clusterInstanceContext.getId(), isPrimary);
+ long time = System.currentTimeMillis();
+ String scalingReason = "Dependency scaling";
+ delegator.delegateSpawn(partitionContext, clusterId, clusterInstanceContext.getId(), isPrimary,scalingReason,time);
count++;
} else {
partitionsAvailable = false;
http://git-wip-us.apache.org/repos/asf/stratos/blob/2fd289b8/products/stratos/modules/distribution/src/main/conf/drools/mincheck.drl
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/conf/drools/mincheck.drl b/products/stratos/modules/distribution/src/main/conf/drools/mincheck.drl
index 96b60da..00a1850 100755
--- a/products/stratos/modules/distribution/src/main/conf/drools/mincheck.drl
+++ b/products/stratos/modules/distribution/src/main/conf/drools/mincheck.drl
@@ -84,7 +84,9 @@ dialect "mvel"
log.info("[min-check] Partition available, hence trying to spawn an instance to fulfil minimum count!" + " [cluster] " + clusterId);
log.debug("[min-check] " + " [partition] " + partitionContext.getPartitionId() + " [cluster] " + clusterId);
- delegator.delegateSpawn(partitionContext, clusterId, clusterInstanceContext.getId(), isPrimary);
+ long time = System.currentTimeMillis();
+ String scalingReason = "Scaling up to fulfil minimum count";
+ delegator.delegateSpawn(partitionContext, clusterId, clusterInstanceContext.getId(), isPrimary,scalingReason,time);
count++;
} else {
http://git-wip-us.apache.org/repos/asf/stratos/blob/2fd289b8/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl b/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl
index e6f8f67..167711f 100644
--- a/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl
+++ b/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl
@@ -69,7 +69,7 @@ dialect "mvel"
eval(log.debug("[scaling] [network-partition] " + clusterInstanceContext.getNetworkPartitionId() + " [cluster] "
+ clusterId + " Algorithm name: " + algorithmName))
-
+
rifThreshold : Float() from loadThresholds.getRequestsInFlightThreshold()
rifAverage : Float() from clusterInstanceContext.getAverageRequestsInFlight()
@@ -163,6 +163,7 @@ dialect "mvel"
boolean partitionsAvailable = true;
int count = 0;
+ String autoscalingReason = (numberOfRequiredInstances == numberOfInstancesReuquiredBasedOnRif)?"Scaling up due to RIF":(numberOfRequiredInstances== numberOfInstancesReuquiredBasedOnMemoryConsumption)?"Scaling up due to MC":"Scaling up due to LA";
while(count != additionalInstances && partitionsAvailable){
@@ -182,7 +183,8 @@ dialect "mvel"
" [laPredictedValue] " + laPredictedValue + " [laThreshold] " + laThreshold);
log.debug("[scale-up] " + " [partition] " + partitionContext.getPartitionId() + " [cluster] " + clusterId );
- delegator.delegateSpawn(partitionContext, clusterId, clusterInstanceContext.getId(), isPrimary);
+ long scalingTime = System.currentTimeMillis();
+ delegator.delegateSpawn(partitionContext, clusterId, clusterInstanceContext.getId(), isPrimary,autoscalingReason,scalingTime);
count++;
} else {
@@ -195,12 +197,9 @@ dialect "mvel"
}
}
} else {
- log.info("[scale-up] Trying to scale up over max, hence not scaling up cluster itself and
- notifying to parent for possible group scaling or app bursting.
- [cluster] " + clusterId + " [instance id]" + clusterInstanceContext.getId() +
+ log.info("[scale-up] Trying to scale up over max, hence not scaling up cluster itself and notifying to parent for possible group scaling or app bursting. [cluster] " + clusterId + " [instance id]" + clusterInstanceContext.getId() +
" [max] " + clusterMaxMembers);
- delegator.delegateScalingOverMaxNotification(clusterId, clusterInstanceContext.getNetworkPartitionId(),
- clusterInstanceContext.getId());
+ delegator.delegateScalingOverMaxNotification(clusterId, clusterInstanceContext.getNetworkPartitionId(),clusterInstanceContext.getId());
}
} else if(scaleDown){
[08/18] stratos git commit: Publishing events for Metering Service
Implementation
Posted by im...@apache.org.
Publishing events for Metering Service Implementation
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/76c7724b
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/76c7724b
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/76c7724b
Branch: refs/heads/master
Commit: 76c7724b6f248e48b14ba2ea69e6e919291b4194
Parents: 00ed5fa
Author: Thanuja <th...@wso2.com>
Authored: Wed Jul 22 16:28:56 2015 +0530
Committer: Thanuja <th...@wso2.com>
Committed: Wed Jul 22 16:28:56 2015 +0530
----------------------------------------------------------------------
.../client/AutoscalerCloudControllerClient.java | 391 +--
.../autoscaler/rule/RuleTasksDelegator.java | 690 ++--
.../messaging/topology/TopologyBuilder.java | 2002 ++++++-----
.../impl/CloudControllerServiceImpl.java | 3155 +++++++++---------
.../impl/CloudControllerServiceUtil.java | 132 +-
.../services/impl/InstanceCreator.java | 11 -
.../publisher/BAMUsageDataPublisher.java | 343 +-
.../util/CloudControllerConstants.java | 504 ++-
.../common/constants/StratosConstants.java | 375 +--
.../src/main/conf/drools/dependent-scaling.drl | 5 +-
.../src/main/conf/drools/scaling.drl | 6 +-
11 files changed, 3802 insertions(+), 3812 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/76c7724b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/AutoscalerCloudControllerClient.java
----------------------------------------------------------------------
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 f944a9f..67fd956 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
@@ -48,194 +48,205 @@ import java.util.List;
*/
public class AutoscalerCloudControllerClient {
- private static final Log log = LogFactory.getLog(AutoscalerCloudControllerClient.class);
-
- 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();
- int port = conf.getInt("autoscaler.cloudController.port", AutoscalerConstants.CLOUD_CONTROLLER_DEFAULT_PORT);
- String hostname = conf.getString("autoscaler.cloudController.hostname", "localhost");
- String epr = "https://" + hostname + ":" + port + "/" + AutoscalerConstants.CLOUD_CONTROLLER_SERVICE_SFX;
- int cloudControllerClientTimeout = conf.getInt("autoscaler.cloudController.clientTimeout", 180000);
-
- stub = new CloudControllerServiceStub(epr);
- stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, cloudControllerClientTimeout);
- stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT,
- cloudControllerClientTimeout);
- } catch (Exception e) {
- log.error("Could not initialize cloud controller client", e);
- }
- }
-
- public synchronized MemberContext startInstance(PartitionRef partition,
- String clusterId, String clusterInstanceId,
- String networkPartitionId, boolean isPrimary,
- int minMemberCount) throws SpawningException {
- try {
- if (log.isInfoEnabled()) {
- log.info(String.format("Trying to spawn an instance via cloud controller: " +
- "[cluster] %s [partition] %s [network-partition-id] %s",
- clusterId, partition.getId(), networkPartitionId));
- }
-
- XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
- long expiryTime = conf.getLong(StratosConstants.OBSOLETED_MEMBER_EXPIRY_TIMEOUT, 86400000);
- if (log.isDebugEnabled()) {
- log.debug("Member obsolete expiry time is set to: " + expiryTime);
- }
-
- InstanceContext instanceContext = new InstanceContext();
- instanceContext.setClusterId(clusterId);
- instanceContext.setClusterInstanceId(clusterInstanceId);
- instanceContext.setPartition(AutoscalerObjectConverter.convertPartitionToCCPartition(partition));
- instanceContext.setInitTime(System.currentTimeMillis());
- instanceContext.setObsoleteExpiryTime(expiryTime);
- instanceContext.setNetworkPartitionId(networkPartitionId);
-
- Properties memberContextProps = new Properties();
- Property isPrimaryProp = new Property();
- isPrimaryProp.setName("PRIMARY");
- isPrimaryProp.setValue(String.valueOf(isPrimary));
-
- Property minCountProp = new Property();
- minCountProp.setName(StratosConstants.MIN_COUNT);
- minCountProp.setValue(String.valueOf(minMemberCount));
-
- memberContextProps.addProperty(isPrimaryProp);
- memberContextProps.addProperty(minCountProp);
- instanceContext.setProperties(AutoscalerUtil.toStubProperties(memberContextProps));
-
- long startTime = System.currentTimeMillis();
- MemberContext memberContext = stub.startInstance(instanceContext);
-
- if (log.isDebugEnabled()) {
- long endTime = System.currentTimeMillis();
- log.debug(String.format("Service call startInstance() returned in %dms", (endTime - startTime)));
- }
- return memberContext;
- } catch (CloudControllerServiceCartridgeNotFoundExceptionException e) {
- String message = e.getFaultMessage().getCartridgeNotFoundException().getMessage();
- log.error(message, e);
- throw new SpawningException(message, e);
- } catch (RemoteException e) {
- log.error(e.getMessage(), e);
- throw new SpawningException(e.getMessage(), e);
- } catch (CloudControllerServiceInvalidIaasProviderExceptionException e) {
- String message = e.getFaultMessage().getInvalidIaasProviderException().getMessage();
- log.error(message, e);
- throw new SpawningException(message, e);
- } catch (CloudControllerServiceCloudControllerExceptionException e) {
- String message = e.getMessage();
- log.error(message, e);
- throw new SpawningException(message, e);
- }
- }
-
- public synchronized void createApplicationClusters(String appId,
- ApplicationClusterContext[] applicationClusterContexts) {
- List<org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext> contextDTOs =
- new ArrayList<org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext>();
- if (applicationClusterContexts != null) {
- for (ApplicationClusterContext applicationClusterContext : applicationClusterContexts) {
- if (applicationClusterContext != null) {
- org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext dto =
- new org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext();
- dto.setClusterId(applicationClusterContext.getClusterId());
- dto.setAutoscalePolicyName(applicationClusterContext.getAutoscalePolicyName());
- dto.setDeploymentPolicyName(applicationClusterContext.getDeploymentPolicyName());
- dto.setCartridgeType(applicationClusterContext.getCartridgeType());
- dto.setHostName(applicationClusterContext.getHostName());
- dto.setTenantRange(applicationClusterContext.getTenantRange());
- dto.setTextPayload(applicationClusterContext.getTextPayload());
- dto.setProperties(AutoscalerUtil.toStubProperties(applicationClusterContext.getProperties()));
- dto.setDependencyClusterIds(applicationClusterContext.getDependencyClusterIds());
- if (applicationClusterContext.getPersistenceContext() != null) {
- dto.setVolumeRequired(true);
- dto.setVolumes(convertVolumesToStubVolumes(
- applicationClusterContext.getPersistenceContext().getVolumes()));
- }
- contextDTOs.add(dto);
- }
- }
- }
-
- org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext[] applicationClusterContextDTOs =
- new org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext[contextDTOs.size()];
- contextDTOs.toArray(applicationClusterContextDTOs);
- try {
- stub.createApplicationClusters(appId, applicationClusterContextDTOs);
- } catch (RemoteException e) {
- String msg = e.getMessage();
- log.error(msg, e);
- } catch (CloudControllerServiceApplicationClusterRegistrationExceptionException e) {
- String msg = e.getMessage();
- log.error(msg, e);
- }
- }
-
-
- private Volume[] convertVolumesToStubVolumes(VolumeContext[] volumeContexts) {
-
- ArrayList<Volume> volumes = new ArrayList<Volume>();
- for (VolumeContext volumeContext : volumeContexts) {
- Volume volume = new Volume();
- volume.setRemoveOntermination(volumeContext.isRemoveOntermination());
- volume.setMappingPath(volumeContext.getMappingPath());
- volume.setId(volumeContext.getId());
- volume.setDevice(volumeContext.getDevice());
- volume.setIaasType(volumeContext.getIaasType());
- volume.setSnapshotId(volumeContext.getSnapshotId());
- volume.setVolumeId(volumeContext.getVolumeId());
- volume.setSize(volumeContext.getSize());
- volumes.add(volume);
- }
- return volumes.toArray(new Volume[volumes.size()]);
- }
-
- public void terminateInstance(String memberId) throws Exception {
- if (log.isInfoEnabled()) {
- log.info(String.format("Terminating instance via cloud controller: [member] %s", memberId));
- }
- long startTime = System.currentTimeMillis();
- stub.terminateInstance(memberId);
- if (log.isDebugEnabled()) {
- long endTime = System.currentTimeMillis();
- log.debug(String.format("Service call terminateInstance() returned in %dms", (endTime - startTime)));
- }
- }
-
- public void terminateInstanceForcefully(String memberId) throws Exception {
- if (log.isDebugEnabled()) {
- log.debug(String.format("Terminating instance forcefully via cloud controller: [member] %s", memberId));
- }
- stub.terminateInstanceForcefully(memberId);
- }
-
- public void terminateAllInstances(String clusterId) throws RemoteException,
- CloudControllerServiceInvalidClusterExceptionException {
- if (log.isInfoEnabled()) {
- log.info(String.format("Terminating all instances of cluster via cloud controller: [cluster] %s", clusterId));
- }
- long startTime = System.currentTimeMillis();
- stub.terminateInstances(clusterId);
-
- if (log.isDebugEnabled()) {
- long endTime = System.currentTimeMillis();
- log.debug(String.format("Service call terminateInstances() returned in %dms", (endTime - startTime)));
- }
- }
+ private static final Log log = LogFactory.getLog(AutoscalerCloudControllerClient.class);
+
+ 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();
+ int port =
+ conf.getInt("autoscaler.cloudController.port", AutoscalerConstants.CLOUD_CONTROLLER_DEFAULT_PORT);
+ String hostname = conf.getString("autoscaler.cloudController.hostname", "localhost");
+ String epr = "https://" + hostname + ":" + port + "/" + AutoscalerConstants.CLOUD_CONTROLLER_SERVICE_SFX;
+ int cloudControllerClientTimeout = conf.getInt("autoscaler.cloudController.clientTimeout", 180000);
+
+ stub = new CloudControllerServiceStub(epr);
+ stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, cloudControllerClientTimeout);
+ stub._getServiceClient().getOptions()
+ .setProperty(HTTPConstants.CONNECTION_TIMEOUT, cloudControllerClientTimeout);
+ } catch (Exception e) {
+ log.error("Could not initialize cloud controller client", e);
+ }
+ }
+
+ public synchronized MemberContext startInstance(PartitionRef partition, String clusterId, String clusterInstanceId,
+ String networkPartitionId, boolean isPrimary, int minMemberCount,
+ String autoscalingReason, long scalingTime)
+ throws SpawningException {
+ try {
+ if (log.isInfoEnabled()) {
+ log.info(String.format("Trying to spawn an instance via cloud controller: " +
+ "[cluster] %s [partition] %s [network-partition-id] %s", clusterId,
+ partition.getId(), networkPartitionId));
+ }
+
+ XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
+ long expiryTime = conf.getLong(StratosConstants.OBSOLETED_MEMBER_EXPIRY_TIMEOUT, 86400000);
+ if (log.isDebugEnabled()) {
+ log.debug("Member obsolete expiry time is set to: " + expiryTime);
+ }
+
+ InstanceContext instanceContext = new InstanceContext();
+ instanceContext.setClusterId(clusterId);
+ instanceContext.setClusterInstanceId(clusterInstanceId);
+ instanceContext.setPartition(AutoscalerObjectConverter.convertPartitionToCCPartition(partition));
+ instanceContext.setInitTime(System.currentTimeMillis());
+ instanceContext.setObsoleteExpiryTime(expiryTime);
+ instanceContext.setNetworkPartitionId(networkPartitionId);
+
+ Properties memberContextProps = new Properties();
+ Property isPrimaryProp = new Property();
+ isPrimaryProp.setName("PRIMARY");
+ isPrimaryProp.setValue(String.valueOf(isPrimary));
+
+ Property minCountProp = new Property();
+ minCountProp.setName(StratosConstants.MIN_COUNT);
+ minCountProp.setValue(String.valueOf(minMemberCount));
+
+ Property autoscalingReasonProp = new Property();
+ autoscalingReasonProp.setName(StratosConstants.SCALING_REASON);
+ autoscalingReasonProp.setValue(autoscalingReason);
+
+ Property scalingTimeProp = new Property();
+ scalingTimeProp.setName(StratosConstants.SCALING_TIME);
+ scalingTimeProp.setValue(String.valueOf(scalingTime));
+
+ memberContextProps.addProperty(isPrimaryProp);
+ memberContextProps.addProperty(minCountProp);
+ memberContextProps.addProperty(autoscalingReasonProp);
+ memberContextProps.addProperty(scalingTimeProp);
+ instanceContext.setProperties(AutoscalerUtil.toStubProperties(memberContextProps));
+
+ long startTime = System.currentTimeMillis();
+ MemberContext memberContext = stub.startInstance(instanceContext);
+
+ if (log.isDebugEnabled()) {
+ long endTime = System.currentTimeMillis();
+ log.debug(String.format("Service call startInstance() returned in %dms", (endTime - startTime)));
+ }
+ return memberContext;
+ } catch (CloudControllerServiceCartridgeNotFoundExceptionException e) {
+ String message = e.getFaultMessage().getCartridgeNotFoundException().getMessage();
+ log.error(message, e);
+ throw new SpawningException(message, e);
+ } catch (RemoteException e) {
+ log.error(e.getMessage(), e);
+ throw new SpawningException(e.getMessage(), e);
+ } catch (CloudControllerServiceInvalidIaasProviderExceptionException e) {
+ String message = e.getFaultMessage().getInvalidIaasProviderException().getMessage();
+ log.error(message, e);
+ throw new SpawningException(message, e);
+ } catch (CloudControllerServiceCloudControllerExceptionException e) {
+ String message = e.getMessage();
+ log.error(message, e);
+ throw new SpawningException(message, e);
+ }
+ }
+
+ public synchronized void createApplicationClusters(String appId,
+ ApplicationClusterContext[] applicationClusterContexts) {
+ List<org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext> contextDTOs =
+ new ArrayList<org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext>();
+ if (applicationClusterContexts != null) {
+ for (ApplicationClusterContext applicationClusterContext : applicationClusterContexts) {
+ if (applicationClusterContext != null) {
+ org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext dto =
+ new org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext();
+ dto.setClusterId(applicationClusterContext.getClusterId());
+ dto.setAutoscalePolicyName(applicationClusterContext.getAutoscalePolicyName());
+ dto.setDeploymentPolicyName(applicationClusterContext.getDeploymentPolicyName());
+ dto.setCartridgeType(applicationClusterContext.getCartridgeType());
+ dto.setHostName(applicationClusterContext.getHostName());
+ dto.setTenantRange(applicationClusterContext.getTenantRange());
+ dto.setTextPayload(applicationClusterContext.getTextPayload());
+ dto.setProperties(AutoscalerUtil.toStubProperties(applicationClusterContext.getProperties()));
+ dto.setDependencyClusterIds(applicationClusterContext.getDependencyClusterIds());
+ if (applicationClusterContext.getPersistenceContext() != null) {
+ dto.setVolumeRequired(true);
+ dto.setVolumes(convertVolumesToStubVolumes(
+ applicationClusterContext.getPersistenceContext().getVolumes()));
+ }
+ contextDTOs.add(dto);
+ }
+ }
+ }
+
+ org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext[] applicationClusterContextDTOs =
+ new org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext[contextDTOs.size()];
+ contextDTOs.toArray(applicationClusterContextDTOs);
+ try {
+ stub.createApplicationClusters(appId, applicationClusterContextDTOs);
+ } catch (RemoteException e) {
+ String msg = e.getMessage();
+ log.error(msg, e);
+ } catch (CloudControllerServiceApplicationClusterRegistrationExceptionException e) {
+ String msg = e.getMessage();
+ log.error(msg, e);
+ }
+ }
+
+ private Volume[] convertVolumesToStubVolumes(VolumeContext[] volumeContexts) {
+
+ ArrayList<Volume> volumes = new ArrayList<Volume>();
+ for (VolumeContext volumeContext : volumeContexts) {
+ Volume volume = new Volume();
+ volume.setRemoveOntermination(volumeContext.isRemoveOntermination());
+ volume.setMappingPath(volumeContext.getMappingPath());
+ volume.setId(volumeContext.getId());
+ volume.setDevice(volumeContext.getDevice());
+ volume.setIaasType(volumeContext.getIaasType());
+ volume.setSnapshotId(volumeContext.getSnapshotId());
+ volume.setVolumeId(volumeContext.getVolumeId());
+ volume.setSize(volumeContext.getSize());
+ volumes.add(volume);
+ }
+ return volumes.toArray(new Volume[volumes.size()]);
+ }
+
+ public void terminateInstance(String memberId) throws Exception {
+ if (log.isInfoEnabled()) {
+ log.info(String.format("Terminating instance via cloud controller: [member] %s", memberId));
+ }
+ long startTime = System.currentTimeMillis();
+ stub.terminateInstance(memberId);
+ if (log.isDebugEnabled()) {
+ long endTime = System.currentTimeMillis();
+ log.debug(String.format("Service call terminateInstance() returned in %dms", (endTime - startTime)));
+ }
+ }
+
+ public void terminateInstanceForcefully(String memberId) throws Exception {
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Terminating instance forcefully via cloud controller: [member] %s", memberId));
+ }
+ stub.terminateInstanceForcefully(memberId);
+ }
+
+ public void terminateAllInstances(String clusterId)
+ throws RemoteException, CloudControllerServiceInvalidClusterExceptionException {
+ if (log.isInfoEnabled()) {
+ log.info(String.format("Terminating all instances of cluster via cloud controller: [cluster] %s",
+ clusterId));
+ }
+ long startTime = System.currentTimeMillis();
+ stub.terminateInstances(clusterId);
+
+ if (log.isDebugEnabled()) {
+ long endTime = System.currentTimeMillis();
+ log.debug(String.format("Service call terminateInstances() returned in %dms", (endTime - startTime)));
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/76c7724b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java
----------------------------------------------------------------------
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 51443a1..5627b8c 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
@@ -36,7 +36,6 @@ import org.apache.stratos.autoscaler.context.partition.network.ClusterLevelNetwo
import org.apache.stratos.autoscaler.event.publisher.InstanceNotificationPublisher;
import org.apache.stratos.autoscaler.monitor.cluster.ClusterMonitor;
import org.apache.stratos.cloud.controller.stub.domain.MemberContext;
-import org.apache.stratos.common.client.CloudControllerServiceClient;
import org.apache.stratos.common.constants.StratosConstants;
/**
@@ -44,347 +43,350 @@ import org.apache.stratos.common.constants.StratosConstants;
*/
public class RuleTasksDelegator {
- private static boolean arspiIsSet = false;
-
- private static final Log log = LogFactory.getLog(RuleTasksDelegator.class);
-
- public double getPredictedValueForNextMinute(float average, float gradient, float secondDerivative, int timeInterval) {
- double predictedValue;
-// 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;
- }
-
-
- public int getNumberOfInstancesRequiredBasedOnRif(float rifPredictedValue, float rifThreshold) {
-
- if (rifThreshold != 0) {
-
- float requiredNumberOfInstances = rifPredictedValue / rifThreshold;
- return (int) Math.ceil(requiredNumberOfInstances);
- } else {
- log.error("Request in flight threshold is Zero");
- return 0;
- }
-
- }
-
- public int getNumberOfInstancesRequiredBasedOnMemoryConsumption(float threshold, double predictedValue,
- int min, int max) {
- double numberOfAdditionalInstancesRequired = 0;
- if (predictedValue != threshold) {
-
- float scalingRange = 100 - threshold;
- int instanceRange = max - min;
-
- if (instanceRange != 0) {
-
- float gradient = scalingRange / instanceRange;
- numberOfAdditionalInstancesRequired = (predictedValue - threshold) / gradient;
- }
-
- if (predictedValue < threshold) {
- //Since predicted-value is less, it can be scale-down
- return min - 1;
- }
- }
-
- return (int) Math.ceil(min + numberOfAdditionalInstancesRequired);
- }
-
- public int getNumberOfInstancesRequiredBasedOnLoadAverage(float threshold, double predictedValue,
- int min) {
-
- double numberOfInstances;
- if (threshold != 0) {
-
- numberOfInstances = (min * predictedValue) / threshold;
- return (int) Math.ceil(numberOfInstances);
- }
-
- return min;
- }
-
- public int getMaxNumberOfInstancesRequired(int numberOfInstancesRequiredBasedOnRif,
- int numberOfInstancesRequiredBasedOnMemoryConsumption,
- boolean mcReset, int numberOfInstancesReuquiredBasedOnLoadAverage,
- boolean laReset) {
- int numberOfInstances = 0;
-
- int rifBasedRequiredInstances = 0;
- int mcBasedRequiredInstances = 0;
- int laBasedRequiredInstances = 0;
- if (arspiIsSet) {
- rifBasedRequiredInstances = numberOfInstancesRequiredBasedOnRif;
- }
- if (mcReset) {
- mcBasedRequiredInstances = numberOfInstancesRequiredBasedOnMemoryConsumption;
- }
- if (laReset) {
- laBasedRequiredInstances = numberOfInstancesReuquiredBasedOnLoadAverage;
- }
- numberOfInstances = Math.max(Math.max(numberOfInstancesRequiredBasedOnMemoryConsumption,
- numberOfInstancesReuquiredBasedOnLoadAverage), numberOfInstancesRequiredBasedOnRif);
- return numberOfInstances;
- }
-
- public PartitionAlgorithm getPartitionAlgorithm(String partitionAlgorithm) {
-
- PartitionAlgorithm autoscaleAlgorithm = null;
- //FIXME to not parse for algo when partition is chosen by the parent
-
- if (partitionAlgorithm == null) {
- //Send one after another as default
- partitionAlgorithm = StratosConstants.PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID;
- }
- if (log.isDebugEnabled()) {
- log.debug(String.format("Retrieving partition algorithm [Partition algorithm]: %s", partitionAlgorithm));
- }
- if (StratosConstants.PARTITION_ROUND_ROBIN_ALGORITHM_ID.equals(partitionAlgorithm)) {
- autoscaleAlgorithm = new RoundRobin();
- } else if (StratosConstants.PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID.equals(partitionAlgorithm)) {
- autoscaleAlgorithm = new OneAfterAnother();
- } else {
- if (log.isErrorEnabled()) {
- log.error(String.format("Partition algorithm %s could not be identified !", partitionAlgorithm));
- }
- }
- return autoscaleAlgorithm;
- }
-
- public void delegateInstanceCleanup(String memberId) {
- try {
- // send the instance notification event.
- InstanceNotificationPublisher.getInstance().sendInstanceCleanupEventForMember(memberId);
- log.info("Instance clean up event sent for [member] " + memberId);
-
- } catch (Exception e) {
- log.error("Cannot terminate instance", e);
- }
- }
-
- /**
- * Invoked from drools to start an instance.
- *
- * @param clusterMonitorPartitionContext Cluster monitor partition context
- * @param clusterId Cluster id
- * @param clusterInstanceId Instance id
- * @param isPrimary Is a primary member
- */
- public void delegateSpawn(ClusterLevelPartitionContext clusterMonitorPartitionContext, String clusterId,
- String clusterInstanceId, boolean isPrimary) {
-
- try {
- String nwPartitionId = clusterMonitorPartitionContext.getNetworkPartitionId();
-
- // Calculate accumulation of minimum counts of all the partition of current network partition
- int minimumCountOfNetworkPartition;
- ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getClusterMonitor(clusterId);
- ClusterContext clusterContext = clusterMonitor.getClusterContext();
- ClusterLevelNetworkPartitionContext clusterLevelNetworkPartitionContext =
- clusterContext.getNetworkPartitionCtxt(nwPartitionId);
- ClusterInstanceContext clusterInstanceContext =
- (ClusterInstanceContext) clusterLevelNetworkPartitionContext.
- getInstanceContext(clusterInstanceId);
- minimumCountOfNetworkPartition = clusterInstanceContext.getMinInstanceCount();
-
- MemberContext memberContext =
- AutoscalerCloudControllerClient.getInstance()
- .startInstance(clusterMonitorPartitionContext.getPartition(),
- clusterId,
- clusterInstanceId, clusterMonitorPartitionContext.getNetworkPartitionId(),
- isPrimary,
- minimumCountOfNetworkPartition);
- if (memberContext != null) {
- ClusterLevelPartitionContext partitionContext = clusterInstanceContext.
- getPartitionCtxt(clusterMonitorPartitionContext.getPartitionId());
- partitionContext.addPendingMember(memberContext);
- partitionContext.addMemberStatsContext(new MemberStatsContext(memberContext.getMemberId()));
- if (log.isDebugEnabled()) {
- log.debug(String.format("Pending member added, [member] %s [partition] %s", memberContext.getMemberId(),
- memberContext.getPartition().getId()));
- }
-
- } else {
- if (log.isErrorEnabled()) {
- log.error("Member context returned from cloud controller is null");
- }
- }
- } catch (Exception e) {
- String message = String.format("Could not start instance: [cluster-id] %s [instance-id] %s",
- clusterId, clusterInstanceId);
- log.error(message, e);
- throw new RuntimeException(message, e);
- }
- }
-
- public void delegateScalingDependencyNotification(String clusterId, String networkPartitionId, String instanceId,
- int requiredInstanceCount, int minimumInstanceCount) {
-
- if (log.isDebugEnabled()) {
- log.debug("Scaling dependent notification is going to the [parentInstance] " + instanceId);
- }
- //Notify parent for checking scaling dependencies
- ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getClusterMonitor(clusterId);
- float fMinimumInstanceCount = minimumInstanceCount;
- float factor = requiredInstanceCount / fMinimumInstanceCount;
- clusterMonitor.sendClusterScalingEvent(networkPartitionId, instanceId, factor);
- }
-
- public void delegateScalingOverMaxNotification(String clusterId, String networkPartitionId, String instanceId) {
- if (log.isDebugEnabled()) {
- log.debug("Scaling max out notification is going to the [parentInstance] " + instanceId);
- }
- //Notify parent for checking scaling dependencies
- ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getClusterMonitor(clusterId);
- clusterMonitor.sendScalingOverMaxEvent(networkPartitionId, instanceId);
- }
-
- public void delegateScalingDownBeyondMinNotification(String clusterId, String networkPartitionId, String instanceId) {
- if (log.isDebugEnabled()) {
- log.debug("Scaling down lower min notification is going to the [parentInstance] " + instanceId);
- }
- //Notify parent for checking scaling dependencies
- ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getClusterMonitor(clusterId);
- clusterMonitor.sendScalingDownBeyondMinEvent(networkPartitionId, instanceId);
- }
-
- public void delegateTerminate(ClusterLevelPartitionContext clusterMonitorPartitionContext, String memberId) {
-
- try {
- //Moving member to pending termination list
- if (clusterMonitorPartitionContext.activeMemberAvailable(memberId)) {
-
- log.info(String.format("[scale-down] Moving active member to termination pending list [member id] %s " +
- "[partition] %s [network partition] %s", memberId,
- clusterMonitorPartitionContext.getPartitionId(),
- clusterMonitorPartitionContext.getNetworkPartitionId()));
- clusterMonitorPartitionContext.moveActiveMemberToTerminationPendingMembers(memberId);
- clusterMonitorPartitionContext.removeMemberStatsContext(memberId);
- } else if (clusterMonitorPartitionContext.pendingMemberAvailable(memberId)) {
-
- log.info(String.format("[scale-down] Moving pending member to termination pending list [member id] %s " +
- "[partition] %s [network partition] %s", memberId,
- clusterMonitorPartitionContext.getPartitionId(),
- clusterMonitorPartitionContext.getNetworkPartitionId()));
- clusterMonitorPartitionContext.movePendingMemberToObsoleteMembers(memberId);
- clusterMonitorPartitionContext.removeMemberStatsContext(memberId);
- }
- } catch (Exception e) {
- log.error("[scale-down] Cannot move member to termination pending list ", e);
- }
- }
-
- public void delegateTerminateDependency(ClusterLevelPartitionContext clusterMonitorPartitionContext, String memberId) {
- try {
- //calling SM to send the instance notification event.
- if (log.isDebugEnabled()) {
- log.debug("delegateTerminateDependency:memberId:" + memberId);
- }
- //InstanceNotificationClient.getInstance().sendMemberCleanupEvent(memberId);
- //partitionContext.moveActiveMemberToTerminationPendingMembers(memberId);
- //CloudControllerClient.getInstance().terminate(memberId);
- } catch (Exception e) {
- log.error("Cannot terminate instance", e);
- }
- }
-
- public void terminateObsoleteInstance(String memberId) {
- try {
- AutoscalerCloudControllerClient.getInstance().terminateInstance(memberId);
- } catch (Exception e) {
- log.error("Cannot terminate instance", e);
- }
- }
-
- //Grouping
- public void delegateTerminateAll(String clusterId) {
- try {
- if (log.isDebugEnabled()) {
- log.debug("delegateTerminateAll - begin");
- }
- AutoscalerCloudControllerClient.getInstance().terminateAllInstances(clusterId);
- if (log.isDebugEnabled()) {
- log.debug("delegateTerminateAll - done");
- }
- } catch (Exception e) {
- log.error("Cannot terminate instance", e);
- }
- }
-
- public int getPredictedReplicasForStat(int minReplicas, float statUpperLimit, float statPredictedValue) {
- if (statUpperLimit == 0) {
- return 0;
- }
- float predictedValue = ((minReplicas / statUpperLimit) * statPredictedValue);
- return (int) Math.ceil(predictedValue);
- }
-
- public double getLoadAveragePredictedValue(ClusterInstanceContext clusterInstanceContext) {
- double loadAveragePredicted = 0.0d;
- int totalMemberCount = 0;
- for (ClusterLevelPartitionContext partitionContext : clusterInstanceContext.getPartitionCtxts()) {
- for (MemberStatsContext memberStatsContext : partitionContext.getMemberStatsContexts().values()) {
-
- float memberAverageLoadAverage = memberStatsContext.getLoadAverage().getAverage();
- float memberGredientLoadAverage = memberStatsContext.getLoadAverage().getGradient();
- float memberSecondDerivativeLoadAverage = memberStatsContext.getLoadAverage().getSecondDerivative();
-
- double memberPredictedLoadAverage = getPredictedValueForNextMinute(memberAverageLoadAverage,
- memberGredientLoadAverage, memberSecondDerivativeLoadAverage, 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("Predicted load average : " + loadAveragePredicted / totalMemberCount);
- return loadAveragePredicted / totalMemberCount;
- } else {
- 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()) {
-
- float memberMemoryConsumptionAverage = memberStatsContext.getMemoryConsumption().getAverage();
- float memberMemoryConsumptionGredient = memberStatsContext.getMemoryConsumption().getGradient();
- float memberMemoryConsumptionSecondDerivative = memberStatsContext.getMemoryConsumption().getSecondDerivative();
-
- double memberPredictedMemoryConsumption = getPredictedValueForNextMinute(memberMemoryConsumptionAverage,
- memberMemoryConsumptionGredient, memberMemoryConsumptionSecondDerivative, 1);
-
- 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("Predicted memory consumption : " + memoryConsumptionPredicted / totalMemberCount);
- return memoryConsumptionPredicted / totalMemberCount;
- } else {
- return 0;
- }
- }
+ private static boolean arspiIsSet = false;
+
+ private static final Log log = LogFactory.getLog(RuleTasksDelegator.class);
+
+ public double getPredictedValueForNextMinute(float average, float gradient, float secondDerivative,
+ int timeInterval) {
+ double predictedValue;
+ // 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;
+ }
+
+ public int getNumberOfInstancesRequiredBasedOnRif(float rifPredictedValue, float rifThreshold) {
+
+ if (rifThreshold != 0) {
+
+ float requiredNumberOfInstances = rifPredictedValue / rifThreshold;
+ return (int) Math.ceil(requiredNumberOfInstances);
+ } else {
+ log.error("Request in flight threshold is Zero");
+ return 0;
+ }
+
+ }
+
+ public int getNumberOfInstancesRequiredBasedOnMemoryConsumption(float threshold, double predictedValue, int min,
+ int max) {
+ double numberOfAdditionalInstancesRequired = 0;
+ if (predictedValue != threshold) {
+
+ float scalingRange = 100 - threshold;
+ int instanceRange = max - min;
+
+ if (instanceRange != 0) {
+
+ float gradient = scalingRange / instanceRange;
+ numberOfAdditionalInstancesRequired = (predictedValue - threshold) / gradient;
+ }
+
+ if (predictedValue < threshold) {
+ //Since predicted-value is less, it can be scale-down
+ return min - 1;
+ }
+ }
+
+ return (int) Math.ceil(min + numberOfAdditionalInstancesRequired);
+ }
+
+ public int getNumberOfInstancesRequiredBasedOnLoadAverage(float threshold, double predictedValue, int min) {
+
+ double numberOfInstances;
+ if (threshold != 0) {
+
+ numberOfInstances = (min * predictedValue) / threshold;
+ return (int) Math.ceil(numberOfInstances);
+ }
+
+ return min;
+ }
+
+ public int getMaxNumberOfInstancesRequired(int numberOfInstancesRequiredBasedOnRif,
+ int numberOfInstancesRequiredBasedOnMemoryConsumption, boolean mcReset,
+ int numberOfInstancesReuquiredBasedOnLoadAverage, boolean laReset) {
+ int numberOfInstances = 0;
+
+ int rifBasedRequiredInstances = 0;
+ int mcBasedRequiredInstances = 0;
+ int laBasedRequiredInstances = 0;
+ if (arspiIsSet) {
+ rifBasedRequiredInstances = numberOfInstancesRequiredBasedOnRif;
+ }
+ if (mcReset) {
+ mcBasedRequiredInstances = numberOfInstancesRequiredBasedOnMemoryConsumption;
+ }
+ if (laReset) {
+ laBasedRequiredInstances = numberOfInstancesReuquiredBasedOnLoadAverage;
+ }
+ numberOfInstances = Math.max(Math.max(numberOfInstancesRequiredBasedOnMemoryConsumption,
+ numberOfInstancesReuquiredBasedOnLoadAverage),
+ numberOfInstancesRequiredBasedOnRif);
+ return numberOfInstances;
+ }
+
+ public PartitionAlgorithm getPartitionAlgorithm(String partitionAlgorithm) {
+
+ PartitionAlgorithm autoscaleAlgorithm = null;
+ //FIXME to not parse for algo when partition is chosen by the parent
+
+ if (partitionAlgorithm == null) {
+ //Send one after another as default
+ partitionAlgorithm = StratosConstants.PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Retrieving partition algorithm [Partition algorithm]: %s", partitionAlgorithm));
+ }
+ if (StratosConstants.PARTITION_ROUND_ROBIN_ALGORITHM_ID.equals(partitionAlgorithm)) {
+ autoscaleAlgorithm = new RoundRobin();
+ } else if (StratosConstants.PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID.equals(partitionAlgorithm)) {
+ autoscaleAlgorithm = new OneAfterAnother();
+ } else {
+ if (log.isErrorEnabled()) {
+ log.error(String.format("Partition algorithm %s could not be identified !", partitionAlgorithm));
+ }
+ }
+ return autoscaleAlgorithm;
+ }
+
+ public void delegateInstanceCleanup(String memberId) {
+ try {
+ // send the instance notification event.
+ InstanceNotificationPublisher.getInstance().sendInstanceCleanupEventForMember(memberId);
+ log.info("Instance clean up event sent for [member] " + memberId);
+
+ } catch (Exception e) {
+ log.error("Cannot terminate instance", e);
+ }
+ }
+
+ /**
+ * Invoked from drools to start an instance.
+ *
+ * @param clusterMonitorPartitionContext Cluster monitor partition context
+ * @param clusterId Cluster id
+ * @param clusterInstanceId Instance id
+ * @param isPrimary Is a primary member
+ */
+ public void delegateSpawn(ClusterLevelPartitionContext clusterMonitorPartitionContext, String clusterId,
+ String clusterInstanceId, boolean isPrimary, String autoscalingReason, long scalingTime) {
+
+ try {
+ String nwPartitionId = clusterMonitorPartitionContext.getNetworkPartitionId();
+
+ // Calculate accumulation of minimum counts of all the partition of current network partition
+ int minimumCountOfNetworkPartition;
+ ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getClusterMonitor(clusterId);
+ ClusterContext clusterContext = clusterMonitor.getClusterContext();
+ ClusterLevelNetworkPartitionContext clusterLevelNetworkPartitionContext =
+ clusterContext.getNetworkPartitionCtxt(nwPartitionId);
+ ClusterInstanceContext clusterInstanceContext =
+ (ClusterInstanceContext) clusterLevelNetworkPartitionContext.
+ getInstanceContext(
+ clusterInstanceId);
+ minimumCountOfNetworkPartition = clusterInstanceContext.getMinInstanceCount();
+
+ MemberContext memberContext = AutoscalerCloudControllerClient.getInstance().startInstance(
+ clusterMonitorPartitionContext.getPartition(), clusterId, clusterInstanceId,
+ clusterMonitorPartitionContext.getNetworkPartitionId(), isPrimary, minimumCountOfNetworkPartition,
+ autoscalingReason, scalingTime);
+ if (memberContext != null) {
+ ClusterLevelPartitionContext partitionContext = clusterInstanceContext.
+ getPartitionCtxt(
+ clusterMonitorPartitionContext
+ .getPartitionId());
+ partitionContext.addPendingMember(memberContext);
+ partitionContext.addMemberStatsContext(new MemberStatsContext(memberContext.getMemberId()));
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Pending member added, [member] %s [partition] %s",
+ memberContext.getMemberId(), memberContext.getPartition().getId()));
+ }
+
+ } else {
+ if (log.isErrorEnabled()) {
+ log.error("Member context returned from cloud controller is null");
+ }
+ }
+ } catch (Exception e) {
+ String message = String.format("Could not start instance: [cluster-id] %s [instance-id] %s", clusterId,
+ clusterInstanceId);
+ log.error(message, e);
+ throw new RuntimeException(message, e);
+ }
+ }
+
+ public void delegateScalingDependencyNotification(String clusterId, String networkPartitionId, String instanceId,
+ int requiredInstanceCount, int minimumInstanceCount) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Scaling dependent notification is going to the [parentInstance] " + instanceId);
+ }
+ //Notify parent for checking scaling dependencies
+ ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getClusterMonitor(clusterId);
+ float fMinimumInstanceCount = minimumInstanceCount;
+ float factor = requiredInstanceCount / fMinimumInstanceCount;
+ clusterMonitor.sendClusterScalingEvent(networkPartitionId, instanceId, factor);
+ }
+
+ public void delegateScalingOverMaxNotification(String clusterId, String networkPartitionId, String instanceId) {
+ if (log.isDebugEnabled()) {
+ log.debug("Scaling max out notification is going to the [parentInstance] " + instanceId);
+ }
+ //Notify parent for checking scaling dependencies
+ ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getClusterMonitor(clusterId);
+ clusterMonitor.sendScalingOverMaxEvent(networkPartitionId, instanceId);
+ }
+
+ public void delegateScalingDownBeyondMinNotification(String clusterId, String networkPartitionId,
+ String instanceId) {
+ if (log.isDebugEnabled()) {
+ log.debug("Scaling down lower min notification is going to the [parentInstance] " + instanceId);
+ }
+ //Notify parent for checking scaling dependencies
+ ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getClusterMonitor(clusterId);
+ clusterMonitor.sendScalingDownBeyondMinEvent(networkPartitionId, instanceId);
+ }
+
+ public void delegateTerminate(ClusterLevelPartitionContext clusterMonitorPartitionContext, String memberId) {
+
+ try {
+ //Moving member to pending termination list
+ if (clusterMonitorPartitionContext.activeMemberAvailable(memberId)) {
+
+ log.info(String.format("[scale-down] Moving active member to termination pending list [member id] %s " +
+ "[partition] %s [network partition] %s", memberId,
+ clusterMonitorPartitionContext.getPartitionId(),
+ clusterMonitorPartitionContext.getNetworkPartitionId()));
+ clusterMonitorPartitionContext.moveActiveMemberToTerminationPendingMembers(memberId);
+ clusterMonitorPartitionContext.removeMemberStatsContext(memberId);
+ } else if (clusterMonitorPartitionContext.pendingMemberAvailable(memberId)) {
+
+ log.info(String.format(
+ "[scale-down] Moving pending member to termination pending list [member id] %s " +
+ "[partition] %s [network partition] %s", memberId,
+ clusterMonitorPartitionContext.getPartitionId(),
+ clusterMonitorPartitionContext.getNetworkPartitionId()));
+ clusterMonitorPartitionContext.movePendingMemberToObsoleteMembers(memberId);
+ clusterMonitorPartitionContext.removeMemberStatsContext(memberId);
+ }
+ } catch (Exception e) {
+ log.error("[scale-down] Cannot move member to termination pending list ", e);
+ }
+ }
+
+ public void delegateTerminateDependency(ClusterLevelPartitionContext clusterMonitorPartitionContext,
+ String memberId) {
+ try {
+ //calling SM to send the instance notification event.
+ if (log.isDebugEnabled()) {
+ log.debug("delegateTerminateDependency:memberId:" + memberId);
+ }
+ //InstanceNotificationClient.getInstance().sendMemberCleanupEvent(memberId);
+ //partitionContext.moveActiveMemberToTerminationPendingMembers(memberId);
+ //CloudControllerClient.getInstance().terminate(memberId);
+ } catch (Exception e) {
+ log.error("Cannot terminate instance", e);
+ }
+ }
+
+ public void terminateObsoleteInstance(String memberId) {
+ try {
+ AutoscalerCloudControllerClient.getInstance().terminateInstance(memberId);
+ } catch (Exception e) {
+ log.error("Cannot terminate instance", e);
+ }
+ }
+
+ //Grouping
+ public void delegateTerminateAll(String clusterId) {
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("delegateTerminateAll - begin");
+ }
+ AutoscalerCloudControllerClient.getInstance().terminateAllInstances(clusterId);
+ if (log.isDebugEnabled()) {
+ log.debug("delegateTerminateAll - done");
+ }
+ } catch (Exception e) {
+ log.error("Cannot terminate instance", e);
+ }
+ }
+
+ public int getPredictedReplicasForStat(int minReplicas, float statUpperLimit, float statPredictedValue) {
+ if (statUpperLimit == 0) {
+ return 0;
+ }
+ float predictedValue = ((minReplicas / statUpperLimit) * statPredictedValue);
+ return (int) Math.ceil(predictedValue);
+ }
+
+ public double getLoadAveragePredictedValue(ClusterInstanceContext clusterInstanceContext) {
+ double loadAveragePredicted = 0.0d;
+ int totalMemberCount = 0;
+ for (ClusterLevelPartitionContext partitionContext : clusterInstanceContext.getPartitionCtxts()) {
+ for (MemberStatsContext memberStatsContext : partitionContext.getMemberStatsContexts().values()) {
+
+ float memberAverageLoadAverage = memberStatsContext.getLoadAverage().getAverage();
+ float memberGredientLoadAverage = memberStatsContext.getLoadAverage().getGradient();
+ float memberSecondDerivativeLoadAverage = memberStatsContext.getLoadAverage().getSecondDerivative();
+
+ double memberPredictedLoadAverage =
+ getPredictedValueForNextMinute(memberAverageLoadAverage, memberGredientLoadAverage,
+ memberSecondDerivativeLoadAverage, 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("Predicted load average : " + loadAveragePredicted / totalMemberCount);
+ return loadAveragePredicted / totalMemberCount;
+ } else {
+ 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()) {
+
+ float memberMemoryConsumptionAverage = memberStatsContext.getMemoryConsumption().getAverage();
+ float memberMemoryConsumptionGredient = memberStatsContext.getMemoryConsumption().getGradient();
+ float memberMemoryConsumptionSecondDerivative =
+ memberStatsContext.getMemoryConsumption().getSecondDerivative();
+
+ double memberPredictedMemoryConsumption =
+ getPredictedValueForNextMinute(memberMemoryConsumptionAverage, memberMemoryConsumptionGredient,
+ memberMemoryConsumptionSecondDerivative, 1);
+
+ 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("Predicted memory consumption : " + memoryConsumptionPredicted / totalMemberCount);
+ return memoryConsumptionPredicted / totalMemberCount;
+ } else {
+ return 0;
+ }
+ }
}
[05/18] stratos git commit: Publishing events for Metering Service
Implementation
Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/76c7724b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java
index 37580eb..571ba9a 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java
@@ -42,70 +42,70 @@ import java.util.Properties;
*/
public class CloudControllerServiceUtil {
- private static final Log log = LogFactory.getLog(CloudControllerServiceUtil.class);
-
- public static Iaas buildIaas(IaasProvider iaasProvider) throws InvalidIaasProviderException {
- return iaasProvider.getIaas();
- }
-
- /**
- * Update the topology, publish statistics to BAM, remove member context
- * and persist cloud controller context.
- *
- * @param memberContext
- */
- public static void executeMemberTerminationPostProcess(MemberContext memberContext) {
- if (memberContext == null) {
- return;
- }
-
- String partitionId = memberContext.getPartition() == null ? null : memberContext.getPartition().getId();
-
- // Update the topology
- TopologyBuilder.handleMemberTerminated(memberContext.getCartridgeType(),
- memberContext.getClusterId(), memberContext.getNetworkPartitionId(),
- partitionId, memberContext.getMemberId());
-
- // Publish statistics to BAM
- BAMUsageDataPublisher.publish(memberContext.getMemberId(),
- partitionId,
- memberContext.getNetworkPartitionId(),
- memberContext.getClusterId(),
- memberContext.getCartridgeType(),
- MemberStatus.Terminated.toString(),
- null);
-
- // Remove member context
- CloudControllerContext.getInstance().removeMemberContext(memberContext.getClusterId(), memberContext.getMemberId());
-
- // Persist cloud controller context
- CloudControllerContext.getInstance().persist();
- }
-
- public static boolean isValidIpAddress(String ip) {
- boolean isValid = InetAddresses.isInetAddress(ip);
- return isValid;
- }
-
- public static IaasProvider validatePartitionAndGetIaasProvider(Partition partition, IaasProvider iaasProvider) throws InvalidPartitionException {
- if (iaasProvider != null) {
- // if this is a IaaS based partition
- Iaas iaas = iaasProvider.getIaas();
- PartitionValidator validator = iaas.getPartitionValidator();
- validator.setIaasProvider(iaasProvider);
- Properties partitionProperties = CloudControllerUtil.toJavaUtilProperties(partition.getProperties());
- iaasProvider = validator.validate(partition, partitionProperties);
- return iaasProvider;
-
- } else {
- String msg = "Partition is not valid: [partition-id] " + partition.getId();
- log.error(msg);
- throw new InvalidPartitionException(msg);
- }
- }
-
- public static boolean validatePartition(Partition partition, IaasProvider iaasProvider) throws InvalidPartitionException {
- validatePartitionAndGetIaasProvider(partition, iaasProvider);
- return true;
- }
+ private static final Log log = LogFactory.getLog(CloudControllerServiceUtil.class);
+
+ public static Iaas buildIaas(IaasProvider iaasProvider) throws InvalidIaasProviderException {
+ return iaasProvider.getIaas();
+ }
+
+ /**
+ * Update the topology, publish statistics to BAM, remove member context
+ * and persist cloud controller context.
+ *
+ * @param memberContext
+ */
+ public static void executeMemberTerminationPostProcess(MemberContext memberContext) {
+ if (memberContext == null) {
+ return;
+ }
+
+ String partitionId = memberContext.getPartition() == null ? null : memberContext.getPartition().getId();
+
+ // Update the topology
+ TopologyBuilder.handleMemberTerminated(memberContext.getCartridgeType(), memberContext.getClusterId(),
+ memberContext.getNetworkPartitionId(), partitionId,
+ memberContext.getMemberId());
+
+ Long timeStamp = System.currentTimeMillis();
+ // Publish statistics to BAM
+ BAMUsageDataPublisher.publish(memberContext.getMemberId(), partitionId, memberContext.getNetworkPartitionId(),
+ memberContext.getClusterId(), memberContext.getCartridgeType(),
+ MemberStatus.Terminated.toString(), timeStamp, null, null, null);
+
+ // Remove member context
+ CloudControllerContext.getInstance()
+ .removeMemberContext(memberContext.getClusterId(), memberContext.getMemberId());
+
+ // Persist cloud controller context
+ CloudControllerContext.getInstance().persist();
+ }
+
+ public static boolean isValidIpAddress(String ip) {
+ boolean isValid = InetAddresses.isInetAddress(ip);
+ return isValid;
+ }
+
+ public static IaasProvider validatePartitionAndGetIaasProvider(Partition partition, IaasProvider iaasProvider)
+ throws InvalidPartitionException {
+ if (iaasProvider != null) {
+ // if this is a IaaS based partition
+ Iaas iaas = iaasProvider.getIaas();
+ PartitionValidator validator = iaas.getPartitionValidator();
+ validator.setIaasProvider(iaasProvider);
+ Properties partitionProperties = CloudControllerUtil.toJavaUtilProperties(partition.getProperties());
+ iaasProvider = validator.validate(partition, partitionProperties);
+ return iaasProvider;
+
+ } else {
+ String msg = "Partition is not valid: [partition-id] " + partition.getId();
+ log.error(msg);
+ throw new InvalidPartitionException(msg);
+ }
+ }
+
+ public static boolean validatePartition(Partition partition, IaasProvider iaasProvider)
+ throws InvalidPartitionException {
+ validatePartitionAndGetIaasProvider(partition, iaasProvider);
+ return true;
+ }
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/76c7724b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/InstanceCreator.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/InstanceCreator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/InstanceCreator.java
index 77cfea2..35c8bb1 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/InstanceCreator.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/InstanceCreator.java
@@ -27,8 +27,6 @@ import org.apache.stratos.cloud.controller.domain.*;
import org.apache.stratos.cloud.controller.exception.CartridgeNotFoundException;
import org.apache.stratos.cloud.controller.iaases.Iaas;
import org.apache.stratos.cloud.controller.messaging.topology.TopologyBuilder;
-import org.apache.stratos.cloud.controller.statistics.publisher.BAMUsageDataPublisher;
-import org.apache.stratos.messaging.domain.topology.MemberStatus;
import java.util.concurrent.locks.Lock;
@@ -85,15 +83,6 @@ public class InstanceCreator implements Runnable {
// Update topology
TopologyBuilder.handleMemberInitializedEvent(memberContext);
- // Publish instance creation statistics to BAM
- BAMUsageDataPublisher.publish(
- memberContext.getMemberId(),
- memberContext.getPartition().getId(),
- memberContext.getNetworkPartitionId(),
- memberContext.getClusterId(),
- memberContext.getCartridgeType(),
- MemberStatus.Initialized.toString(),
- memberContext.getInstanceMetadata());
} catch (Exception e) {
String message = String.format("Could not start instance: [cartridge-type] %s [cluster-id] %s",
memberContext.getCartridgeType(), memberContext.getClusterId());
http://git-wip-us.apache.org/repos/asf/stratos/blob/76c7724b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/statistics/publisher/BAMUsageDataPublisher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/statistics/publisher/BAMUsageDataPublisher.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/statistics/publisher/BAMUsageDataPublisher.java
index d5aabbd..c69feef 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/statistics/publisher/BAMUsageDataPublisher.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/statistics/publisher/BAMUsageDataPublisher.java
@@ -46,168 +46,183 @@ import java.util.List;
*/
public class BAMUsageDataPublisher {
- private static final Log log = LogFactory.getLog(BAMUsageDataPublisher.class);
-
- private static AsyncDataPublisher dataPublisher;
- private static StreamDefinition streamDefinition;
- private static final String cloudControllerEventStreamVersion = "1.0.0";
-
- public static void publish(String memberId,
- String partitionId,
- String networkId,
- String clusterId,
- String serviceName,
- String status,
- InstanceMetadata metadata) {
- if (!CloudControllerConfig.getInstance().isBAMDataPublisherEnabled()) {
- return;
- }
- log.debug(CloudControllerConstants.DATA_PUB_TASK_NAME + " cycle started.");
-
- if (dataPublisher == null) {
- createDataPublisher();
-
- //If we cannot create a data publisher we should give up
- //this means data will not be published
- if (dataPublisher == null) {
- log.error("Data Publisher cannot be created or found.");
- release();
- return;
- }
- }
-
- MemberContext memberContext = CloudControllerContext.getInstance().getMemberContextOfMemberId(memberId);
- String cartridgeType = memberContext.getCartridgeType();
- Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType);
-
- //Construct the data to be published
- List<Object> payload = new ArrayList<Object>();
- // Payload values
- payload.add(memberId);
- payload.add(serviceName);
- payload.add(clusterId);
- payload.add(handleNull(memberContext.getLbClusterId()));
- payload.add(handleNull(partitionId));
- payload.add(handleNull(networkId));
- if (cartridge != null) {
- payload.add(handleNull(String.valueOf(cartridge.isMultiTenant())));
- } else {
- payload.add("");
- }
- payload.add(handleNull(memberContext.getPartition().getProvider()));
- payload.add(handleNull(status));
-
- if (metadata != null) {
- payload.add(metadata.getHostname());
- payload.add(metadata.getHypervisor());
- payload.add(String.valueOf(metadata.getRam()));
- payload.add(metadata.getImageId());
- payload.add(metadata.getLoginPort());
- payload.add(metadata.getOperatingSystemName());
- payload.add(metadata.getOperatingSystemVersion());
- payload.add(metadata.getOperatingSystemArchitecture());
- payload.add(String.valueOf(metadata.isOperatingSystem64bit()));
- } else {
- payload.add("");
- payload.add("");
- payload.add("");
- payload.add("");
- payload.add(0);
- payload.add("");
- payload.add("");
- payload.add("");
- payload.add("");
- }
-
- payload.add(handleNull(Arrays.toString(memberContext.getPrivateIPs())));
- payload.add(handleNull(Arrays.toString(memberContext.getPublicIPs())));
- payload.add(handleNull(Arrays.toString(memberContext.getAllocatedIPs())));
-
- Event event = new Event();
- event.setPayloadData(payload.toArray());
- event.setArbitraryDataMap(new HashMap<String, String>());
-
- try {
- if (log.isDebugEnabled()) {
- log.debug(String.format("Publishing BAM event: [stream] %s [version] %s", streamDefinition.getName(), streamDefinition.getVersion()));
- }
- dataPublisher.publish(streamDefinition.getName(), streamDefinition.getVersion(), event);
- } catch (AgentException e) {
- if (log.isErrorEnabled()) {
- log.error(String.format("Could not publish BAM event: [stream] %s [version] %s", streamDefinition.getName(), streamDefinition.getVersion()), e);
- }
- }
- }
-
- private static void release() {
- CloudControllerContext.getInstance().setPublisherRunning(false);
- }
-
- private static StreamDefinition initializeStream() throws Exception {
- streamDefinition = new StreamDefinition(
- CloudControllerConstants.CLOUD_CONTROLLER_EVENT_STREAM,
- cloudControllerEventStreamVersion);
- streamDefinition.setNickName("cloud.controller");
- streamDefinition.setDescription("Instances booted up by the Cloud Controller");
- // Payload definition
- List<Attribute> payloadData = new ArrayList<Attribute>();
- payloadData.add(new Attribute(CloudControllerConstants.MEMBER_ID_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.CARTRIDGE_TYPE_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.CLUSTER_ID_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.LB_CLUSTER_ID_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.PARTITION_ID_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.NETWORK_ID_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.IS_MULTI_TENANT_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.IAAS_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.STATUS_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.HOST_NAME_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.HYPERVISOR_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.RAM_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.IMAGE_ID_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.LOGIN_PORT_COL, AttributeType.INT));
- payloadData.add(new Attribute(CloudControllerConstants.OS_NAME_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.OS_VERSION_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.OS_ARCH_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.OS_BIT_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.PRIV_IP_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.PUB_IP_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.ALLOCATE_IP_COL, AttributeType.STRING));
- streamDefinition.setPayloadData(payloadData);
- return streamDefinition;
- }
-
-
- private static void createDataPublisher() {
- //creating the agent
-
- ServerConfiguration serverConfig = CarbonUtils.getServerConfiguration();
- String trustStorePath = serverConfig.getFirstProperty("Security.TrustStore.Location");
- String trustStorePassword = serverConfig.getFirstProperty("Security.TrustStore.Password");
- String bamServerUrl = serverConfig.getFirstProperty("BamServerURL");
- String adminUsername = CloudControllerConfig.getInstance().getDataPubConfig().getBamUsername();
- String adminPassword = CloudControllerConfig.getInstance().getDataPubConfig().getBamPassword();
-
- System.setProperty("javax.net.ssl.trustStore", trustStorePath);
- System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
-
-
- try {
- dataPublisher = new AsyncDataPublisher("tcp://" + bamServerUrl + "", adminUsername, adminPassword);
- CloudControllerContext.getInstance().setDataPublisher(dataPublisher);
- initializeStream();
- dataPublisher.addStreamDefinition(streamDefinition);
- } catch (Exception e) {
- String msg = "Unable to create a data publisher to " + bamServerUrl +
- ". Usage Agent will not function properly. ";
- log.error(msg, e);
- throw new CloudControllerException(msg, e);
- }
- }
-
- private static String handleNull(String val) {
- if (val == null) {
- return "";
- }
- return val;
- }
+ private static final Log log = LogFactory.getLog(BAMUsageDataPublisher.class);
+
+ private static AsyncDataPublisher dataPublisher;
+ private static StreamDefinition streamDefinition;
+ private static final String cloudControllerEventStreamVersion = "1.0.0";
+
+ public static void publish(String memberId, String partitionId, String networkId, String clusterId,
+ String clusterInstanceId, String serviceName, String status, Long timeStamp,
+ String autoscalingReason, Long scalingTime, InstanceMetadata metadata) {
+ if (!CloudControllerConfig.getInstance().isBAMDataPublisherEnabled()) {
+ return;
+ }
+ log.debug(CloudControllerConstants.DATA_PUB_TASK_NAME + " cycle started.");
+
+ if (dataPublisher == null) {
+ createDataPublisher();
+
+ //If we cannot create a data publisher we should give up
+ //this means data will not be published
+ if (dataPublisher == null) {
+ log.error("Data Publisher cannot be created or found.");
+ release();
+ return;
+ }
+ }
+
+ MemberContext memberContext = CloudControllerContext.getInstance().getMemberContextOfMemberId(memberId);
+ String cartridgeType = memberContext.getCartridgeType();
+ Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType);
+ String instanceType =
+ CloudControllerContext.getInstance().getIaasProviderOfPartition(cartridgeType, partitionId)
+ .getProperty(CloudControllerConstants.INSTANCE_TYPE);
+
+ //Construct the data to be published
+ List<Object> payload = new ArrayList<Object>();
+ // Payload values
+ payload.add(timeStamp);
+ payload.add(memberId);
+ payload.add(serviceName);
+ payload.add(clusterId);
+ payload.add(clusterInstanceId);
+ payload.add(handleNull(memberContext.getLbClusterId()));
+ payload.add(handleNull(partitionId));
+ payload.add(handleNull(networkId));
+ payload.add(handleNull(instanceType));
+ payload.add(handleNull(autoscalingReason));
+ payload.add(handleNull(scalingTime));
+ if (cartridge != null) {
+ payload.add(handleNull(String.valueOf(cartridge.isMultiTenant())));
+ } else {
+ payload.add("");
+ }
+ payload.add(handleNull(memberContext.getPartition().getProvider()));
+ payload.add(handleNull(status));
+
+ if (metadata != null) {
+ payload.add(metadata.getHostname());
+ payload.add(metadata.getHypervisor());
+ payload.add(String.valueOf(metadata.getRam()));
+ payload.add(metadata.getImageId());
+ payload.add(metadata.getLoginPort());
+ payload.add(metadata.getOperatingSystemName());
+ payload.add(metadata.getOperatingSystemVersion());
+ payload.add(metadata.getOperatingSystemArchitecture());
+ payload.add(String.valueOf(metadata.isOperatingSystem64bit()));
+ } else {
+ payload.add("");
+ payload.add("");
+ payload.add("");
+ payload.add("");
+ payload.add(0);
+ payload.add("");
+ payload.add("");
+ payload.add("");
+ payload.add("");
+ }
+
+ payload.add(handleNull(Arrays.toString(memberContext.getPrivateIPs())));
+ payload.add(handleNull(Arrays.toString(memberContext.getPublicIPs())));
+ payload.add(handleNull(Arrays.toString(memberContext.getAllocatedIPs())));
+
+ Event event = new Event();
+ event.setPayloadData(payload.toArray());
+ event.setArbitraryDataMap(new HashMap<String, String>());
+
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Publishing BAM event: [stream] %s [version] %s", streamDefinition.getName(),
+ streamDefinition.getVersion()));
+ }
+ dataPublisher.publish(streamDefinition.getName(), streamDefinition.getVersion(), event);
+ } catch (AgentException e) {
+ if (log.isErrorEnabled()) {
+ log.error(String.format("Could not publish BAM event: [stream] %s [version] %s",
+ streamDefinition.getName(), streamDefinition.getVersion()), e);
+ }
+ }
+ }
+
+ private static void release() {
+ CloudControllerContext.getInstance().setPublisherRunning(false);
+ }
+
+ private static StreamDefinition initializeStream() throws Exception {
+ streamDefinition = new StreamDefinition(CloudControllerConstants.CLOUD_CONTROLLER_EVENT_STREAM,
+ cloudControllerEventStreamVersion);
+ streamDefinition.setNickName("cloud.controller");
+ streamDefinition.setDescription("Instances booted up by the Cloud Controller");
+ // Payload definition
+ List<Attribute> payloadData = new ArrayList<Attribute>();
+ payloadData.add(new Attribute(CloudControllerConstants.TIME_STAMP, AttributeType.LONG));
+ payloadData.add(new Attribute(CloudControllerConstants.MEMBER_ID_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.CARTRIDGE_TYPE_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.CLUSTER_ID_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.CLUSTER_INSTANCE_ID_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.LB_CLUSTER_ID_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.PARTITION_ID_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.NETWORK_ID_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.INSTANCE_TYPE, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.SCALING_REASON, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.SCALING_TIME, AttributeType.LONG));
+ payloadData.add(new Attribute(CloudControllerConstants.IS_MULTI_TENANT_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.IAAS_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.STATUS_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.HOST_NAME_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.HYPERVISOR_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.RAM_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.IMAGE_ID_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.LOGIN_PORT_COL, AttributeType.INT));
+ payloadData.add(new Attribute(CloudControllerConstants.OS_NAME_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.OS_VERSION_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.OS_ARCH_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.OS_BIT_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.PRIV_IP_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.PUB_IP_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.ALLOCATE_IP_COL, AttributeType.STRING));
+ streamDefinition.setPayloadData(payloadData);
+ return streamDefinition;
+ }
+
+ private static void createDataPublisher() {
+ //creating the agent
+
+ ServerConfiguration serverConfig = CarbonUtils.getServerConfiguration();
+ String trustStorePath = serverConfig.getFirstProperty("Security.TrustStore.Location");
+ String trustStorePassword = serverConfig.getFirstProperty("Security.TrustStore.Password");
+ String bamServerUrl = serverConfig.getFirstProperty("BamServerURL");
+ String adminUsername = CloudControllerConfig.getInstance().getDataPubConfig().getBamUsername();
+ String adminPassword = CloudControllerConfig.getInstance().getDataPubConfig().getBamPassword();
+
+ System.setProperty("javax.net.ssl.trustStore", trustStorePath);
+ System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
+
+ try {
+ dataPublisher = new AsyncDataPublisher("tcp://" + bamServerUrl + "", adminUsername, adminPassword);
+ CloudControllerContext.getInstance().setDataPublisher(dataPublisher);
+ initializeStream();
+ dataPublisher.addStreamDefinition(streamDefinition);
+ } catch (Exception e) {
+ String msg = "Unable to create a data publisher to " + bamServerUrl +
+ ". Usage Agent will not function properly. ";
+ log.error(msg, e);
+ throw new CloudControllerException(msg, e);
+ }
+ }
+
+ private static String handleNull(String val) {
+ if (val == null) {
+ return "";
+ }
+ return val;
+ }
+
+ private static Long handleNull(Long val) {
+ if (val == null) {
+ return -1L;
+ }
+ return val;
+ }
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/76c7724b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
index 5e6115f..6d07e7f 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
@@ -24,281 +24,267 @@ import java.io.File;
public final class CloudControllerConstants {
- /**
- * cloud-controller XML file's elements
- */
- public static final String CLOUD_CONTROLLER_ELEMENT = "cloudController";
- public static final String SERIALIZATION_DIR_ELEMENT = "serializationDir";
- public static final String IAAS_PROVIDERS_ELEMENT = "iaasProviders";
- public static final String IAAS_PROVIDER_ELEMENT = "iaasProvider";
- public static final String PARTITION_ELEMENT = "partition";
- public static final String PARTITIONS_ELEMENT = "partitions";
- public static final String REGION_ELEMENT = "region";
- public static final String ZONE_ELEMENT = "zone";
- public static final String DEPLOYMENT_ELEMENT = "deployment";
- public static final String PORT_MAPPING_ELEMENT = "portMapping";
- public static final String APP_TYPES_ELEMENT = "appTypes";
- public static final String TYPE_ATTR = "type";
- public static final String HOST_ATTR = "host";
- public static final String BASE_DIR_ATTR = "baseDir";
- public static final String PROVIDER_ATTR = "provider";
- public static final String VERSION_ATTR = "version";
- public static final String MULTI_TENANT_ATTR = "multiTenant";
- public static final String PORT_ATTR = "port";
- public static final String PROXY_PORT_ATTR = "proxyPort";
- public static final String NAME_ATTR = "name";
- public static final String APP_SPECIFIC_MAPPING_ATTR = "appSpecificMapping";
+ /**
+ * cloud-controller XML file's elements
+ */
+ public static final String CLOUD_CONTROLLER_ELEMENT = "cloudController";
+ public static final String SERIALIZATION_DIR_ELEMENT = "serializationDir";
+ public static final String IAAS_PROVIDERS_ELEMENT = "iaasProviders";
+ public static final String IAAS_PROVIDER_ELEMENT = "iaasProvider";
+ public static final String PARTITION_ELEMENT = "partition";
+ public static final String PARTITIONS_ELEMENT = "partitions";
+ public static final String REGION_ELEMENT = "region";
+ public static final String ZONE_ELEMENT = "zone";
+ public static final String DEPLOYMENT_ELEMENT = "deployment";
+ public static final String PORT_MAPPING_ELEMENT = "portMapping";
+ public static final String APP_TYPES_ELEMENT = "appTypes";
+ public static final String TYPE_ATTR = "type";
+ public static final String HOST_ATTR = "host";
+ public static final String BASE_DIR_ATTR = "baseDir";
+ public static final String PROVIDER_ATTR = "provider";
+ public static final String VERSION_ATTR = "version";
+ public static final String MULTI_TENANT_ATTR = "multiTenant";
+ public static final String PORT_ATTR = "port";
+ public static final String PROXY_PORT_ATTR = "proxyPort";
+ public static final String NAME_ATTR = "name";
+ public static final String APP_SPECIFIC_MAPPING_ATTR = "appSpecificMapping";
- public static final String CARTRIDGES_ELEMENT = "cartridges";
- public static final String CARTRIDGE_ELEMENT = "cartridge";
+ public static final String CARTRIDGES_ELEMENT = "cartridges";
+ public static final String CARTRIDGE_ELEMENT = "cartridge";
- public static final String DISPLAY_NAME_ELEMENT = "displayName";
- public static final String DESCRIPTION_ELEMENT = "description";
- public static final String PROPERTY_ELEMENT = "property";
- public static final String PROPERTY_NAME_ATTR = "name";
- public static final String PROPERTY_VALUE_ATTR = "value";
- public static final String IMAGE_ID_ELEMENT = "imageId";
- public static final String SCALE_DOWN_ORDER_ELEMENT = "scaleDownOrder";
- public static final String SCALE_UP_ORDER_ELEMENT = "scaleUpOrder";
- public static final String CLASS_NAME_ELEMENT = "className";
- public static final String PROVIDER_ELEMENT = "provider";
- public static final String IDENTITY_ELEMENT = "identity";
- public static final String TYPE_ELEMENT = "type";
- public static final String SCOPE_ELEMENT = "scope";
- public static final String ID_ELEMENT = "id";
- public static final String CREDENTIAL_ELEMENT = "credential";
- public static final String DEFAULT_SERVICE_ELEMENT = "default";
- public static final String SERVICE_ELEMENT = "service";
- public static final String SERVICES_ELEMENT = "services";
- public static final String DIRECTORY_ELEMENT = "dir";
- public static final String HTTP_ELEMENT = "http";
- public static final String HTTPS_ELEMENT = "https";
- public static final String APP_TYPE_ELEMENT = "appType";
- public static final String SERVICE_DOMAIN_ATTR = "domain";
- public static final String SERVICE_SUB_DOMAIN_ATTR = "subDomain";
- public static final String SERVICE_TENANT_RANGE_ATTR = "tenantRange";
- public static final String POLICY_NAME = "policyName";
- public static final String PAYLOAD_ELEMENT = "payload";
- public static final String DATA_PUBLISHER_ELEMENT = "dataPublisher";
- public static final String TOPOLOGY_SYNC_ELEMENT = "topologySync";
- public static final String ENABLE_ATTR = "enable";
- public static final String BAM_SERVER_ELEMENT = "bamServer";
- public static final String CRON_ELEMENT = "cron";
- public static final String BAM_SERVER_ADMIN_USERNAME_ELEMENT = "adminUserName";
- public static final String BAM_SERVER_ADMIN_PASSWORD_ELEMENT = "adminPassword";
- public static final String CASSANDRA_INFO_ELEMENT = "cassandraInfo";
- public static final String HOST_ELEMENT = "host";
- public static final String CONNECTION_URL_ELEMENT = "connectionUrl";
- public static final String HOST_PORT_ELEMENT = "port";
- public static final String USER_NAME_ELEMENT = "userName";
- public static final String PASSWORD_ELEMENT = "password";
- public static final String CLOUD_CONTROLLER_EVENT_STREAM = "org.apache.stratos.cloud.controller";
- public static final String CLOUD_CONTROLLER_COL_FAMILY = CLOUD_CONTROLLER_EVENT_STREAM
- .replaceAll("[/.]", "_");
+ public static final String DISPLAY_NAME_ELEMENT = "displayName";
+ public static final String DESCRIPTION_ELEMENT = "description";
+ public static final String PROPERTY_ELEMENT = "property";
+ public static final String PROPERTY_NAME_ATTR = "name";
+ public static final String PROPERTY_VALUE_ATTR = "value";
+ public static final String IMAGE_ID_ELEMENT = "imageId";
+ public static final String SCALE_DOWN_ORDER_ELEMENT = "scaleDownOrder";
+ public static final String SCALE_UP_ORDER_ELEMENT = "scaleUpOrder";
+ public static final String CLASS_NAME_ELEMENT = "className";
+ public static final String PROVIDER_ELEMENT = "provider";
+ public static final String IDENTITY_ELEMENT = "identity";
+ public static final String TYPE_ELEMENT = "type";
+ public static final String SCOPE_ELEMENT = "scope";
+ public static final String ID_ELEMENT = "id";
+ public static final String CREDENTIAL_ELEMENT = "credential";
+ public static final String DEFAULT_SERVICE_ELEMENT = "default";
+ public static final String SERVICE_ELEMENT = "service";
+ public static final String SERVICES_ELEMENT = "services";
+ public static final String DIRECTORY_ELEMENT = "dir";
+ public static final String HTTP_ELEMENT = "http";
+ public static final String HTTPS_ELEMENT = "https";
+ public static final String APP_TYPE_ELEMENT = "appType";
+ public static final String SERVICE_DOMAIN_ATTR = "domain";
+ public static final String SERVICE_SUB_DOMAIN_ATTR = "subDomain";
+ public static final String SERVICE_TENANT_RANGE_ATTR = "tenantRange";
+ public static final String POLICY_NAME = "policyName";
+ public static final String PAYLOAD_ELEMENT = "payload";
+ public static final String DATA_PUBLISHER_ELEMENT = "dataPublisher";
+ public static final String TOPOLOGY_SYNC_ELEMENT = "topologySync";
+ public static final String ENABLE_ATTR = "enable";
+ public static final String BAM_SERVER_ELEMENT = "bamServer";
+ public static final String CRON_ELEMENT = "cron";
+ public static final String BAM_SERVER_ADMIN_USERNAME_ELEMENT = "adminUserName";
+ public static final String BAM_SERVER_ADMIN_PASSWORD_ELEMENT = "adminPassword";
+ public static final String CASSANDRA_INFO_ELEMENT = "cassandraInfo";
+ public static final String HOST_ELEMENT = "host";
+ public static final String CONNECTION_URL_ELEMENT = "connectionUrl";
+ public static final String HOST_PORT_ELEMENT = "port";
+ public static final String USER_NAME_ELEMENT = "userName";
+ public static final String PASSWORD_ELEMENT = "password";
+ public static final String CLOUD_CONTROLLER_EVENT_STREAM = "org.apache.stratos.cloud.controller";
+ public static final String CLOUD_CONTROLLER_COL_FAMILY = CLOUD_CONTROLLER_EVENT_STREAM.replaceAll("[/.]", "_");
- /**
- * column names
- */
- public static final String PAYLOAD_PREFIX = "payload_";
- public static final String MEMBER_ID_COL = "memberId";
- public static final String CARTRIDGE_TYPE_COL = "cartridgeType";
- public static final String CLUSTER_ID_COL = "clusterId";
- public static final String PARTITION_ID_COL = "partitionId";
- public static final String NETWORK_ID_COL = "networkId";
- public static final String ALIAS_COL = "alias";
- public static final String TENANT_RANGE_COL = "tenantRange";
- public static final String IS_MULTI_TENANT_COL = "isMultiTenant";
- public static final String IAAS_COL = "iaas";
- public static final String STATUS_COL = "status";
- public static final String HOST_NAME_COL = "hostName";
- public static final String HYPERVISOR_COL = "hypervisor";
- public static final String RAM_COL = "ram";
- public static final String IMAGE_ID_COL = "imageId";
- public static final String LOGIN_PORT_COL = "loginPort";
- public static final String OS_NAME_COL = "osName";
- public static final String OS_VERSION_COL = "osVersion";
- public static final String OS_ARCH_COL = "osArch";
- public static final String OS_BIT_COL = "is64bitOS";
- public static final String PRIV_IP_COL = "privateIPAddresses";
- public static final String PUB_IP_COL = "publicIPAddresses";
- public static final String ALLOCATE_IP_COL = "allocateIPAddresses";
+ /**
+ * column names
+ */
+ public static final String PAYLOAD_PREFIX = "payload_";
+ public static final String MEMBER_ID_COL = "memberId";
+ public static final String CARTRIDGE_TYPE_COL = "cartridgeType";
+ public static final String CLUSTER_ID_COL = "clusterId";
+ public static final String CLUSTER_INSTANCE_ID_COL = "clusterInstanceId";
+ public static final String PARTITION_ID_COL = "partitionId";
+ public static final String NETWORK_ID_COL = "networkId";
+ public static final String ALIAS_COL = "alias";
+ public static final String TENANT_RANGE_COL = "tenantRange";
+ public static final String IS_MULTI_TENANT_COL = "isMultiTenant";
+ public static final String IAAS_COL = "iaas";
+ public static final String STATUS_COL = "status";
+ public static final String HOST_NAME_COL = "hostName";
+ public static final String HYPERVISOR_COL = "hypervisor";
+ public static final String RAM_COL = "ram";
+ public static final String IMAGE_ID_COL = "imageId";
+ public static final String LOGIN_PORT_COL = "loginPort";
+ public static final String OS_NAME_COL = "osName";
+ public static final String OS_VERSION_COL = "osVersion";
+ public static final String OS_ARCH_COL = "osArch";
+ public static final String OS_BIT_COL = "is64bitOS";
+ public static final String PRIV_IP_COL = "privateIPAddresses";
+ public static final String PUB_IP_COL = "publicIPAddresses";
+ public static final String ALLOCATE_IP_COL = "allocateIPAddresses";
+ public static final String TIME_STAMP = "timeStamp";
+ public static final String SCALING_REASON = "scalingReason";
+ public static final String SCALING_TIME = "scalingTime";
- /**
- * Properties
- */
- public static final String REGION_PROPERTY = "region";
- public static final String TOPICS_PROPERTY = "topics";
- public static final String PUBLIC_IP_PROPERTY = "public_ip";
- public static final String TENANT_ID_PROPERTY = "tenant_id";
- public static final String ALIAS_PROPERTY = "alias";
- public static final String AUTO_ASSIGN_IP_PROPERTY = "autoAssignIp";
- public static final String JCLOUDS_ENDPOINT = "jclouds.endpoint";
- public static final String CRON_PROPERTY = "cron";
- public static final String AMQP_CONNECTION_URL_PROPERTY = "amqpConnectionUrl";
- public static final String AMQP_INITIAL_CONTEXT_FACTORY_PROPERTY = "amqpInitialContextFactory";
- public static final String AMQP_TOPIC_CONNECTION_FACTORY_PROPERTY = "amqpTopicConnectionFactory";
- public static final String INSTANCE_TOPIC = "instance/*";
- // pre define a floating ip
- public static final String FLOATING_IP_PROPERTY = "floatingIp";
- public static final String DEFAULT_FLOATING_IP_POOL = "defaultFloatingIpPool";
- public static final String OPENSTACK_NETWORKING_PROVIDER = "openstack.networking.provider";
- public static final String OPENSTACK_NEUTRON_NETWORKING = "neutron";
+ /**
+ * Properties
+ */
+ public static final String REGION_PROPERTY = "region";
+ public static final String TOPICS_PROPERTY = "topics";
+ public static final String PUBLIC_IP_PROPERTY = "public_ip";
+ public static final String TENANT_ID_PROPERTY = "tenant_id";
+ public static final String ALIAS_PROPERTY = "alias";
+ public static final String AUTO_ASSIGN_IP_PROPERTY = "autoAssignIp";
+ public static final String JCLOUDS_ENDPOINT = "jclouds.endpoint";
+ public static final String CRON_PROPERTY = "cron";
+ public static final String AMQP_CONNECTION_URL_PROPERTY = "amqpConnectionUrl";
+ public static final String AMQP_INITIAL_CONTEXT_FACTORY_PROPERTY = "amqpInitialContextFactory";
+ public static final String AMQP_TOPIC_CONNECTION_FACTORY_PROPERTY = "amqpTopicConnectionFactory";
+ public static final String INSTANCE_TOPIC = "instance/*";
+ // pre define a floating ip
+ public static final String FLOATING_IP_PROPERTY = "floatingIp";
+ public static final String DEFAULT_FLOATING_IP_POOL = "defaultFloatingIpPool";
+ public static final String OPENSTACK_NETWORKING_PROVIDER = "openstack.networking.provider";
+ public static final String OPENSTACK_NEUTRON_NETWORKING = "neutron";
- /**
- * XPath expressions
- */
- public static final String IAAS_PROVIDER_XPATH = "/"
- + CLOUD_CONTROLLER_ELEMENT + "/" + IAAS_PROVIDERS_ELEMENT + "/"
- + IAAS_PROVIDER_ELEMENT;
- public static final String PARTITION_XPATH = "/" + CLOUD_CONTROLLER_ELEMENT
- + "/" + PARTITIONS_ELEMENT + "/" + PARTITION_ELEMENT;
- public static final String REGION_XPATH = "/" + CLOUD_CONTROLLER_ELEMENT
- + "/" + IAAS_PROVIDERS_ELEMENT + "/" + IAAS_PROVIDER_ELEMENT + "/"
- + REGION_ELEMENT;
- public static final String ZONE_XPATH = "/" + CLOUD_CONTROLLER_ELEMENT
- + "/" + IAAS_PROVIDERS_ELEMENT + "/" + IAAS_PROVIDER_ELEMENT + "/"
- + REGION_ELEMENT + "/" + ZONE_ELEMENT;
- public static final String HOST_XPATH = "/" + CLOUD_CONTROLLER_ELEMENT
- + "/" + IAAS_PROVIDERS_ELEMENT + "/" + IAAS_PROVIDER_ELEMENT + "/"
- + REGION_ELEMENT + "/" + ZONE_ELEMENT + "/" + HOST_ELEMENT;
- public static final String PROPERTY_ELEMENT_XPATH = "/" + PROPERTY_ELEMENT;
- public static final String IMAGE_ID_ELEMENT_XPATH = "/" + IMAGE_ID_ELEMENT;
- public static final String SCALE_UP_ORDER_ELEMENT_XPATH = "/"
- + SCALE_UP_ORDER_ELEMENT;
- public static final String SCALE_DOWN_ORDER_ELEMENT_XPATH = "/"
- + SCALE_DOWN_ORDER_ELEMENT;
- public static final String PROVIDER_ELEMENT_XPATH = "/" + PROPERTY_ELEMENT;
- public static final String IDENTITY_ELEMENT_XPATH = "/" + IDENTITY_ELEMENT;
- public static final String CREDENTIAL_ELEMENT_XPATH = "/"
- + CREDENTIAL_ELEMENT;
- public static final String SERVICES_ELEMENT_XPATH = "/" + SERVICES_ELEMENT
- + "/" + SERVICE_ELEMENT;
- public static final String SERVICE_ELEMENT_XPATH = "/" + SERVICE_ELEMENT;
- public static final String CARTRIDGE_ELEMENT_XPATH = "/"
- + CARTRIDGE_ELEMENT;
- public static final String PAYLOAD_ELEMENT_XPATH = "/" + PAYLOAD_ELEMENT;
- public static final String HOST_ELEMENT_XPATH = "/" + HOST_ELEMENT;
- public static final String CARTRIDGES_ELEMENT_XPATH = "/"
- + CARTRIDGES_ELEMENT + "/" + CARTRIDGE_ELEMENT;
- public static final String IAAS_PROVIDER_ELEMENT_XPATH = "/"
- + IAAS_PROVIDER_ELEMENT;
- public static final String DEPLOYMENT_ELEMENT_XPATH = "/"
- + DEPLOYMENT_ELEMENT;
- public static final String PORT_MAPPING_ELEMENT_XPATH = "/"
- + PORT_MAPPING_ELEMENT;
- public static final String APP_TYPES_ELEMENT_XPATH = "/"
- + APP_TYPES_ELEMENT;
+ /**
+ * XPath expressions
+ */
+ public static final String IAAS_PROVIDER_XPATH =
+ "/" + CLOUD_CONTROLLER_ELEMENT + "/" + IAAS_PROVIDERS_ELEMENT + "/" + IAAS_PROVIDER_ELEMENT;
+ public static final String PARTITION_XPATH =
+ "/" + CLOUD_CONTROLLER_ELEMENT + "/" + PARTITIONS_ELEMENT + "/" + PARTITION_ELEMENT;
+ public static final String REGION_XPATH =
+ "/" + CLOUD_CONTROLLER_ELEMENT + "/" + IAAS_PROVIDERS_ELEMENT + "/" + IAAS_PROVIDER_ELEMENT + "/" +
+ REGION_ELEMENT;
+ public static final String ZONE_XPATH =
+ "/" + CLOUD_CONTROLLER_ELEMENT + "/" + IAAS_PROVIDERS_ELEMENT + "/" + IAAS_PROVIDER_ELEMENT + "/" +
+ REGION_ELEMENT + "/" + ZONE_ELEMENT;
+ public static final String HOST_XPATH =
+ "/" + CLOUD_CONTROLLER_ELEMENT + "/" + IAAS_PROVIDERS_ELEMENT + "/" + IAAS_PROVIDER_ELEMENT + "/" +
+ REGION_ELEMENT + "/" + ZONE_ELEMENT + "/" + HOST_ELEMENT;
+ public static final String PROPERTY_ELEMENT_XPATH = "/" + PROPERTY_ELEMENT;
+ public static final String IMAGE_ID_ELEMENT_XPATH = "/" + IMAGE_ID_ELEMENT;
+ public static final String SCALE_UP_ORDER_ELEMENT_XPATH = "/" + SCALE_UP_ORDER_ELEMENT;
+ public static final String SCALE_DOWN_ORDER_ELEMENT_XPATH = "/" + SCALE_DOWN_ORDER_ELEMENT;
+ public static final String PROVIDER_ELEMENT_XPATH = "/" + PROPERTY_ELEMENT;
+ public static final String IDENTITY_ELEMENT_XPATH = "/" + IDENTITY_ELEMENT;
+ public static final String CREDENTIAL_ELEMENT_XPATH = "/" + CREDENTIAL_ELEMENT;
+ public static final String SERVICES_ELEMENT_XPATH = "/" + SERVICES_ELEMENT + "/" + SERVICE_ELEMENT;
+ public static final String SERVICE_ELEMENT_XPATH = "/" + SERVICE_ELEMENT;
+ public static final String CARTRIDGE_ELEMENT_XPATH = "/" + CARTRIDGE_ELEMENT;
+ public static final String PAYLOAD_ELEMENT_XPATH = "/" + PAYLOAD_ELEMENT;
+ public static final String HOST_ELEMENT_XPATH = "/" + HOST_ELEMENT;
+ public static final String CARTRIDGES_ELEMENT_XPATH = "/" + CARTRIDGES_ELEMENT + "/" + CARTRIDGE_ELEMENT;
+ public static final String IAAS_PROVIDER_ELEMENT_XPATH = "/" + IAAS_PROVIDER_ELEMENT;
+ public static final String DEPLOYMENT_ELEMENT_XPATH = "/" + DEPLOYMENT_ELEMENT;
+ public static final String PORT_MAPPING_ELEMENT_XPATH = "/" + PORT_MAPPING_ELEMENT;
+ public static final String APP_TYPES_ELEMENT_XPATH = "/" + APP_TYPES_ELEMENT;
- public static final String DATA_PUBLISHER_XPATH = "/"
- + CLOUD_CONTROLLER_ELEMENT + "/" + DATA_PUBLISHER_ELEMENT;
- public static final String TOPOLOGY_SYNC_XPATH = "/"
- + CLOUD_CONTROLLER_ELEMENT + "/" + TOPOLOGY_SYNC_ELEMENT;
- public static final String DATA_PUBLISHER_CRON_XPATH = "/"
- + CLOUD_CONTROLLER_ELEMENT + "/" + CRON_ELEMENT;
- public static final String BAM_SERVER_ADMIN_USERNAME_XPATH = "/"
- + CLOUD_CONTROLLER_ELEMENT + "/"
- + BAM_SERVER_ADMIN_USERNAME_ELEMENT;
- public static final String BAM_SERVER_ADMIN_PASSWORD_XPATH = "/"
- + CLOUD_CONTROLLER_ELEMENT + "/"
- + BAM_SERVER_ADMIN_PASSWORD_ELEMENT;
- // public static final String CASSANDRA_HOST_ADDRESS_XPATH =
- // "/"+CLOUD_CONTROLLER_ELEMENT+
- // "/"+CASSANDRA_HOST_ADDRESS;
- // public static final String CASSANDRA_HOST_PORT_XPATH =
- // "/"+CLOUD_CONTROLLER_ELEMENT+
- // "/"+CASSANDRA_HOST_PORT;
+ public static final String DATA_PUBLISHER_XPATH = "/" + CLOUD_CONTROLLER_ELEMENT + "/" + DATA_PUBLISHER_ELEMENT;
+ public static final String TOPOLOGY_SYNC_XPATH = "/" + CLOUD_CONTROLLER_ELEMENT + "/" + TOPOLOGY_SYNC_ELEMENT;
+ public static final String DATA_PUBLISHER_CRON_XPATH = "/" + CLOUD_CONTROLLER_ELEMENT + "/" + CRON_ELEMENT;
+ public static final String BAM_SERVER_ADMIN_USERNAME_XPATH =
+ "/" + CLOUD_CONTROLLER_ELEMENT + "/" + BAM_SERVER_ADMIN_USERNAME_ELEMENT;
+ public static final String BAM_SERVER_ADMIN_PASSWORD_XPATH =
+ "/" + CLOUD_CONTROLLER_ELEMENT + "/" + BAM_SERVER_ADMIN_PASSWORD_ELEMENT;
+ // public static final String CASSANDRA_HOST_ADDRESS_XPATH =
+ // "/"+CLOUD_CONTROLLER_ELEMENT+
+ // "/"+CASSANDRA_HOST_ADDRESS;
+ // public static final String CASSANDRA_HOST_PORT_XPATH =
+ // "/"+CLOUD_CONTROLLER_ELEMENT+
+ // "/"+CASSANDRA_HOST_PORT;
- /**
- * Secret Manager related aliases.
- */
- public static final String ALIAS_ATTRIBUTE = "secretAlias";
- public static final String ALIAS_ATTRIBUTE_PREFIX = "svns";
- public static final String ALIAS_NAMESPACE = "http://org.wso2.securevault/configuration";
+ /**
+ * Secret Manager related aliases.
+ */
+ public static final String ALIAS_ATTRIBUTE = "secretAlias";
+ public static final String ALIAS_ATTRIBUTE_PREFIX = "svns";
+ public static final String ALIAS_NAMESPACE = "http://org.wso2.securevault/configuration";
- /**
- * Payload related constants
- */
- public static final String PAYLOAD_NAME = "payload";
- public static final String ENTRY_SEPARATOR = ",";
+ /**
+ * Payload related constants
+ */
+ public static final String PAYLOAD_NAME = "payload";
+ public static final String ENTRY_SEPARATOR = ",";
- /**
- * Publisher task related constants
- */
- public static final String DATA_PUB_TASK_TYPE = "CLOUD_CONTROLLER_DATA_PUBLISHER_TASK";
- // default is : data publisher will run in first second of every minute
- public static final String PUB_CRON_EXPRESSION = "1 * * * * ? *";
- public static final String DATA_PUB_TASK_NAME = "CartridgeInstanceDataPublisher";
- public static final String DEFAULT_BAM_SERVER_USER_NAME = "admin";
- public static final String DEFAULT_BAM_SERVER_PASSWORD = "admin";
- public static final String DEFAULT_CASSANDRA_URL = "localhost:9160";
- public static final String DEFAULT_CASSANDRA_USER = "admin";
- public static final String DEFAULT_CASSANDRA_PASSWORD = "admin";
- public static final String DEFAULT_CASSANDRA_CLUSTER_NAME = "Test Cluster";
- public static final String DEFAULT_CASSANDRA_KEY_SPACE = "EVENT_KS";
+ /**
+ * Publisher task related constants
+ */
+ public static final String DATA_PUB_TASK_TYPE = "CLOUD_CONTROLLER_DATA_PUBLISHER_TASK";
+ // default is : data publisher will run in first second of every minute
+ public static final String PUB_CRON_EXPRESSION = "1 * * * * ? *";
+ public static final String DATA_PUB_TASK_NAME = "CartridgeInstanceDataPublisher";
+ public static final String DEFAULT_BAM_SERVER_USER_NAME = "admin";
+ public static final String DEFAULT_BAM_SERVER_PASSWORD = "admin";
+ public static final String DEFAULT_CASSANDRA_URL = "localhost:9160";
+ public static final String DEFAULT_CASSANDRA_USER = "admin";
+ public static final String DEFAULT_CASSANDRA_PASSWORD = "admin";
+ public static final String DEFAULT_CASSANDRA_CLUSTER_NAME = "Test Cluster";
+ public static final String DEFAULT_CASSANDRA_KEY_SPACE = "EVENT_KS";
- /**
- * Directories
- */
- public static final String SERVICES_DIR = CarbonUtils.getCarbonRepository()
- + File.separator + "services" + File.separator;
+ /**
+ * Directories
+ */
+ public static final String SERVICES_DIR =
+ CarbonUtils.getCarbonRepository() + File.separator + "services" + File.separator;
- /**
- * Topology sync related constants
- */
- public static final String TOPOLOGY_FILE_PATH = CarbonUtils
- .getCarbonConfigDirPath()
- + File.separator
- + "service-topology.conf";
- public static final String TOPOLOGY_SYNC_CRON = "1 * * * * ? *";
- public static final String TOPOLOGY_SYNC_TASK_NAME = "TOPOLOGY_SYNC_TASK";
- public static final String TOPOLOGY_SYNC_TASK_TYPE = "TOPOLOGY_SYNC_TASK_TYPE";
- public static final String AMQP_CONNECTION_URL = "amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5672'";
- public static final String AMQP_INITIAL_CONTEXT_FACTORY = "org.wso2.andes.jndi.PropertiesFileInitialContextFactory";
- public static final String AMQP_TOPIC_CONNECTION_FACTORY = "qpidConnectionfactory";
+ /**
+ * Topology sync related constants
+ */
+ public static final String TOPOLOGY_FILE_PATH =
+ CarbonUtils.getCarbonConfigDirPath() + File.separator + "service-topology.conf";
+ public static final String TOPOLOGY_SYNC_CRON = "1 * * * * ? *";
+ public static final String TOPOLOGY_SYNC_TASK_NAME = "TOPOLOGY_SYNC_TASK";
+ public static final String TOPOLOGY_SYNC_TASK_TYPE = "TOPOLOGY_SYNC_TASK_TYPE";
+ public static final String AMQP_CONNECTION_URL =
+ "amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5672'";
+ public static final String AMQP_INITIAL_CONTEXT_FACTORY = "org.wso2.andes.jndi.PropertiesFileInitialContextFactory";
+ public static final String AMQP_TOPIC_CONNECTION_FACTORY = "qpidConnectionfactory";
- /**
- * Persistence
- */
- public static final String DATA_RESOURCE = "/cloud.controller/data";
- public static final String TOPOLOGY_RESOURCE = "/cloud.controller/topology";
- public static final String AVAILABILITY_ZONE = "availabilityZone";
- public static final String KEY_PAIR = "keyPair";
- public static final String HOST = "host";
- public static final String SECURITY_GROUP_IDS = "securityGroupIds";
- public static final String SECURITY_GROUPS = "securityGroups";
- public static final String SUBNET_ID = "subnetId";
- public static final String TAGS = "tags";
- public static final String TAGS_AS_KEY_VALUE_PAIRS_PREFIX = "tag:";
- public static final String AUTO_ASSIGN_IP = "autoAssignIp";
- public static final String BLOCK_UNTIL_RUNNING = "blockUntilRunning";
- public static final String INSTANCE_TYPE = "instanceType";
- public static final String ASSOCIATE_PUBLIC_IP_ADDRESS = "associatePublicIpAddress";
- public static final String LB_CLUSTER_ID_COL = "lbclusterId";
- public static final String NETWORK_INTERFACES = "networkInterfaces";
- public static final String NETWORK_FIXED_IP = "fixedIp";
- public static final String NETWORK_PORT = "portUuid";
- public static final String NETWORK_UUID = "networkUuid";
+ /**
+ * Persistence
+ */
+ public static final String DATA_RESOURCE = "/cloud.controller/data";
+ public static final String TOPOLOGY_RESOURCE = "/cloud.controller/topology";
+ public static final String AVAILABILITY_ZONE = "availabilityZone";
+ public static final String KEY_PAIR = "keyPair";
+ public static final String HOST = "host";
+ public static final String SECURITY_GROUP_IDS = "securityGroupIds";
+ public static final String SECURITY_GROUPS = "securityGroups";
+ public static final String SUBNET_ID = "subnetId";
+ public static final String TAGS = "tags";
+ public static final String TAGS_AS_KEY_VALUE_PAIRS_PREFIX = "tag:";
+ public static final String AUTO_ASSIGN_IP = "autoAssignIp";
+ public static final String BLOCK_UNTIL_RUNNING = "blockUntilRunning";
+ public static final String INSTANCE_TYPE = "instanceType";
+ public static final String ASSOCIATE_PUBLIC_IP_ADDRESS = "associatePublicIpAddress";
+ public static final String LB_CLUSTER_ID_COL = "lbclusterId";
+ public static final String NETWORK_INTERFACES = "networkInterfaces";
+ public static final String NETWORK_FIXED_IP = "fixedIp";
+ public static final String NETWORK_PORT = "portUuid";
+ public static final String NETWORK_UUID = "networkUuid";
- // CloudStack specific
- public static final String USER_NAME = "username";
- public static final String DOMAIN_ID = "domainId";
- public static final String DISK_OFFERING = "diskOffering";
- public static final String NETWORK_IDS = "networkIds";
+ // CloudStack specific
+ public static final String USER_NAME = "username";
+ public static final String DOMAIN_ID = "domainId";
+ public static final String DISK_OFFERING = "diskOffering";
+ public static final String NETWORK_IDS = "networkIds";
- public static final String IS_LOAD_BALANCER = "load.balancer";
+ public static final String IS_LOAD_BALANCER = "load.balancer";
- /**
- * PortRange min max
- */
- public static final int PORT_RANGE_MAX = 65535;
- public static final int PORT_RANGE_MIN = 1;
+ /**
+ * PortRange min max
+ */
+ public static final int PORT_RANGE_MAX = 65535;
+ public static final int PORT_RANGE_MIN = 1;
- public static final String KUBERNETES_PARTITION_PROVIDER = "kubernetes";
+ public static final String KUBERNETES_PARTITION_PROVIDER = "kubernetes";
- /**
- * Load balancing ip type enumeration values
- */
- public static final String LOADBALANCING_IP_TYPE_PRIVATE = "private";
- public static final String LOADBALANCING_IP_TYPE_PUBLIC = "public";
+ /**
+ * Load balancing ip type enumeration values
+ */
+ public static final String LOADBALANCING_IP_TYPE_PRIVATE = "private";
+ public static final String LOADBALANCING_IP_TYPE_PUBLIC = "public";
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/76c7724b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java
index 1275f5c..9cf2007 100644
--- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java
+++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java
@@ -18,197 +18,192 @@
*/
package org.apache.stratos.common.constants;
-
public class StratosConstants {
- public static final String CLOUD_SERVICE_IS_ACTIVE_PROP_KEY = "active";
-
- public static final String CLOUD_SERVICE_INFO_STORE_PATH =
- "/repository/components/org.apache.stratos/cloud-manager/cloud-services";
-
- public static final String TENANT_USER_VALIDATION_STORE_PATH =
- "/repository/components/org.wso2.carbon.validations";
- public static final String ADMIN_EMAIL_VERIFICATION_FLAG_PATH =
- "/repository/components/org.wso2.carbon.email-confirmation-flag";
- public static final String TENANT_DOMAIN_VERIFICATION_FLAG_PATH =
- "/repository/components/org.wso2.carbon.domain-confirmation-flag";
-
- public static final String DOMAIN_VALIDATOR_INFO_PATH =
- "/repository/components/org.wso2.carbon.domain-validator-info";
-
- public static final String TENANT_CREATION_THEME_PAGE_TOKEN =
- "/repository/components/org.wso2.carbon.theme-page-token";
-
- public static final String TENANT_PACKAGE_INFO_PATH =
- "/repository/components/org.wso2.carbon.package-info";
-
- public static final String ALL_THEMES_PATH =
- "/repository/components/org.wso2.carbon.all-themes";
-
- public static final String THROTTLING_RULES_PATH =
- "/repository/components/org.wso2.carbon.throttling-rules";
-
- public static final String ORIGINATED_SERVICE_PATH =
- "/repository/components/org.wso2.carbon.originated-service";
-
- public static final String PATH_SEPARATOR = "/";
-
- public static final String CLOUD_SERVICE_ICONS_STORE_PATH =
- "/repository/components/org.wso2.carbon.cloud-manager/" +
- "cloud-services-icons";
-
- public static final String VALIDATION_KEY_RESOURCE_NAME = "validation-key";
- public static final String INCOMING_PATH_DIR = "incoming";
- public static final String OUTGOING_PATH_DIR = "outgoing";
- public static final String MULTITENANCY_SCHEDULED_TASK_ID = "multitenancyScheduledTask";
- public static final String MULTITENANCY_VIEWING_TASK_ID = "multitenancyViewingTask";
-
- public static final String INVALID_TENANT = "invalidTenant";
- public static final String INACTIVE_TENANT = "inactiveTenant";
- public static final String ACTIVE_TENANT = "activeTenant";
- public static final String IS_EMAIL_VALIDATED = "isEmailValidated";
- public static final String IS_CREDENTIALS_ALREADY_RESET = "isCredentialsReset";
- public static final String TENANT_ADMIN = "tenantAdminUsername";
-
- public static final String CLOUD_MANAGER_SERVICE = "Apache Stratos Controller";
- public static final String CLOUD_IDENTITY_SERVICE = "WSO2 Stratos Identity";
- public static final String CLOUD_GOVERNANCE_SERVICE = "WSO2 Stratos Governance";
- public static final String CLOUD_ESB_SERVICE = "WSO2 Stratos Enterprise Service Bus";
-
- // keystore mgt related Constants
- public static final String TENANT_KS = "/repository/security/key-stores/";
- public static final String TENANT_PUB_KEY = "/repository/security/pub-key";
- public static final String PROP_TENANT_KS_TYPE = "key-store-type";
- public static final String PROP_TENANT_KS_PASSWD = "key-store-password";
- public static final String PROP_TENANT_KS_PRIV_KEY_PASSWD = "priv-key-password";
- public static final String PROP_TENANT_KS_ALIAS = "alias";
-
- // constants related to redirection
-
- public static final String UNVERIFIED_ACCOUNT_DOMAIN_SUFFIX = "-unverified";
- public static final String TENANT_SPECIFIC_URL_RESOLVED = "tenant-sepcific-url-resolved";
- public static final String SUFFIXED_UNVERIFIED_SESSION_FLAG = "temp-suffixed-unverified";
-
- // metering constants
- public static final String THROTTLING_ALL_ACTION = "all_actions";
- public static final String THROTTLING_IN_DATA_ACTION = "in_data_action"; //this covers registry capacity + registry bandwidth
- public static final String THROTTLING_OUT_DATA_ACTION = "out_data_action"; //this covers registry bandwidth
- public static final String THROTTLING_ADD_USER_ACTION = "add_user_action";
- public static final String THROTTLING_SERVICE_IN_BANDWIDTH_ACTION = "service_in_bandwith_action";
- public static final String THROTTLING_SERVICE_OUT_BANDWIDTH_ACTION = "service_out_bandwith_action";
- public static final String THROTTLING_WEBAPP_IN_BANDWIDTH_ACTION = "webapp_in_bandwith_action";
- public static final String THROTTLING_WEBAPP_OUT_BANDWIDTH_ACTION = "webapp_out_bandwith_action";
- public static final String THROTTLING_SERVICE_REQUEST_ACTION = "service_request_action";
- public static final String THROTTLING_SERVICE_RESPONSE_ACTION = "service_response_action";
-
- // the session attribute to keep track whether the registry action validated
- // and the usage persisted
- public static final String REGISTRY_ACTION_VALIDATED_SESSION_ATTR = "registryActionValidated";
- public static final String REGISTRY_USAGE_PERSISTED_SESSION_ATTR = "usagePersited";
-
- // Metering servlet attributes
- public static final String SERVICE_NAME_SERVLET_ATTR = "meteringServiceName";
- public static final String TENANT_ID_SERVLET_ATTR = "tenantId";
- public static final String ADMIN_SERVICE_SERVLET_ATTR = "adminService";
-
- // * as a Service impl related constants
- public static final String ORIGINATED_SERVICE = "originatedService";
-
- // Configuration file name
- public static final String STRATOS_CONF_FILE = "stratos.xml";
- //public static final String STRATOS_CONF_LOC = "repository/conf/";
- //public static final String STRATOS_CONF_FILE_WITH_PATH = STRATOS_CONF_LOC + STRATOS_CONF_FILE;
-
- // EULA location
- public static final String STRATOS_EULA = "eula.xml";
-
- // EULA default text.
- public static final String STRATOS_EULA_DEFAULT_TEXT =
- "Please refer to: " + StratosConstants.STRATOS_TERMS_OF_USAGE +
- " for terms and usage and " + StratosConstants.STRATOS_PRIVACY_POLICY +
- " for privacy policy of WSO2 Stratos.";
-
- // Web location of Terms of Usage and privacy policy
- public static final String STRATOS_TERMS_OF_USAGE =
- "http://wso2.com/cloud/services/terms-of-use/";
- public static final String STRATOS_PRIVACY_POLICY =
- "http://wso2.com/cloud/services/privacy-policy/";
- public static final String MULTITENANCY_FREE_PLAN = "Demo";
- public static final String MULTITENANCY_SMALL_PLAN = "SMB";
- public static final String MULTITENANCY_MEDIUM_PLAN = "Professional";
- public static final String MULTITENANCY_LARGE_PLAN = "Enterprise";
- public static final String EMAIL_CONFIG = "email";
- public static final String MULTITENANCY_CONFIG_FOLDER = "multitenancy";
-
- // Cloud controller - payload
- public static final String MEMBER_ID = "MEMBER_ID";
- public static final String LB_CLUSTER_ID = "LB_CLUSTER_ID";
- public static final String NETWORK_PARTITION_ID = "NETWORK_PARTITION_ID";
-
- // Kubernetes related constants
- public static final String KUBERNETES_CLUSTER_ID = "KUBERNETES_CLUSTER_ID";
- public static final String KUBERNETES_MASTER_PORT = "KUBERNETES_MASTER_PORT";
- public static final String KUBERNETES_MASTER_DEFAULT_PORT = "8080";
-
- //drools related constants
- public static final String DROOLS_DIR_NAME = "drools";
- public static final String SCALE_CHECK_DROOL_FILE = "scaling.drl";
- public static final String DEPENDENT_SCALE_CHECK_DROOL_FILE = "dependent-scaling.drl";
- public static final String MIN_CHECK_DROOL_FILE = "mincheck.drl";
- public static final String MAX_CHECK_DROOL_FILE = "maxcheck.drl";
- public static final String OBSOLETE_CHECK_DROOL_FILE = "obsoletecheck.drl";
- public static final String MIN_COUNT = "MIN_COUNT";
-
- // Policy and definition related constants
- public static final int PUBLIC_DEFINITION = 0;
-
- // member expiry timeout constants
- public static final String PENDING_MEMBER_EXPIRY_TIMEOUT = "autoscaler.member.pendingMemberExpiryTimeout";
- public static final String OBSOLETED_MEMBER_EXPIRY_TIMEOUT = "autoscaler.member.obsoletedMemberExpiryTimeout";
- public static final String PENDING_TERMINATION_MEMBER_EXPIRY_TIMEOUT = "autoscaler.member.pendingTerminationMemberExpiryTimeout";
-
- public static final String FILTER_VALUE_SEPARATOR = ",";
- public static final String TOPOLOGY_APPLICATION_FILTER = "stratos.topology.application.filter";
- public static final String TOPOLOGY_SERVICE_FILTER = "stratos.topology.service.filter";
- public static final String TOPOLOGY_CLUSTER_FILTER = "stratos.topology.cluster.filter";
- public static final String TOPOLOGY_MEMBER_FILTER = "stratos.topology.member.filter";
- public static final String TOPOLOGY_NETWORK_PARTITION_FILTER = "stratos.topology.network.partition.filter";
-
- // to identify a lb cluster
- public static final String LOAD_BALANCER_REF = "load.balancer.ref";
- public static final String SERVICE_AWARE_LOAD_BALANCER = "service.aware.load.balancer";
- public static final String DEFAULT_LOAD_BALANCER = "default.load.balancer";
- public static final String NO_LOAD_BALANCER = "no.load.balancer";
- public static final String EXISTING_LOAD_BALANCERS = "existing.load.balancers";
-
- public static final long HAZELCAST_INSTANCE_INIT_TIMEOUT = 300000; // 5 min
-
- public static final String AUTOSCALER_SERVICE_URL = "autoscaler.service.url";
- public static final String CLOUD_CONTROLLER_SERVICE_URL = "cloud.controller.service.url";
- public static final String STRATOS_MANAGER_SERVICE_URL = "stratos.manager.service.url";
-
- public static final String CLOUD_CONTROLLER_CLIENT_SOCKET_TIMEOUT = "cc.socket.timeout";
- public static final String CLOUD_CONTROLLER_CLIENT_CONNECTION_TIMEOUT = "cc.connection.timeout";
- public static final String AUTOSCALER_CLIENT_SOCKET_TIMEOUT = "autoscaler.socket.timeout";
- public static final String AUTOSCALER_CLIENT_CONNECTION_TIMEOUT = "autoscaler.connection.timeout";
- public static final String STRATOS_MANAGER_CLIENT_SOCKET_TIMEOUT = "stratos.manager.socket.timeout";
- public static final String STRATOS_MANAGER_CLIENT_CONNECTION_TIMEOUT = "stratos.manager.connection.timeout";
-
- public static final String DEFAULT_CLIENT_SOCKET_TIMEOUT = "300000";
- public static final String DEFAULT_CLIENT_CONNECTION_TIMEOUT = "300000";
-
- // partition algorithm id constants
- public static final String PARTITION_ROUND_ROBIN_ALGORITHM_ID = "round-robin";
- public static final String PARTITION_WEIGHTED_ROUND_ROBIN_ALGORITHM_ID = "weighted-round-robin";
- public static final String PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID = "one-after-another";
- // network partition algorithm id constants
- public static final String NETWORK_PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID = "one-after-another";
- public static final String NETWORK_PARTITION_ALL_AT_ONCE_ALGORITHM_ID = "all-at-once";
- public static final String APPLICATION_POLICY_NETWORK_PARTITION_GROUPS = "networkPartitionGroups";
- public static final String APPLICATION_POLICY_NETWORK_PARTITIONS_SPLITTER = "\\|";
- public static final String APPLICATION_POLICY_NETWORK_PARTITION_GROUPS_SPLITTER = ",";
-
- public static final String NOT_DEFINED = "not-defined";
- public static final String CLUSTER_INSTANCE_ID = "cluster.instance.id";
+ public static final String CLOUD_SERVICE_IS_ACTIVE_PROP_KEY = "active";
+
+ public static final String CLOUD_SERVICE_INFO_STORE_PATH =
+ "/repository/components/org.apache.stratos/cloud-manager/cloud-services";
+
+ public static final String TENANT_USER_VALIDATION_STORE_PATH = "/repository/components/org.wso2.carbon.validations";
+ public static final String ADMIN_EMAIL_VERIFICATION_FLAG_PATH =
+ "/repository/components/org.wso2.carbon.email-confirmation-flag";
+ public static final String TENANT_DOMAIN_VERIFICATION_FLAG_PATH =
+ "/repository/components/org.wso2.carbon.domain-confirmation-flag";
+
+ public static final String DOMAIN_VALIDATOR_INFO_PATH =
+ "/repository/components/org.wso2.carbon.domain-validator-info";
+
+ public static final String TENANT_CREATION_THEME_PAGE_TOKEN =
+ "/repository/components/org.wso2.carbon.theme-page-token";
+
+ public static final String TENANT_PACKAGE_INFO_PATH = "/repository/components/org.wso2.carbon.package-info";
+
+ public static final String ALL_THEMES_PATH = "/repository/components/org.wso2.carbon.all-themes";
+
+ public static final String THROTTLING_RULES_PATH = "/repository/components/org.wso2.carbon.throttling-rules";
+
+ public static final String ORIGINATED_SERVICE_PATH = "/repository/components/org.wso2.carbon.originated-service";
+
+ public static final String PATH_SEPARATOR = "/";
+
+ public static final String CLOUD_SERVICE_ICONS_STORE_PATH =
+ "/repository/components/org.wso2.carbon.cloud-manager/" + "cloud-services-icons";
+
+ public static final String VALIDATION_KEY_RESOURCE_NAME = "validation-key";
+ public static final String INCOMING_PATH_DIR = "incoming";
+ public static final String OUTGOING_PATH_DIR = "outgoing";
+ public static final String MULTITENANCY_SCHEDULED_TASK_ID = "multitenancyScheduledTask";
+ public static final String MULTITENANCY_VIEWING_TASK_ID = "multitenancyViewingTask";
+
+ public static final String INVALID_TENANT = "invalidTenant";
+ public static final String INACTIVE_TENANT = "inactiveTenant";
+ public static final String ACTIVE_TENANT = "activeTenant";
+ public static final String IS_EMAIL_VALIDATED = "isEmailValidated";
+ public static final String IS_CREDENTIALS_ALREADY_RESET = "isCredentialsReset";
+ public static final String TENANT_ADMIN = "tenantAdminUsername";
+
+ public static final String CLOUD_MANAGER_SERVICE = "Apache Stratos Controller";
+ public static final String CLOUD_IDENTITY_SERVICE = "WSO2 Stratos Identity";
+ public static final String CLOUD_GOVERNANCE_SERVICE = "WSO2 Stratos Governance";
+ public static final String CLOUD_ESB_SERVICE = "WSO2 Stratos Enterprise Service Bus";
+
+ // keystore mgt related Constants
+ public static final String TENANT_KS = "/repository/security/key-stores/";
+ public static final String TENANT_PUB_KEY = "/repository/security/pub-key";
+ public static final String PROP_TENANT_KS_TYPE = "key-store-type";
+ public static final String PROP_TENANT_KS_PASSWD = "key-store-password";
+ public static final String PROP_TENANT_KS_PRIV_KEY_PASSWD = "priv-key-password";
+ public static final String PROP_TENANT_KS_ALIAS = "alias";
+
+ // constants related to redirection
+
+ public static final String UNVERIFIED_ACCOUNT_DOMAIN_SUFFIX = "-unverified";
+ public static final String TENANT_SPECIFIC_URL_RESOLVED = "tenant-sepcific-url-resolved";
+ public static final String SUFFIXED_UNVERIFIED_SESSION_FLAG = "temp-suffixed-unverified";
+
+ // metering constants
+ public static final String THROTTLING_ALL_ACTION = "all_actions";
+ public static final String THROTTLING_IN_DATA_ACTION = "in_data_action";
+ //this covers registry capacity + registry bandwidth
+ public static final String THROTTLING_OUT_DATA_ACTION = "out_data_action"; //this covers registry bandwidth
+ public static final String THROTTLING_ADD_USER_ACTION = "add_user_action";
+ public static final String THROTTLING_SERVICE_IN_BANDWIDTH_ACTION = "service_in_bandwith_action";
+ public static final String THROTTLING_SERVICE_OUT_BANDWIDTH_ACTION = "service_out_bandwith_action";
+ public static final String THROTTLING_WEBAPP_IN_BANDWIDTH_ACTION = "webapp_in_bandwith_action";
+ public static final String THROTTLING_WEBAPP_OUT_BANDWIDTH_ACTION = "webapp_out_bandwith_action";
+ public static final String THROTTLING_SERVICE_REQUEST_ACTION = "service_request_action";
+ public static final String THROTTLING_SERVICE_RESPONSE_ACTION = "service_response_action";
+
+ // the session attribute to keep track whether the registry action validated
+ // and the usage persisted
+ public static final String REGISTRY_ACTION_VALIDATED_SESSION_ATTR = "registryActionValidated";
+ public static final String REGISTRY_USAGE_PERSISTED_SESSION_ATTR = "usagePersited";
+
+ // Metering servlet attributes
+ public static final String SERVICE_NAME_SERVLET_ATTR = "meteringServiceName";
+ public static final String TENANT_ID_SERVLET_ATTR = "tenantId";
+ public static final String ADMIN_SERVICE_SERVLET_ATTR = "adminService";
+
+ // * as a Service impl related constants
+ public static final String ORIGINATED_SERVICE = "originatedService";
+
+ // Configuration file name
+ public static final String STRATOS_CONF_FILE = "stratos.xml";
+ //public static final String STRATOS_CONF_LOC = "repository/conf/";
+ //public static final String STRATOS_CONF_FILE_WITH_PATH = STRATOS_CONF_LOC + STRATOS_CONF_FILE;
+
+ // EULA location
+ public static final String STRATOS_EULA = "eula.xml";
+
+ // EULA default text.
+ public static final String STRATOS_EULA_DEFAULT_TEXT =
+ "Please refer to: " + StratosConstants.STRATOS_TERMS_OF_USAGE +
+ " for terms and usage and " + StratosConstants.STRATOS_PRIVACY_POLICY +
+ " for privacy policy of WSO2 Stratos.";
+
+ // Web location of Terms of Usage and privacy policy
+ public static final String STRATOS_TERMS_OF_USAGE = "http://wso2.com/cloud/services/terms-of-use/";
+ public static final String STRATOS_PRIVACY_POLICY = "http://wso2.com/cloud/services/privacy-policy/";
+ public static final String MULTITENANCY_FREE_PLAN = "Demo";
+ public static final String MULTITENANCY_SMALL_PLAN = "SMB";
+ public static final String MULTITENANCY_MEDIUM_PLAN = "Professional";
+ public static final String MULTITENANCY_LARGE_PLAN = "Enterprise";
+ public static final String EMAIL_CONFIG = "email";
+ public static final String MULTITENANCY_CONFIG_FOLDER = "multitenancy";
+
+ // Cloud controller - payload
+ public static final String MEMBER_ID = "MEMBER_ID";
+ public static final String LB_CLUSTER_ID = "LB_CLUSTER_ID";
+ public static final String NETWORK_PARTITION_ID = "NETWORK_PARTITION_ID";
+
+ // Kubernetes related constants
+ public static final String KUBERNETES_CLUSTER_ID = "KUBERNETES_CLUSTER_ID";
+ public static final String KUBERNETES_MASTER_PORT = "KUBERNETES_MASTER_PORT";
+ public static final String KUBERNETES_MASTER_DEFAULT_PORT = "8080";
+
+ //drools related constants
+ public static final String DROOLS_DIR_NAME = "drools";
+ public static final String SCALE_CHECK_DROOL_FILE = "scaling.drl";
+ public static final String DEPENDENT_SCALE_CHECK_DROOL_FILE = "dependent-scaling.drl";
+ public static final String MIN_CHECK_DROOL_FILE = "mincheck.drl";
+ public static final String MAX_CHECK_DROOL_FILE = "maxcheck.drl";
+ public static final String OBSOLETE_CHECK_DROOL_FILE = "obsoletecheck.drl";
+ public static final String MIN_COUNT = "MIN_COUNT";
+ public static final String SCALING_REASON = "SCALING_REASON";
+ public static final String SCALING_TIME = "SCALING_TIME";
+
+ // Policy and definition related constants
+ public static final int PUBLIC_DEFINITION = 0;
+
+ // member expiry timeout constants
+ public static final String PENDING_MEMBER_EXPIRY_TIMEOUT = "autoscaler.member.pendingMemberExpiryTimeout";
+ public static final String OBSOLETED_MEMBER_EXPIRY_TIMEOUT = "autoscaler.member.obsoletedMemberExpiryTimeout";
+ public static final String PENDING_TERMINATION_MEMBER_EXPIRY_TIMEOUT =
+ "autoscaler.member.pendingTerminationMemberExpiryTimeout";
+
+ public static final String FILTER_VALUE_SEPARATOR = ",";
+ public static final String TOPOLOGY_APPLICATION_FILTER = "stratos.topology.application.filter";
+ public static final String TOPOLOGY_SERVICE_FILTER = "stratos.topology.service.filter";
+ public static final String TOPOLOGY_CLUSTER_FILTER = "stratos.topology.cluster.filter";
+ public static final String TOPOLOGY_MEMBER_FILTER = "stratos.topology.member.filter";
+ public static final String TOPOLOGY_NETWORK_PARTITION_FILTER = "stratos.topology.network.partition.filter";
+
+ // to identify a lb cluster
+ public static final String LOAD_BALANCER_REF = "load.balancer.ref";
+ public static final String SERVICE_AWARE_LOAD_BALANCER = "service.aware.load.balancer";
+ public static final String DEFAULT_LOAD_BALANCER = "default.load.balancer";
+ public static final String NO_LOAD_BALANCER = "no.load.balancer";
+ public static final String EXISTING_LOAD_BALANCERS = "existing.load.balancers";
+
+ public static final long HAZELCAST_INSTANCE_INIT_TIMEOUT = 300000; // 5 min
+
+ public static final String AUTOSCALER_SERVICE_URL = "autoscaler.service.url";
+ public static final String CLOUD_CONTROLLER_SERVICE_URL = "cloud.controller.service.url";
+ public static final String STRATOS_MANAGER_SERVICE_URL = "stratos.manager.service.url";
+
+ public static final String CLOUD_CONTROLLER_CLIENT_SOCKET_TIMEOUT = "cc.socket.timeout";
+ public static final String CLOUD_CONTROLLER_CLIENT_CONNECTION_TIMEOUT = "cc.connection.timeout";
+ public static final String AUTOSCALER_CLIENT_SOCKET_TIMEOUT = "autoscaler.socket.timeout";
+ public static final String AUTOSCALER_CLIENT_CONNECTION_TIMEOUT = "autoscaler.connection.timeout";
+ public static final String STRATOS_MANAGER_CLIENT_SOCKET_TIMEOUT = "stratos.manager.socket.timeout";
+ public static final String STRATOS_MANAGER_CLIENT_CONNECTION_TIMEOUT = "stratos.manager.connection.timeout";
+
+ public static final String DEFAULT_CLIENT_SOCKET_TIMEOUT = "300000";
+ public static final String DEFAULT_CLIENT_CONNECTION_TIMEOUT = "300000";
+
+ // partition algorithm id constants
+ public static final String PARTITION_ROUND_ROBIN_ALGORITHM_ID = "round-robin";
+ public static final String PARTITION_WEIGHTED_ROUND_ROBIN_ALGORITHM_ID = "weighted-round-robin";
+ public static final String PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID = "one-after-another";
+ // network partition algorithm id constants
+ public static final String NETWORK_PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID = "one-after-another";
+ public static final String NETWORK_PARTITION_ALL_AT_ONCE_ALGORITHM_ID = "all-at-once";
+ public static final String APPLICATION_POLICY_NETWORK_PARTITION_GROUPS = "networkPartitionGroups";
+ public static final String APPLICATION_POLICY_NETWORK_PARTITIONS_SPLITTER = "\\|";
+ public static final String APPLICATION_POLICY_NETWORK_PARTITION_GROUPS_SPLITTER = ",";
+
+ public static final String NOT_DEFINED = "not-defined";
+ public static final String CLUSTER_INSTANCE_ID = "cluster.instance.id";
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/76c7724b/products/stratos/modules/distribution/src/main/conf/drools/dependent-scaling.drl
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/conf/drools/dependent-scaling.drl b/products/stratos/modules/distribution/src/main/conf/drools/dependent-scaling.drl
index 56e9164..43b204f 100644
--- a/products/stratos/modules/distribution/src/main/conf/drools/dependent-scaling.drl
+++ b/products/stratos/modules/distribution/src/main/conf/drools/dependent-scaling.drl
@@ -84,7 +84,10 @@ dialect "mvel"
log.info("[dependency-scale] [scale-up] Partition available, hence trying to spawn an instance to scale up!" );
log.debug("[dependency-scale] [scale-up] " + " [partition] " + partitionContext.getPartitionId() + " [cluster] " + clusterId );
- delegator.delegateSpawn(partitionContext, clusterId, clusterInstanceContext.getId(), isPrimary);
+ long time = System.currentTimeMillis();
+ String scalingReason = "Dependency scaling";
+ delegator.delegateSpawn(partitionContext, clusterId, clusterInstanceContext.getId(), isPrimary,scalingReason,time);
+
count++;
} else {
partitionsAvailable = false;
http://git-wip-us.apache.org/repos/asf/stratos/blob/76c7724b/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl b/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl
index e6f8f67..cad9c8f 100644
--- a/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl
+++ b/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl
@@ -164,6 +164,9 @@ dialect "mvel"
boolean partitionsAvailable = true;
int count = 0;
+ String autoscalingReason = (numberOfRequiredInstances == numberOfInstancesReuquiredBasedOnRif)?"Scaling up due to RIF":(numberOfRequiredInstances== numberOfInstancesReuquiredBasedOnMemoryConsumption)?"Scaling up due to MC":"Scaling up due to LA";
+
+
while(count != additionalInstances && partitionsAvailable){
ClusterLevelPartitionContext partitionContext = (ClusterLevelPartitionContext) partitionAlgorithm.getNextScaleUpPartitionContext(clusterInstanceContext.getPartitionCtxtsAsAnArray());
@@ -182,7 +185,8 @@ dialect "mvel"
" [laPredictedValue] " + laPredictedValue + " [laThreshold] " + laThreshold);
log.debug("[scale-up] " + " [partition] " + partitionContext.getPartitionId() + " [cluster] " + clusterId );
- delegator.delegateSpawn(partitionContext, clusterId, clusterInstanceContext.getId(), isPrimary);
+ long scalingTime = System.currentTimeMillis();
+ delegator.delegateSpawn(partitionContext, clusterId, clusterInstanceContext.getId(), isPrimary,autoscalingReason,scalingTime);
count++;
} else {
[17/18] stratos git commit: Formatting the code
Posted by im...@apache.org.
Formatting the code
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/218b5fdc
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/218b5fdc
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/218b5fdc
Branch: refs/heads/master
Commit: 218b5fdc520344547abf4d8f11fbc8964919f5f6
Parents: a61331e
Author: Thanuja <th...@wso2.com>
Authored: Thu Jul 23 15:51:41 2015 +0530
Committer: Thanuja <th...@wso2.com>
Committed: Thu Jul 23 15:51:41 2015 +0530
----------------------------------------------------------------------
.../client/AutoscalerCloudControllerClient.java | 402 +--
.../messaging/topology/TopologyBuilder.java | 1986 +++++------
.../impl/CloudControllerServiceImpl.java | 3191 +++++++++---------
.../impl/CloudControllerServiceUtil.java | 134 +-
.../publisher/BAMUsageDataPublisher.java | 358 +-
.../common/constants/StratosConstants.java | 370 +-
.../modules/healthstatspublisher/healthstats.py | 2 +-
.../src/main/conf/drools/scaling.drl | 3 -
8 files changed, 3237 insertions(+), 3209 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/218b5fdc/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/AutoscalerCloudControllerClient.java
----------------------------------------------------------------------
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 67fd956..f478ee9 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
@@ -48,205 +48,205 @@ import java.util.List;
*/
public class AutoscalerCloudControllerClient {
- private static final Log log = LogFactory.getLog(AutoscalerCloudControllerClient.class);
-
- 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();
- int port =
- conf.getInt("autoscaler.cloudController.port", AutoscalerConstants.CLOUD_CONTROLLER_DEFAULT_PORT);
- String hostname = conf.getString("autoscaler.cloudController.hostname", "localhost");
- String epr = "https://" + hostname + ":" + port + "/" + AutoscalerConstants.CLOUD_CONTROLLER_SERVICE_SFX;
- int cloudControllerClientTimeout = conf.getInt("autoscaler.cloudController.clientTimeout", 180000);
-
- stub = new CloudControllerServiceStub(epr);
- stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, cloudControllerClientTimeout);
- stub._getServiceClient().getOptions()
- .setProperty(HTTPConstants.CONNECTION_TIMEOUT, cloudControllerClientTimeout);
- } catch (Exception e) {
- log.error("Could not initialize cloud controller client", e);
- }
- }
-
- public synchronized MemberContext startInstance(PartitionRef partition, String clusterId, String clusterInstanceId,
- String networkPartitionId, boolean isPrimary, int minMemberCount,
- String autoscalingReason, long scalingTime)
- throws SpawningException {
- try {
- if (log.isInfoEnabled()) {
- log.info(String.format("Trying to spawn an instance via cloud controller: " +
- "[cluster] %s [partition] %s [network-partition-id] %s", clusterId,
- partition.getId(), networkPartitionId));
- }
-
- XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
- long expiryTime = conf.getLong(StratosConstants.OBSOLETED_MEMBER_EXPIRY_TIMEOUT, 86400000);
- if (log.isDebugEnabled()) {
- log.debug("Member obsolete expiry time is set to: " + expiryTime);
- }
-
- InstanceContext instanceContext = new InstanceContext();
- instanceContext.setClusterId(clusterId);
- instanceContext.setClusterInstanceId(clusterInstanceId);
- instanceContext.setPartition(AutoscalerObjectConverter.convertPartitionToCCPartition(partition));
- instanceContext.setInitTime(System.currentTimeMillis());
- instanceContext.setObsoleteExpiryTime(expiryTime);
- instanceContext.setNetworkPartitionId(networkPartitionId);
-
- Properties memberContextProps = new Properties();
- Property isPrimaryProp = new Property();
- isPrimaryProp.setName("PRIMARY");
- isPrimaryProp.setValue(String.valueOf(isPrimary));
-
- Property minCountProp = new Property();
- minCountProp.setName(StratosConstants.MIN_COUNT);
- minCountProp.setValue(String.valueOf(minMemberCount));
-
- Property autoscalingReasonProp = new Property();
- autoscalingReasonProp.setName(StratosConstants.SCALING_REASON);
- autoscalingReasonProp.setValue(autoscalingReason);
-
- Property scalingTimeProp = new Property();
- scalingTimeProp.setName(StratosConstants.SCALING_TIME);
- scalingTimeProp.setValue(String.valueOf(scalingTime));
-
- memberContextProps.addProperty(isPrimaryProp);
- memberContextProps.addProperty(minCountProp);
- memberContextProps.addProperty(autoscalingReasonProp);
- memberContextProps.addProperty(scalingTimeProp);
- instanceContext.setProperties(AutoscalerUtil.toStubProperties(memberContextProps));
-
- long startTime = System.currentTimeMillis();
- MemberContext memberContext = stub.startInstance(instanceContext);
-
- if (log.isDebugEnabled()) {
- long endTime = System.currentTimeMillis();
- log.debug(String.format("Service call startInstance() returned in %dms", (endTime - startTime)));
- }
- return memberContext;
- } catch (CloudControllerServiceCartridgeNotFoundExceptionException e) {
- String message = e.getFaultMessage().getCartridgeNotFoundException().getMessage();
- log.error(message, e);
- throw new SpawningException(message, e);
- } catch (RemoteException e) {
- log.error(e.getMessage(), e);
- throw new SpawningException(e.getMessage(), e);
- } catch (CloudControllerServiceInvalidIaasProviderExceptionException e) {
- String message = e.getFaultMessage().getInvalidIaasProviderException().getMessage();
- log.error(message, e);
- throw new SpawningException(message, e);
- } catch (CloudControllerServiceCloudControllerExceptionException e) {
- String message = e.getMessage();
- log.error(message, e);
- throw new SpawningException(message, e);
- }
- }
-
- public synchronized void createApplicationClusters(String appId,
- ApplicationClusterContext[] applicationClusterContexts) {
- List<org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext> contextDTOs =
- new ArrayList<org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext>();
- if (applicationClusterContexts != null) {
- for (ApplicationClusterContext applicationClusterContext : applicationClusterContexts) {
- if (applicationClusterContext != null) {
- org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext dto =
- new org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext();
- dto.setClusterId(applicationClusterContext.getClusterId());
- dto.setAutoscalePolicyName(applicationClusterContext.getAutoscalePolicyName());
- dto.setDeploymentPolicyName(applicationClusterContext.getDeploymentPolicyName());
- dto.setCartridgeType(applicationClusterContext.getCartridgeType());
- dto.setHostName(applicationClusterContext.getHostName());
- dto.setTenantRange(applicationClusterContext.getTenantRange());
- dto.setTextPayload(applicationClusterContext.getTextPayload());
- dto.setProperties(AutoscalerUtil.toStubProperties(applicationClusterContext.getProperties()));
- dto.setDependencyClusterIds(applicationClusterContext.getDependencyClusterIds());
- if (applicationClusterContext.getPersistenceContext() != null) {
- dto.setVolumeRequired(true);
- dto.setVolumes(convertVolumesToStubVolumes(
- applicationClusterContext.getPersistenceContext().getVolumes()));
- }
- contextDTOs.add(dto);
- }
- }
- }
-
- org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext[] applicationClusterContextDTOs =
- new org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext[contextDTOs.size()];
- contextDTOs.toArray(applicationClusterContextDTOs);
- try {
- stub.createApplicationClusters(appId, applicationClusterContextDTOs);
- } catch (RemoteException e) {
- String msg = e.getMessage();
- log.error(msg, e);
- } catch (CloudControllerServiceApplicationClusterRegistrationExceptionException e) {
- String msg = e.getMessage();
- log.error(msg, e);
- }
- }
-
- private Volume[] convertVolumesToStubVolumes(VolumeContext[] volumeContexts) {
-
- ArrayList<Volume> volumes = new ArrayList<Volume>();
- for (VolumeContext volumeContext : volumeContexts) {
- Volume volume = new Volume();
- volume.setRemoveOntermination(volumeContext.isRemoveOntermination());
- volume.setMappingPath(volumeContext.getMappingPath());
- volume.setId(volumeContext.getId());
- volume.setDevice(volumeContext.getDevice());
- volume.setIaasType(volumeContext.getIaasType());
- volume.setSnapshotId(volumeContext.getSnapshotId());
- volume.setVolumeId(volumeContext.getVolumeId());
- volume.setSize(volumeContext.getSize());
- volumes.add(volume);
- }
- return volumes.toArray(new Volume[volumes.size()]);
- }
-
- public void terminateInstance(String memberId) throws Exception {
- if (log.isInfoEnabled()) {
- log.info(String.format("Terminating instance via cloud controller: [member] %s", memberId));
- }
- long startTime = System.currentTimeMillis();
- stub.terminateInstance(memberId);
- if (log.isDebugEnabled()) {
- long endTime = System.currentTimeMillis();
- log.debug(String.format("Service call terminateInstance() returned in %dms", (endTime - startTime)));
- }
- }
-
- public void terminateInstanceForcefully(String memberId) throws Exception {
- if (log.isDebugEnabled()) {
- log.debug(String.format("Terminating instance forcefully via cloud controller: [member] %s", memberId));
- }
- stub.terminateInstanceForcefully(memberId);
- }
-
- public void terminateAllInstances(String clusterId)
- throws RemoteException, CloudControllerServiceInvalidClusterExceptionException {
- if (log.isInfoEnabled()) {
- log.info(String.format("Terminating all instances of cluster via cloud controller: [cluster] %s",
- clusterId));
- }
- long startTime = System.currentTimeMillis();
- stub.terminateInstances(clusterId);
-
- if (log.isDebugEnabled()) {
- long endTime = System.currentTimeMillis();
- log.debug(String.format("Service call terminateInstances() returned in %dms", (endTime - startTime)));
- }
- }
+ private static final Log log = LogFactory.getLog(AutoscalerCloudControllerClient.class);
+
+ 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();
+ int port =
+ conf.getInt("autoscaler.cloudController.port", AutoscalerConstants.CLOUD_CONTROLLER_DEFAULT_PORT);
+ String hostname = conf.getString("autoscaler.cloudController.hostname", "localhost");
+ String epr = "https://" + hostname + ":" + port + "/" + AutoscalerConstants.CLOUD_CONTROLLER_SERVICE_SFX;
+ int cloudControllerClientTimeout = conf.getInt("autoscaler.cloudController.clientTimeout", 180000);
+
+ stub = new CloudControllerServiceStub(epr);
+ stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, cloudControllerClientTimeout);
+ stub._getServiceClient().getOptions()
+ .setProperty(HTTPConstants.CONNECTION_TIMEOUT, cloudControllerClientTimeout);
+ } catch (Exception e) {
+ log.error("Could not initialize cloud controller client", e);
+ }
+ }
+
+ public synchronized MemberContext startInstance(PartitionRef partition, String clusterId, String clusterInstanceId,
+ String networkPartitionId, boolean isPrimary, int minMemberCount,
+ String autoscalingReason, long scalingTime)
+ throws SpawningException {
+ try {
+ if (log.isInfoEnabled()) {
+ log.info(String.format("Trying to spawn an instance via cloud controller: " +
+ "[cluster] %s [partition] %s [network-partition-id] %s", clusterId,
+ partition.getId(), networkPartitionId));
+ }
+
+ XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
+ long expiryTime = conf.getLong(StratosConstants.OBSOLETED_MEMBER_EXPIRY_TIMEOUT, 86400000);
+ if (log.isDebugEnabled()) {
+ log.debug("Member obsolete expiry time is set to: " + expiryTime);
+ }
+
+ InstanceContext instanceContext = new InstanceContext();
+ instanceContext.setClusterId(clusterId);
+ instanceContext.setClusterInstanceId(clusterInstanceId);
+ instanceContext.setPartition(AutoscalerObjectConverter.convertPartitionToCCPartition(partition));
+ instanceContext.setInitTime(System.currentTimeMillis());
+ instanceContext.setObsoleteExpiryTime(expiryTime);
+ instanceContext.setNetworkPartitionId(networkPartitionId);
+
+ Properties memberContextProps = new Properties();
+ Property isPrimaryProp = new Property();
+ isPrimaryProp.setName("PRIMARY");
+ isPrimaryProp.setValue(String.valueOf(isPrimary));
+
+ Property minCountProp = new Property();
+ minCountProp.setName(StratosConstants.MIN_COUNT);
+ minCountProp.setValue(String.valueOf(minMemberCount));
+
+ Property autoscalingReasonProp = new Property();
+ autoscalingReasonProp.setName(StratosConstants.SCALING_REASON);
+ autoscalingReasonProp.setValue(autoscalingReason);
+
+ Property scalingTimeProp = new Property();
+ scalingTimeProp.setName(StratosConstants.SCALING_TIME);
+ scalingTimeProp.setValue(String.valueOf(scalingTime));
+
+ memberContextProps.addProperty(isPrimaryProp);
+ memberContextProps.addProperty(minCountProp);
+ memberContextProps.addProperty(autoscalingReasonProp);
+ memberContextProps.addProperty(scalingTimeProp);
+ instanceContext.setProperties(AutoscalerUtil.toStubProperties(memberContextProps));
+
+ long startTime = System.currentTimeMillis();
+ MemberContext memberContext = stub.startInstance(instanceContext);
+
+ if (log.isDebugEnabled()) {
+ long endTime = System.currentTimeMillis();
+ log.debug(String.format("Service call startInstance() returned in %dms", (endTime - startTime)));
+ }
+ return memberContext;
+ } catch (CloudControllerServiceCartridgeNotFoundExceptionException e) {
+ String message = e.getFaultMessage().getCartridgeNotFoundException().getMessage();
+ log.error(message, e);
+ throw new SpawningException(message, e);
+ } catch (RemoteException e) {
+ log.error(e.getMessage(), e);
+ throw new SpawningException(e.getMessage(), e);
+ } catch (CloudControllerServiceInvalidIaasProviderExceptionException e) {
+ String message = e.getFaultMessage().getInvalidIaasProviderException().getMessage();
+ log.error(message, e);
+ throw new SpawningException(message, e);
+ } catch (CloudControllerServiceCloudControllerExceptionException e) {
+ String message = e.getMessage();
+ log.error(message, e);
+ throw new SpawningException(message, e);
+ }
+ }
+
+ public synchronized void createApplicationClusters(String appId,
+ ApplicationClusterContext[] applicationClusterContexts) {
+ List<org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext> contextDTOs =
+ new ArrayList<org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext>();
+ if (applicationClusterContexts != null) {
+ for (ApplicationClusterContext applicationClusterContext : applicationClusterContexts) {
+ if (applicationClusterContext != null) {
+ org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext dto =
+ new org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext();
+ dto.setClusterId(applicationClusterContext.getClusterId());
+ dto.setAutoscalePolicyName(applicationClusterContext.getAutoscalePolicyName());
+ dto.setDeploymentPolicyName(applicationClusterContext.getDeploymentPolicyName());
+ dto.setCartridgeType(applicationClusterContext.getCartridgeType());
+ dto.setHostName(applicationClusterContext.getHostName());
+ dto.setTenantRange(applicationClusterContext.getTenantRange());
+ dto.setTextPayload(applicationClusterContext.getTextPayload());
+ dto.setProperties(AutoscalerUtil.toStubProperties(applicationClusterContext.getProperties()));
+ dto.setDependencyClusterIds(applicationClusterContext.getDependencyClusterIds());
+ if (applicationClusterContext.getPersistenceContext() != null) {
+ dto.setVolumeRequired(true);
+ dto.setVolumes(convertVolumesToStubVolumes(
+ applicationClusterContext.getPersistenceContext().getVolumes()));
+ }
+ contextDTOs.add(dto);
+ }
+ }
+ }
+
+ org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext[] applicationClusterContextDTOs =
+ new org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext[contextDTOs.size()];
+ contextDTOs.toArray(applicationClusterContextDTOs);
+ try {
+ stub.createApplicationClusters(appId, applicationClusterContextDTOs);
+ } catch (RemoteException e) {
+ String msg = e.getMessage();
+ log.error(msg, e);
+ } catch (CloudControllerServiceApplicationClusterRegistrationExceptionException e) {
+ String msg = e.getMessage();
+ log.error(msg, e);
+ }
+ }
+
+ private Volume[] convertVolumesToStubVolumes(VolumeContext[] volumeContexts) {
+
+ ArrayList<Volume> volumes = new ArrayList<Volume>();
+ for (VolumeContext volumeContext : volumeContexts) {
+ Volume volume = new Volume();
+ volume.setRemoveOntermination(volumeContext.isRemoveOntermination());
+ volume.setMappingPath(volumeContext.getMappingPath());
+ volume.setId(volumeContext.getId());
+ volume.setDevice(volumeContext.getDevice());
+ volume.setIaasType(volumeContext.getIaasType());
+ volume.setSnapshotId(volumeContext.getSnapshotId());
+ volume.setVolumeId(volumeContext.getVolumeId());
+ volume.setSize(volumeContext.getSize());
+ volumes.add(volume);
+ }
+ return volumes.toArray(new Volume[volumes.size()]);
+ }
+
+ public void terminateInstance(String memberId) throws Exception {
+ if (log.isInfoEnabled()) {
+ log.info(String.format("Terminating instance via cloud controller: [member] %s", memberId));
+ }
+ long startTime = System.currentTimeMillis();
+ stub.terminateInstance(memberId);
+ if (log.isDebugEnabled()) {
+ long endTime = System.currentTimeMillis();
+ log.debug(String.format("Service call terminateInstance() returned in %dms", (endTime - startTime)));
+ }
+ }
+
+ public void terminateInstanceForcefully(String memberId) throws Exception {
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Terminating instance forcefully via cloud controller: [member] %s", memberId));
+ }
+ stub.terminateInstanceForcefully(memberId);
+ }
+
+ public void terminateAllInstances(String clusterId)
+ throws RemoteException, CloudControllerServiceInvalidClusterExceptionException {
+ if (log.isInfoEnabled()) {
+ log.info(String.format("Terminating all instances of cluster via cloud controller: [cluster] %s",
+ clusterId));
+ }
+ long startTime = System.currentTimeMillis();
+ stub.terminateInstances(clusterId);
+
+ if (log.isDebugEnabled()) {
+ long endTime = System.currentTimeMillis();
+ log.debug(String.format("Service call terminateInstances() returned in %dms", (endTime - startTime)));
+ }
+ }
}
[13/18] stratos git commit: Removing DAS-Artifacts
Posted by im...@apache.org.
Removing DAS-Artifacts
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/a61331e0
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/a61331e0
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/a61331e0
Branch: refs/heads/master
Commit: a61331e0cb9c2a7f87e95a6bc4fec233109a3daf
Parents: d5d7f79
Author: Thanuja <th...@wso2.com>
Authored: Thu Jul 23 15:00:58 2015 +0530
Committer: Thanuja <th...@wso2.com>
Committed: Thu Jul 23 15:00:58 2015 +0530
----------------------------------------------------------------------
DAS-Artifacts/CCEventReceiver.xml | 9 -
DAS-Artifacts/SparkQuery.txt | 19 -
...g.apache.stratos.cloud.controller_1.0.0.json | 112 ---
.../org_apache_stratos_cloud_controller.xml | 1 -
.../autoscaler/rule/RuleTasksDelegator.java | 688 +++++++++----------
.../util/CloudControllerConstants.java | 478 ++++++-------
6 files changed, 583 insertions(+), 724 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/a61331e0/DAS-Artifacts/CCEventReceiver.xml
----------------------------------------------------------------------
diff --git a/DAS-Artifacts/CCEventReceiver.xml b/DAS-Artifacts/CCEventReceiver.xml
deleted file mode 100644
index 0ddd086..0000000
--- a/DAS-Artifacts/CCEventReceiver.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<eventReceiver name="CCEventReceiver" statistics="disable"
- trace="enable" xmlns="http://wso2.org/carbon/eventreceiver">
- <from eventAdapterType="wso2event">
- <property name="events.duplicated.in.cluster">false</property>
- </from>
- <mapping customMapping="disable" type="wso2event"/>
- <to streamName="org.apache.stratos.cloud.controller" version="1.0.0"/>
-</eventReceiver>
http://git-wip-us.apache.org/repos/asf/stratos/blob/a61331e0/DAS-Artifacts/SparkQuery.txt
----------------------------------------------------------------------
diff --git a/DAS-Artifacts/SparkQuery.txt b/DAS-Artifacts/SparkQuery.txt
deleted file mode 100644
index 39f7d47..0000000
--- a/DAS-Artifacts/SparkQuery.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-CREATE TEMPORARY TABLE memberstatus
-USING CarbonAnalytics
-OPTIONS (tableName "ORG_APACHE_STRATOS_CLOUD_CONTROLLER");
-
-CREATE TEMPORARY TABLE memberstatusnew
-USING CarbonAnalytics
-OPTIONS (tableName "CLUSTER_MEMBER_NEW",
- schema "startTime String, endTime String, clusterId STRING, activatedInstanceCount INT, terminatedInstanceCount INT, activeInstanceCount INT");
-
-
-;WITH InstanceCount as
-(select clusterId, count(case when status='Active' and timeStamp > current_time(null)-60000 and timeStamp <= current_time(null) then 1 else NULL end) as activatedInstanceCount, count(case when status='Terminated' and timeStamp > current_time(null)-60000 and timeStamp <= current_time(null) then 1 else NULL end) as terminatedInstanceCount, (sum(case when status='Active' then 1 else 0 end) - sum(case when status='Terminated' then 1 else 0 end))as activeInstanceCount from memberstatus group by clusterId)
-INSERT INTO table memberstatusnew select time(current_time(null)-60000),time(current_time(null)),clusterId, activatedInstanceCount, terminatedInstanceCount,activeInstanceCount from InstanceCount;
-
-CREATE TEMPORARY TABLE membersnew
-USING CarbonAnalytics
-OPTIONS (tableName "MEMBER_NEW",schema "clusterId STRING, clusterInstanceId STRING, partitionId STRING, networkId STRING, cartridgeType STRING, instanceType STRING, memberId STRING, scalingTime LONG,scalingReason STRING, timeStamp LONG");
-
-INSERT INTO TABLE membersnew select clusterId, clusterInstanceId,partitionId,networkId,cartridgeType,instanceType, memberId, time(scalingTime),scalingReason,time(timeStamp) FROM memberstatus where status='Created';
http://git-wip-us.apache.org/repos/asf/stratos/blob/a61331e0/DAS-Artifacts/org.apache.stratos.cloud.controller_1.0.0.json
----------------------------------------------------------------------
diff --git a/DAS-Artifacts/org.apache.stratos.cloud.controller_1.0.0.json b/DAS-Artifacts/org.apache.stratos.cloud.controller_1.0.0.json
deleted file mode 100644
index de1025f..0000000
--- a/DAS-Artifacts/org.apache.stratos.cloud.controller_1.0.0.json
+++ /dev/null
@@ -1,112 +0,0 @@
-{
- "name": "org.apache.stratos.cloud.controller",
- "version": "1.0.0",
- "nickName": "cloud.controller",
- "description": "Instances booted up by the Cloud Controller",
- "payloadData": [
- {
- "name": "timeStamp",
- "type": "LONG"
- },
- {
- "name": "memberId",
- "type": "STRING"
- },
- {
- "name": "cartridgeType",
- "type": "STRING"
- },
- {
- "name": "clusterId",
- "type": "STRING"
- },
- {
- "name": "clusterInstanceId",
- "type": "STRING"
- },
- {
- "name": "lbclusterId",
- "type": "STRING"
- },
- {
- "name": "partitionId",
- "type": "STRING"
- },
- {
- "name": "networkId",
- "type": "STRING"
- },
- {
- "name": "instanceType",
- "type": "STRING"
- },
- {
- "name": "scalingReason",
- "type": "STRING"
- },
- {
- "name": "scalingTime",
- "type": "LONG"
- },
- {
- "name": "isMultiTenant",
- "type": "STRING"
- },
- {
- "name": "iaas",
- "type": "STRING"
- },
- {
- "name": "status",
- "type": "STRING"
- },
- {
- "name": "hostName",
- "type": "STRING"
- },
- {
- "name": "hypervisor",
- "type": "STRING"
- },
- {
- "name": "ram",
- "type": "STRING"
- },
- {
- "name": "imageId",
- "type": "STRING"
- },
- {
- "name": "loginPort",
- "type": "INT"
- },
- {
- "name": "osName",
- "type": "STRING"
- },
- {
- "name": "osVersion",
- "type": "STRING"
- },
- {
- "name": "osArch",
- "type": "STRING"
- },
- {
- "name": "is64bitOS",
- "type": "STRING"
- },
- {
- "name": "privateIPAddresses",
- "type": "STRING"
- },
- {
- "name": "publicIPAddresses",
- "type": "STRING"
- },
- {
- "name": "allocateIPAddresses",
- "type": "STRING"
- }
- ]
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/a61331e0/DAS-Artifacts/org_apache_stratos_cloud_controller.xml
----------------------------------------------------------------------
diff --git a/DAS-Artifacts/org_apache_stratos_cloud_controller.xml b/DAS-Artifacts/org_apache_stratos_cloud_controller.xml
deleted file mode 100644
index ee99acd..0000000
--- a/DAS-Artifacts/org_apache_stratos_cloud_controller.xml
+++ /dev/null
@@ -1 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?><EventStoreConfiguration><TableSchema><ColumnDefinition><Name>timeStamp</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>LONG</Type></ColumnDefinition><ColumnDefinition><Name>memberId</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>cartridgeType</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>clusterId</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>clusterInstanceId</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScorePar
am>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>lbclusterId</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>partitionId</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>networkId</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>instanceType</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>scalingReason</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam
><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>scalingTime</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>LONG</Type></ColumnDefinition><ColumnDefinition><Name>isMultiTenant</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>iaas</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>status</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>hostName</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><Co
lumnDefinition><Name>hypervisor</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>ram</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>imageId</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>loginPort</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>INTEGER</Type></ColumnDefinition><ColumnDefinition><Name>osName</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>osVersion</Name><EnableIn
dexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>osArch</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>is64bitOS</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>privateIPAddresses</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>publicIPAddresses</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>allocateIPAddresses</Name><EnableIndexing>false<
/EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition></TableSchema><Source><StreamId>org.apache.stratos.cloud.controller:1.0.0</StreamId></Source><RecordStoreName>EVENT_STORE</RecordStoreName></EventStoreConfiguration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/a61331e0/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java
----------------------------------------------------------------------
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 3a69880..d569ed2 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,348 +43,348 @@ import org.apache.stratos.common.constants.StratosConstants;
*/
public class RuleTasksDelegator {
- private static boolean arspiIsSet = false;
-
- private static final Log log = LogFactory.getLog(RuleTasksDelegator.class);
-
- public double getPredictedValueForNextMinute(float average, float gradient, float secondDerivative,
- int timeInterval) {
- double predictedValue;
- // 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;
- }
-
- public int getNumberOfInstancesRequiredBasedOnRif(float rifPredictedValue, float rifThreshold) {
-
- if (rifThreshold != 0) {
-
- float requiredNumberOfInstances = rifPredictedValue / rifThreshold;
- return (int) Math.ceil(requiredNumberOfInstances);
- } else {
- log.error("Request in flight threshold is Zero");
- return 0;
- }
-
- }
-
- public int getNumberOfInstancesRequiredBasedOnMemoryConsumption(float threshold, double predictedValue, int min,
- int max) {
- double numberOfAdditionalInstancesRequired = 0;
- if (predictedValue != threshold) {
-
- float scalingRange = 100 - threshold;
- int instanceRange = max - min;
-
- if (instanceRange != 0) {
-
- float gradient = scalingRange / instanceRange;
- numberOfAdditionalInstancesRequired = (predictedValue - threshold) / gradient;
- }
-
- if (predictedValue < threshold) {
- //Since predicted-value is less, it can be scale-down
- return min - 1;
- }
- }
-
- return (int) Math.ceil(min + numberOfAdditionalInstancesRequired);
- }
-
- public int getNumberOfInstancesRequiredBasedOnLoadAverage(float threshold, double predictedValue, int min) {
-
- double numberOfInstances;
- if (threshold != 0) {
-
- numberOfInstances = (min * predictedValue) / threshold;
- return (int) Math.ceil(numberOfInstances);
- }
-
- return min;
- }
-
- public int getMaxNumberOfInstancesRequired(int numberOfInstancesRequiredBasedOnRif,
- int numberOfInstancesRequiredBasedOnMemoryConsumption, boolean mcReset,
- int numberOfInstancesReuquiredBasedOnLoadAverage, boolean laReset) {
- int numberOfInstances = 0;
-
- int rifBasedRequiredInstances = 0;
- int mcBasedRequiredInstances = 0;
- int laBasedRequiredInstances = 0;
- if (arspiIsSet) {
- rifBasedRequiredInstances = numberOfInstancesRequiredBasedOnRif;
- }
- if (mcReset) {
- mcBasedRequiredInstances = numberOfInstancesRequiredBasedOnMemoryConsumption;
- }
- if (laReset) {
- laBasedRequiredInstances = numberOfInstancesReuquiredBasedOnLoadAverage;
- }
- numberOfInstances = Math.max(Math.max(numberOfInstancesRequiredBasedOnMemoryConsumption,
- numberOfInstancesReuquiredBasedOnLoadAverage),
- numberOfInstancesRequiredBasedOnRif);
- return numberOfInstances;
- }
-
- public PartitionAlgorithm getPartitionAlgorithm(String partitionAlgorithm) {
-
- PartitionAlgorithm autoscaleAlgorithm = null;
- //FIXME to not parse for algo when partition is chosen by the parent
-
- if (partitionAlgorithm == null) {
- //Send one after another as default
- partitionAlgorithm = StratosConstants.PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID;
- }
- if (log.isDebugEnabled()) {
- log.debug(String.format("Retrieving partition algorithm [Partition algorithm]: %s", partitionAlgorithm));
- }
- if (StratosConstants.PARTITION_ROUND_ROBIN_ALGORITHM_ID.equals(partitionAlgorithm)) {
- autoscaleAlgorithm = new RoundRobin();
- } else if (StratosConstants.PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID.equals(partitionAlgorithm)) {
- autoscaleAlgorithm = new OneAfterAnother();
- } else {
- if (log.isErrorEnabled()) {
- log.error(String.format("Partition algorithm %s could not be identified !", partitionAlgorithm));
- }
- }
- return autoscaleAlgorithm;
- }
-
- public void delegateInstanceCleanup(String memberId) {
- try {
- // send the instance notification event.
- InstanceNotificationPublisher.getInstance().sendInstanceCleanupEventForMember(memberId);
- log.info("Instance clean up event sent for [member] " + memberId);
-
- } catch (Exception e) {
- log.error("Cannot terminate instance", e);
- }
- }
-
- /**
- * Invoked from drools to start an instance.
- *
- * @param clusterMonitorPartitionContext Cluster monitor partition context
- * @param clusterId Cluster id
- * @param clusterInstanceId Instance id
- * @param isPrimary Is a primary member
- */
- public void delegateSpawn(ClusterLevelPartitionContext clusterMonitorPartitionContext, String clusterId,
- String clusterInstanceId, boolean isPrimary, String autoscalingReason, long scalingTime) {
-
- try {
- String nwPartitionId = clusterMonitorPartitionContext.getNetworkPartitionId();
-
- // Calculate accumulation of minimum counts of all the partition of current network partition
- int minimumCountOfNetworkPartition;
- ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getClusterMonitor(clusterId);
- ClusterContext clusterContext = clusterMonitor.getClusterContext();
- ClusterLevelNetworkPartitionContext clusterLevelNetworkPartitionContext =
- clusterContext.getNetworkPartitionCtxt(nwPartitionId);
- ClusterInstanceContext clusterInstanceContext =
- (ClusterInstanceContext) clusterLevelNetworkPartitionContext.
- getInstanceContext(
- clusterInstanceId);
- minimumCountOfNetworkPartition = clusterInstanceContext.getMinInstanceCount();
-
- MemberContext memberContext = AutoscalerCloudControllerClient.getInstance().startInstance(
- clusterMonitorPartitionContext.getPartition(), clusterId, clusterInstanceId,
- clusterMonitorPartitionContext.getNetworkPartitionId(), isPrimary, minimumCountOfNetworkPartition,
- autoscalingReason, scalingTime);
- if (memberContext != null) {
- ClusterLevelPartitionContext partitionContext = clusterInstanceContext.
- getPartitionCtxt(
- clusterMonitorPartitionContext
- .getPartitionId());
- partitionContext.addPendingMember(memberContext);
- partitionContext.addMemberStatsContext(new MemberStatsContext(memberContext.getMemberId()));
- if (log.isDebugEnabled()) {
- log.debug(String.format("Pending member added, [member] %s [partition] %s",
- memberContext.getMemberId(), memberContext.getPartition().getId()));
- }
-
- } else {
- if (log.isErrorEnabled()) {
- log.error("Member context returned from cloud controller is null");
- }
- }
- } catch (Exception e) {
- String message = String.format("Could not start instance: [cluster-id] %s [instance-id] %s", clusterId,
- clusterInstanceId);
- log.error(message, e);
- throw new RuntimeException(message, e);
- }
- }
-
- public void delegateScalingDependencyNotification(String clusterId, String networkPartitionId, String instanceId,
- int requiredInstanceCount, int minimumInstanceCount) {
-
- if (log.isDebugEnabled()) {
- log.debug("Scaling dependent notification is going to the [parentInstance] " + instanceId);
- }
- //Notify parent for checking scaling dependencies
- ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getClusterMonitor(clusterId);
- float fMinimumInstanceCount = minimumInstanceCount;
- float factor = requiredInstanceCount / fMinimumInstanceCount;
- clusterMonitor.sendClusterScalingEvent(networkPartitionId, instanceId, factor);
- }
-
- public void delegateScalingOverMaxNotification(String clusterId, String networkPartitionId, String instanceId) {
- if (log.isDebugEnabled()) {
- log.debug("Scaling max out notification is going to the [parentInstance] " + instanceId);
- }
- //Notify parent for checking scaling dependencies
- ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getClusterMonitor(clusterId);
- clusterMonitor.sendScalingOverMaxEvent(networkPartitionId, instanceId);
- }
-
- public void delegateScalingDownBeyondMinNotification(String clusterId, String networkPartitionId,
- String instanceId) {
- if (log.isDebugEnabled()) {
- log.debug("Scaling down lower min notification is going to the [parentInstance] " + instanceId);
- }
- //Notify parent for checking scaling dependencies
- ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getClusterMonitor(clusterId);
- clusterMonitor.sendScalingDownBeyondMinEvent(networkPartitionId, instanceId);
- }
-
- public void delegateTerminate(ClusterLevelPartitionContext clusterMonitorPartitionContext, String memberId) {
-
- try {
- //Moving member to pending termination list
- if (clusterMonitorPartitionContext.activeMemberAvailable(memberId)) {
-
- log.info(String.format("[scale-down] Moving active member to termination pending list [member id] %s " +
- "[partition] %s [network partition] %s", memberId,
- clusterMonitorPartitionContext.getPartitionId(),
- clusterMonitorPartitionContext.getNetworkPartitionId()));
- clusterMonitorPartitionContext.moveActiveMemberToTerminationPendingMembers(memberId);
- clusterMonitorPartitionContext.removeMemberStatsContext(memberId);
- } else if (clusterMonitorPartitionContext.pendingMemberAvailable(memberId)) {
-
- log.info(String.format(
- "[scale-down] Moving pending member to termination pending list [member id] %s " +
- "[partition] %s [network partition] %s", memberId,
- clusterMonitorPartitionContext.getPartitionId(),
- clusterMonitorPartitionContext.getNetworkPartitionId()));
- clusterMonitorPartitionContext.movePendingMemberToObsoleteMembers(memberId);
- clusterMonitorPartitionContext.removeMemberStatsContext(memberId);
- }
- } catch (Exception e) {
- log.error("[scale-down] Cannot move member to termination pending list ", e);
- }
- }
-
- public void delegateTerminateDependency(ClusterLevelPartitionContext clusterMonitorPartitionContext,
- String memberId) {
- try {
- //calling SM to send the instance notification event.
- if (log.isDebugEnabled()) {
- log.debug("delegateTerminateDependency:memberId:" + memberId);
- }
-
- } catch (Exception e) {
- log.error("Cannot terminate instance", e);
- }
- }
-
- public void terminateObsoleteInstance(String memberId) {
- try {
- AutoscalerCloudControllerClient.getInstance().terminateInstance(memberId);
- } catch (Exception e) {
- log.error("Cannot terminate instance", e);
- }
- }
-
- //Grouping
- public void delegateTerminateAll(String clusterId) {
- try {
- if (log.isDebugEnabled()) {
- log.debug("delegateTerminateAll - begin");
- }
- AutoscalerCloudControllerClient.getInstance().terminateAllInstances(clusterId);
- if (log.isDebugEnabled()) {
- log.debug("delegateTerminateAll - done");
- }
- } catch (Exception e) {
- log.error("Cannot terminate instance", e);
- }
- }
-
- public int getPredictedReplicasForStat(int minReplicas, float statUpperLimit, float statPredictedValue) {
- if (statUpperLimit == 0) {
- return 0;
- }
- float predictedValue = ((minReplicas / statUpperLimit) * statPredictedValue);
- return (int) Math.ceil(predictedValue);
- }
-
- public double getLoadAveragePredictedValue(ClusterInstanceContext clusterInstanceContext) {
- double loadAveragePredicted = 0.0d;
- int totalMemberCount = 0;
- for (ClusterLevelPartitionContext partitionContext : clusterInstanceContext.getPartitionCtxts()) {
- for (MemberStatsContext memberStatsContext : partitionContext.getMemberStatsContexts().values()) {
-
- float memberAverageLoadAverage = memberStatsContext.getLoadAverage().getAverage();
- float memberGredientLoadAverage = memberStatsContext.getLoadAverage().getGradient();
- float memberSecondDerivativeLoadAverage = memberStatsContext.getLoadAverage().getSecondDerivative();
-
- double memberPredictedLoadAverage =
- getPredictedValueForNextMinute(memberAverageLoadAverage, memberGredientLoadAverage,
- memberSecondDerivativeLoadAverage, 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("Predicted load average : " + loadAveragePredicted / totalMemberCount);
- return loadAveragePredicted / totalMemberCount;
- } else {
- 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()) {
-
- float memberMemoryConsumptionAverage = memberStatsContext.getMemoryConsumption().getAverage();
- float memberMemoryConsumptionGredient = memberStatsContext.getMemoryConsumption().getGradient();
- float memberMemoryConsumptionSecondDerivative =
- memberStatsContext.getMemoryConsumption().getSecondDerivative();
-
- double memberPredictedMemoryConsumption =
- getPredictedValueForNextMinute(memberMemoryConsumptionAverage, memberMemoryConsumptionGredient,
- memberMemoryConsumptionSecondDerivative, 1);
-
- 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("Predicted memory consumption : " + memoryConsumptionPredicted / totalMemberCount);
- return memoryConsumptionPredicted / totalMemberCount;
- } else {
- return 0;
- }
- }
+ private static boolean arspiIsSet = false;
+
+ private static final Log log = LogFactory.getLog(RuleTasksDelegator.class);
+
+ public double getPredictedValueForNextMinute(float average, float gradient, float secondDerivative,
+ int timeInterval) {
+ double predictedValue;
+ // 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;
+ }
+
+ public int getNumberOfInstancesRequiredBasedOnRif(float rifPredictedValue, float rifThreshold) {
+
+ if (rifThreshold != 0) {
+
+ float requiredNumberOfInstances = rifPredictedValue / rifThreshold;
+ return (int) Math.ceil(requiredNumberOfInstances);
+ } else {
+ log.error("Request in flight threshold is Zero");
+ return 0;
+ }
+
+ }
+
+ public int getNumberOfInstancesRequiredBasedOnMemoryConsumption(float threshold, double predictedValue, int min,
+ int max) {
+ double numberOfAdditionalInstancesRequired = 0;
+ if (predictedValue != threshold) {
+
+ float scalingRange = 100 - threshold;
+ int instanceRange = max - min;
+
+ if (instanceRange != 0) {
+
+ float gradient = scalingRange / instanceRange;
+ numberOfAdditionalInstancesRequired = (predictedValue - threshold) / gradient;
+ }
+
+ if (predictedValue < threshold) {
+ //Since predicted-value is less, it can be scale-down
+ return min - 1;
+ }
+ }
+
+ return (int) Math.ceil(min + numberOfAdditionalInstancesRequired);
+ }
+
+ public int getNumberOfInstancesRequiredBasedOnLoadAverage(float threshold, double predictedValue, int min) {
+
+ double numberOfInstances;
+ if (threshold != 0) {
+
+ numberOfInstances = (min * predictedValue) / threshold;
+ return (int) Math.ceil(numberOfInstances);
+ }
+
+ return min;
+ }
+
+ public int getMaxNumberOfInstancesRequired(int numberOfInstancesRequiredBasedOnRif,
+ int numberOfInstancesRequiredBasedOnMemoryConsumption, boolean mcReset,
+ int numberOfInstancesReuquiredBasedOnLoadAverage, boolean laReset) {
+ int numberOfInstances = 0;
+
+ int rifBasedRequiredInstances = 0;
+ int mcBasedRequiredInstances = 0;
+ int laBasedRequiredInstances = 0;
+ if (arspiIsSet) {
+ rifBasedRequiredInstances = numberOfInstancesRequiredBasedOnRif;
+ }
+ if (mcReset) {
+ mcBasedRequiredInstances = numberOfInstancesRequiredBasedOnMemoryConsumption;
+ }
+ if (laReset) {
+ laBasedRequiredInstances = numberOfInstancesReuquiredBasedOnLoadAverage;
+ }
+ numberOfInstances = Math.max(Math.max(numberOfInstancesRequiredBasedOnMemoryConsumption,
+ numberOfInstancesReuquiredBasedOnLoadAverage),
+ numberOfInstancesRequiredBasedOnRif);
+ return numberOfInstances;
+ }
+
+ public PartitionAlgorithm getPartitionAlgorithm(String partitionAlgorithm) {
+
+ PartitionAlgorithm autoscaleAlgorithm = null;
+ //FIXME to not parse for algo when partition is chosen by the parent
+
+ if (partitionAlgorithm == null) {
+ //Send one after another as default
+ partitionAlgorithm = StratosConstants.PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Retrieving partition algorithm [Partition algorithm]: %s", partitionAlgorithm));
+ }
+ if (StratosConstants.PARTITION_ROUND_ROBIN_ALGORITHM_ID.equals(partitionAlgorithm)) {
+ autoscaleAlgorithm = new RoundRobin();
+ } else if (StratosConstants.PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID.equals(partitionAlgorithm)) {
+ autoscaleAlgorithm = new OneAfterAnother();
+ } else {
+ if (log.isErrorEnabled()) {
+ log.error(String.format("Partition algorithm %s could not be identified !", partitionAlgorithm));
+ }
+ }
+ return autoscaleAlgorithm;
+ }
+
+ public void delegateInstanceCleanup(String memberId) {
+ try {
+ // send the instance notification event.
+ InstanceNotificationPublisher.getInstance().sendInstanceCleanupEventForMember(memberId);
+ log.info("Instance clean up event sent for [member] " + memberId);
+
+ } catch (Exception e) {
+ log.error("Cannot terminate instance", e);
+ }
+ }
+
+ /**
+ * Invoked from drools to start an instance.
+ *
+ * @param clusterMonitorPartitionContext Cluster monitor partition context
+ * @param clusterId Cluster id
+ * @param clusterInstanceId Instance id
+ * @param isPrimary Is a primary member
+ */
+ public void delegateSpawn(ClusterLevelPartitionContext clusterMonitorPartitionContext, String clusterId,
+ String clusterInstanceId, boolean isPrimary, String autoscalingReason, long scalingTime) {
+
+ try {
+ String nwPartitionId = clusterMonitorPartitionContext.getNetworkPartitionId();
+
+ // Calculate accumulation of minimum counts of all the partition of current network partition
+ int minimumCountOfNetworkPartition;
+ ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getClusterMonitor(clusterId);
+ ClusterContext clusterContext = clusterMonitor.getClusterContext();
+ ClusterLevelNetworkPartitionContext clusterLevelNetworkPartitionContext =
+ clusterContext.getNetworkPartitionCtxt(nwPartitionId);
+ ClusterInstanceContext clusterInstanceContext =
+ (ClusterInstanceContext) clusterLevelNetworkPartitionContext.
+ getInstanceContext(
+ clusterInstanceId);
+ minimumCountOfNetworkPartition = clusterInstanceContext.getMinInstanceCount();
+
+ MemberContext memberContext = AutoscalerCloudControllerClient.getInstance().startInstance(
+ clusterMonitorPartitionContext.getPartition(), clusterId, clusterInstanceId,
+ clusterMonitorPartitionContext.getNetworkPartitionId(), isPrimary, minimumCountOfNetworkPartition,
+ autoscalingReason, scalingTime);
+ if (memberContext != null) {
+ ClusterLevelPartitionContext partitionContext = clusterInstanceContext.
+ getPartitionCtxt(
+ clusterMonitorPartitionContext
+ .getPartitionId());
+ partitionContext.addPendingMember(memberContext);
+ partitionContext.addMemberStatsContext(new MemberStatsContext(memberContext.getMemberId()));
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Pending member added, [member] %s [partition] %s",
+ memberContext.getMemberId(), memberContext.getPartition().getId()));
+ }
+
+ } else {
+ if (log.isErrorEnabled()) {
+ log.error("Member context returned from cloud controller is null");
+ }
+ }
+ } catch (Exception e) {
+ String message = String.format("Could not start instance: [cluster-id] %s [instance-id] %s", clusterId,
+ clusterInstanceId);
+ log.error(message, e);
+ throw new RuntimeException(message, e);
+ }
+ }
+
+ public void delegateScalingDependencyNotification(String clusterId, String networkPartitionId, String instanceId,
+ int requiredInstanceCount, int minimumInstanceCount) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Scaling dependent notification is going to the [parentInstance] " + instanceId);
+ }
+ //Notify parent for checking scaling dependencies
+ ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getClusterMonitor(clusterId);
+ float fMinimumInstanceCount = minimumInstanceCount;
+ float factor = requiredInstanceCount / fMinimumInstanceCount;
+ clusterMonitor.sendClusterScalingEvent(networkPartitionId, instanceId, factor);
+ }
+
+ public void delegateScalingOverMaxNotification(String clusterId, String networkPartitionId, String instanceId) {
+ if (log.isDebugEnabled()) {
+ log.debug("Scaling max out notification is going to the [parentInstance] " + instanceId);
+ }
+ //Notify parent for checking scaling dependencies
+ ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getClusterMonitor(clusterId);
+ clusterMonitor.sendScalingOverMaxEvent(networkPartitionId, instanceId);
+ }
+
+ public void delegateScalingDownBeyondMinNotification(String clusterId, String networkPartitionId,
+ String instanceId) {
+ if (log.isDebugEnabled()) {
+ log.debug("Scaling down lower min notification is going to the [parentInstance] " + instanceId);
+ }
+ //Notify parent for checking scaling dependencies
+ ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getClusterMonitor(clusterId);
+ clusterMonitor.sendScalingDownBeyondMinEvent(networkPartitionId, instanceId);
+ }
+
+ public void delegateTerminate(ClusterLevelPartitionContext clusterMonitorPartitionContext, String memberId) {
+
+ try {
+ //Moving member to pending termination list
+ if (clusterMonitorPartitionContext.activeMemberAvailable(memberId)) {
+
+ log.info(String.format("[scale-down] Moving active member to termination pending list [member id] %s " +
+ "[partition] %s [network partition] %s", memberId,
+ clusterMonitorPartitionContext.getPartitionId(),
+ clusterMonitorPartitionContext.getNetworkPartitionId()));
+ clusterMonitorPartitionContext.moveActiveMemberToTerminationPendingMembers(memberId);
+ clusterMonitorPartitionContext.removeMemberStatsContext(memberId);
+ } else if (clusterMonitorPartitionContext.pendingMemberAvailable(memberId)) {
+
+ log.info(String.format(
+ "[scale-down] Moving pending member to termination pending list [member id] %s " +
+ "[partition] %s [network partition] %s", memberId,
+ clusterMonitorPartitionContext.getPartitionId(),
+ clusterMonitorPartitionContext.getNetworkPartitionId()));
+ clusterMonitorPartitionContext.movePendingMemberToObsoleteMembers(memberId);
+ clusterMonitorPartitionContext.removeMemberStatsContext(memberId);
+ }
+ } catch (Exception e) {
+ log.error("[scale-down] Cannot move member to termination pending list ", e);
+ }
+ }
+
+ public void delegateTerminateDependency(ClusterLevelPartitionContext clusterMonitorPartitionContext,
+ String memberId) {
+ try {
+ //calling SM to send the instance notification event.
+ if (log.isDebugEnabled()) {
+ log.debug("delegateTerminateDependency:memberId:" + memberId);
+ }
+
+ } catch (Exception e) {
+ log.error("Cannot terminate instance", e);
+ }
+ }
+
+ public void terminateObsoleteInstance(String memberId) {
+ try {
+ AutoscalerCloudControllerClient.getInstance().terminateInstance(memberId);
+ } catch (Exception e) {
+ log.error("Cannot terminate instance", e);
+ }
+ }
+
+ //Grouping
+ public void delegateTerminateAll(String clusterId) {
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("delegateTerminateAll - begin");
+ }
+ AutoscalerCloudControllerClient.getInstance().terminateAllInstances(clusterId);
+ if (log.isDebugEnabled()) {
+ log.debug("delegateTerminateAll - done");
+ }
+ } catch (Exception e) {
+ log.error("Cannot terminate instance", e);
+ }
+ }
+
+ public int getPredictedReplicasForStat(int minReplicas, float statUpperLimit, float statPredictedValue) {
+ if (statUpperLimit == 0) {
+ return 0;
+ }
+ float predictedValue = ((minReplicas / statUpperLimit) * statPredictedValue);
+ return (int) Math.ceil(predictedValue);
+ }
+
+ public double getLoadAveragePredictedValue(ClusterInstanceContext clusterInstanceContext) {
+ double loadAveragePredicted = 0.0d;
+ int totalMemberCount = 0;
+ for (ClusterLevelPartitionContext partitionContext : clusterInstanceContext.getPartitionCtxts()) {
+ for (MemberStatsContext memberStatsContext : partitionContext.getMemberStatsContexts().values()) {
+
+ float memberAverageLoadAverage = memberStatsContext.getLoadAverage().getAverage();
+ float memberGredientLoadAverage = memberStatsContext.getLoadAverage().getGradient();
+ float memberSecondDerivativeLoadAverage = memberStatsContext.getLoadAverage().getSecondDerivative();
+
+ double memberPredictedLoadAverage =
+ getPredictedValueForNextMinute(memberAverageLoadAverage, memberGredientLoadAverage,
+ memberSecondDerivativeLoadAverage, 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("Predicted load average : " + loadAveragePredicted / totalMemberCount);
+ return loadAveragePredicted / totalMemberCount;
+ } else {
+ 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()) {
+
+ float memberMemoryConsumptionAverage = memberStatsContext.getMemoryConsumption().getAverage();
+ float memberMemoryConsumptionGredient = memberStatsContext.getMemoryConsumption().getGradient();
+ float memberMemoryConsumptionSecondDerivative =
+ memberStatsContext.getMemoryConsumption().getSecondDerivative();
+
+ double memberPredictedMemoryConsumption =
+ getPredictedValueForNextMinute(memberMemoryConsumptionAverage, memberMemoryConsumptionGredient,
+ memberMemoryConsumptionSecondDerivative, 1);
+
+ 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("Predicted memory consumption : " + memoryConsumptionPredicted / totalMemberCount);
+ return memoryConsumptionPredicted / totalMemberCount;
+ } else {
+ return 0;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/a61331e0/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
index e2d953b..41dd8f0 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
@@ -24,261 +24,261 @@ import java.io.File;
public final class CloudControllerConstants {
- /**
- * cloud-controller XML file's elements
- */
- public static final String CLOUD_CONTROLLER_ELEMENT = "cloudController";
- public static final String SERIALIZATION_DIR_ELEMENT = "serializationDir";
- public static final String IAAS_PROVIDERS_ELEMENT = "iaasProviders";
- public static final String IAAS_PROVIDER_ELEMENT = "iaasProvider";
- public static final String PARTITION_ELEMENT = "partition";
- public static final String PARTITIONS_ELEMENT = "partitions";
- public static final String REGION_ELEMENT = "region";
- public static final String ZONE_ELEMENT = "zone";
- public static final String DEPLOYMENT_ELEMENT = "deployment";
- public static final String PORT_MAPPING_ELEMENT = "portMapping";
- public static final String APP_TYPES_ELEMENT = "appTypes";
- public static final String TYPE_ATTR = "type";
- public static final String HOST_ATTR = "host";
- public static final String BASE_DIR_ATTR = "baseDir";
- public static final String PROVIDER_ATTR = "provider";
- public static final String VERSION_ATTR = "version";
- public static final String MULTI_TENANT_ATTR = "multiTenant";
- public static final String PORT_ATTR = "port";
- public static final String PROXY_PORT_ATTR = "proxyPort";
- public static final String NAME_ATTR = "name";
- public static final String APP_SPECIFIC_MAPPING_ATTR = "appSpecificMapping";
+ /**
+ * cloud-controller XML file's elements
+ */
+ public static final String CLOUD_CONTROLLER_ELEMENT = "cloudController";
+ public static final String SERIALIZATION_DIR_ELEMENT = "serializationDir";
+ public static final String IAAS_PROVIDERS_ELEMENT = "iaasProviders";
+ public static final String IAAS_PROVIDER_ELEMENT = "iaasProvider";
+ public static final String PARTITION_ELEMENT = "partition";
+ public static final String PARTITIONS_ELEMENT = "partitions";
+ public static final String REGION_ELEMENT = "region";
+ public static final String ZONE_ELEMENT = "zone";
+ public static final String DEPLOYMENT_ELEMENT = "deployment";
+ public static final String PORT_MAPPING_ELEMENT = "portMapping";
+ public static final String APP_TYPES_ELEMENT = "appTypes";
+ public static final String TYPE_ATTR = "type";
+ public static final String HOST_ATTR = "host";
+ public static final String BASE_DIR_ATTR = "baseDir";
+ public static final String PROVIDER_ATTR = "provider";
+ public static final String VERSION_ATTR = "version";
+ public static final String MULTI_TENANT_ATTR = "multiTenant";
+ public static final String PORT_ATTR = "port";
+ public static final String PROXY_PORT_ATTR = "proxyPort";
+ public static final String NAME_ATTR = "name";
+ public static final String APP_SPECIFIC_MAPPING_ATTR = "appSpecificMapping";
- public static final String CARTRIDGES_ELEMENT = "cartridges";
- public static final String CARTRIDGE_ELEMENT = "cartridge";
+ public static final String CARTRIDGES_ELEMENT = "cartridges";
+ public static final String CARTRIDGE_ELEMENT = "cartridge";
- public static final String DISPLAY_NAME_ELEMENT = "displayName";
- public static final String DESCRIPTION_ELEMENT = "description";
- public static final String PROPERTY_ELEMENT = "property";
- public static final String PROPERTY_NAME_ATTR = "name";
- public static final String PROPERTY_VALUE_ATTR = "value";
- public static final String IMAGE_ID_ELEMENT = "imageId";
- public static final String SCALE_DOWN_ORDER_ELEMENT = "scaleDownOrder";
- public static final String SCALE_UP_ORDER_ELEMENT = "scaleUpOrder";
- public static final String CLASS_NAME_ELEMENT = "className";
- public static final String PROVIDER_ELEMENT = "provider";
- public static final String IDENTITY_ELEMENT = "identity";
- public static final String TYPE_ELEMENT = "type";
- public static final String SCOPE_ELEMENT = "scope";
- public static final String ID_ELEMENT = "id";
- public static final String CREDENTIAL_ELEMENT = "credential";
- public static final String DEFAULT_SERVICE_ELEMENT = "default";
- public static final String SERVICE_ELEMENT = "service";
- public static final String SERVICES_ELEMENT = "services";
- public static final String DIRECTORY_ELEMENT = "dir";
- public static final String HTTP_ELEMENT = "http";
- public static final String HTTPS_ELEMENT = "https";
- public static final String APP_TYPE_ELEMENT = "appType";
- public static final String SERVICE_DOMAIN_ATTR = "domain";
- public static final String SERVICE_SUB_DOMAIN_ATTR = "subDomain";
- public static final String SERVICE_TENANT_RANGE_ATTR = "tenantRange";
- public static final String POLICY_NAME = "policyName";
- public static final String PAYLOAD_ELEMENT = "payload";
- public static final String DATA_PUBLISHER_ELEMENT = "dataPublisher";
- public static final String TOPOLOGY_SYNC_ELEMENT = "topologySync";
- public static final String ENABLE_ATTR = "enable";
- public static final String BAM_SERVER_ELEMENT = "bamServer";
- public static final String CRON_ELEMENT = "cron";
- public static final String BAM_SERVER_ADMIN_USERNAME_ELEMENT = "adminUserName";
- public static final String BAM_SERVER_ADMIN_PASSWORD_ELEMENT = "adminPassword";
- public static final String CASSANDRA_INFO_ELEMENT = "cassandraInfo";
- public static final String HOST_ELEMENT = "host";
- public static final String CONNECTION_URL_ELEMENT = "connectionUrl";
- public static final String HOST_PORT_ELEMENT = "port";
- public static final String USER_NAME_ELEMENT = "userName";
- public static final String PASSWORD_ELEMENT = "password";
- public static final String CLOUD_CONTROLLER_EVENT_STREAM = "org.apache.stratos.cloud.controller";
- public static final String CLOUD_CONTROLLER_COL_FAMILY = CLOUD_CONTROLLER_EVENT_STREAM.replaceAll("[/.]", "_");
+ public static final String DISPLAY_NAME_ELEMENT = "displayName";
+ public static final String DESCRIPTION_ELEMENT = "description";
+ public static final String PROPERTY_ELEMENT = "property";
+ public static final String PROPERTY_NAME_ATTR = "name";
+ public static final String PROPERTY_VALUE_ATTR = "value";
+ public static final String IMAGE_ID_ELEMENT = "imageId";
+ public static final String SCALE_DOWN_ORDER_ELEMENT = "scaleDownOrder";
+ public static final String SCALE_UP_ORDER_ELEMENT = "scaleUpOrder";
+ public static final String CLASS_NAME_ELEMENT = "className";
+ public static final String PROVIDER_ELEMENT = "provider";
+ public static final String IDENTITY_ELEMENT = "identity";
+ public static final String TYPE_ELEMENT = "type";
+ public static final String SCOPE_ELEMENT = "scope";
+ public static final String ID_ELEMENT = "id";
+ public static final String CREDENTIAL_ELEMENT = "credential";
+ public static final String DEFAULT_SERVICE_ELEMENT = "default";
+ public static final String SERVICE_ELEMENT = "service";
+ public static final String SERVICES_ELEMENT = "services";
+ public static final String DIRECTORY_ELEMENT = "dir";
+ public static final String HTTP_ELEMENT = "http";
+ public static final String HTTPS_ELEMENT = "https";
+ public static final String APP_TYPE_ELEMENT = "appType";
+ public static final String SERVICE_DOMAIN_ATTR = "domain";
+ public static final String SERVICE_SUB_DOMAIN_ATTR = "subDomain";
+ public static final String SERVICE_TENANT_RANGE_ATTR = "tenantRange";
+ public static final String POLICY_NAME = "policyName";
+ public static final String PAYLOAD_ELEMENT = "payload";
+ public static final String DATA_PUBLISHER_ELEMENT = "dataPublisher";
+ public static final String TOPOLOGY_SYNC_ELEMENT = "topologySync";
+ public static final String ENABLE_ATTR = "enable";
+ public static final String BAM_SERVER_ELEMENT = "bamServer";
+ public static final String CRON_ELEMENT = "cron";
+ public static final String BAM_SERVER_ADMIN_USERNAME_ELEMENT = "adminUserName";
+ public static final String BAM_SERVER_ADMIN_PASSWORD_ELEMENT = "adminPassword";
+ public static final String CASSANDRA_INFO_ELEMENT = "cassandraInfo";
+ public static final String HOST_ELEMENT = "host";
+ public static final String CONNECTION_URL_ELEMENT = "connectionUrl";
+ public static final String HOST_PORT_ELEMENT = "port";
+ public static final String USER_NAME_ELEMENT = "userName";
+ public static final String PASSWORD_ELEMENT = "password";
+ public static final String CLOUD_CONTROLLER_EVENT_STREAM = "org.apache.stratos.cloud.controller";
+ public static final String CLOUD_CONTROLLER_COL_FAMILY = CLOUD_CONTROLLER_EVENT_STREAM.replaceAll("[/.]", "_");
- /**
- * column names
- */
- public static final String PAYLOAD_PREFIX = "payload_";
- public static final String MEMBER_ID_COL = "memberId";
- public static final String CARTRIDGE_TYPE_COL = "cartridgeType";
- public static final String CLUSTER_ID_COL = "clusterId";
- public static final String CLUSTER_INSTANCE_ID_COL = "clusterInstanceId";
- public static final String PARTITION_ID_COL = "partitionId";
- public static final String NETWORK_ID_COL = "networkId";
- public static final String ALIAS_COL = "alias";
- public static final String TENANT_RANGE_COL = "tenantRange";
- public static final String IS_MULTI_TENANT_COL = "isMultiTenant";
- public static final String IAAS_COL = "iaas";
- public static final String STATUS_COL = "status";
- public static final String HOST_NAME_COL = "hostName";
- public static final String HYPERVISOR_COL = "hypervisor";
- public static final String RAM_COL = "ram";
- public static final String IMAGE_ID_COL = "imageId";
- public static final String LOGIN_PORT_COL = "loginPort";
- public static final String OS_NAME_COL = "osName";
- public static final String OS_VERSION_COL = "osVersion";
- public static final String OS_ARCH_COL = "osArch";
- public static final String OS_BIT_COL = "is64bitOS";
- public static final String PRIV_IP_COL = "privateIPAddresses";
- public static final String PUB_IP_COL = "publicIPAddresses";
- public static final String ALLOCATE_IP_COL = "allocateIPAddresses";
- public static final String TIME_STAMP = "timeStamp";
- public static final String SCALING_REASON = "scalingReason";
- public static final String SCALING_TIME = "scalingTime";
+ /**
+ * column names
+ */
+ public static final String PAYLOAD_PREFIX = "payload_";
+ public static final String MEMBER_ID_COL = "memberId";
+ public static final String CARTRIDGE_TYPE_COL = "cartridgeType";
+ public static final String CLUSTER_ID_COL = "clusterId";
+ public static final String CLUSTER_INSTANCE_ID_COL = "clusterInstanceId";
+ public static final String PARTITION_ID_COL = "partitionId";
+ public static final String NETWORK_ID_COL = "networkId";
+ public static final String ALIAS_COL = "alias";
+ public static final String TENANT_RANGE_COL = "tenantRange";
+ public static final String IS_MULTI_TENANT_COL = "isMultiTenant";
+ public static final String IAAS_COL = "iaas";
+ public static final String STATUS_COL = "status";
+ public static final String HOST_NAME_COL = "hostName";
+ public static final String HYPERVISOR_COL = "hypervisor";
+ public static final String RAM_COL = "ram";
+ public static final String IMAGE_ID_COL = "imageId";
+ public static final String LOGIN_PORT_COL = "loginPort";
+ public static final String OS_NAME_COL = "osName";
+ public static final String OS_VERSION_COL = "osVersion";
+ public static final String OS_ARCH_COL = "osArch";
+ public static final String OS_BIT_COL = "is64bitOS";
+ public static final String PRIV_IP_COL = "privateIPAddresses";
+ public static final String PUB_IP_COL = "publicIPAddresses";
+ public static final String ALLOCATE_IP_COL = "allocateIPAddresses";
+ public static final String TIME_STAMP = "timeStamp";
+ public static final String SCALING_REASON = "scalingReason";
+ public static final String SCALING_TIME = "scalingTime";
- /**
- * Properties
- */
- public static final String REGION_PROPERTY = "region";
- public static final String TOPICS_PROPERTY = "topics";
- public static final String PUBLIC_IP_PROPERTY = "public_ip";
- public static final String TENANT_ID_PROPERTY = "tenant_id";
- public static final String ALIAS_PROPERTY = "alias";
- public static final String AUTO_ASSIGN_IP_PROPERTY = "autoAssignIp";
- public static final String JCLOUDS_ENDPOINT = "jclouds.endpoint";
- public static final String CRON_PROPERTY = "cron";
- public static final String AMQP_CONNECTION_URL_PROPERTY = "amqpConnectionUrl";
- public static final String AMQP_INITIAL_CONTEXT_FACTORY_PROPERTY = "amqpInitialContextFactory";
- public static final String AMQP_TOPIC_CONNECTION_FACTORY_PROPERTY = "amqpTopicConnectionFactory";
- public static final String INSTANCE_TOPIC = "instance/*";
- // pre define a floating ip
- public static final String FLOATING_IP_PROPERTY = "floatingIp";
- public static final String DEFAULT_FLOATING_IP_POOL = "defaultFloatingIpPool";
- public static final String OPENSTACK_NETWORKING_PROVIDER = "openstack.networking.provider";
- public static final String OPENSTACK_NEUTRON_NETWORKING = "neutron";
+ /**
+ * Properties
+ */
+ public static final String REGION_PROPERTY = "region";
+ public static final String TOPICS_PROPERTY = "topics";
+ public static final String PUBLIC_IP_PROPERTY = "public_ip";
+ public static final String TENANT_ID_PROPERTY = "tenant_id";
+ public static final String ALIAS_PROPERTY = "alias";
+ public static final String AUTO_ASSIGN_IP_PROPERTY = "autoAssignIp";
+ public static final String JCLOUDS_ENDPOINT = "jclouds.endpoint";
+ public static final String CRON_PROPERTY = "cron";
+ public static final String AMQP_CONNECTION_URL_PROPERTY = "amqpConnectionUrl";
+ public static final String AMQP_INITIAL_CONTEXT_FACTORY_PROPERTY = "amqpInitialContextFactory";
+ public static final String AMQP_TOPIC_CONNECTION_FACTORY_PROPERTY = "amqpTopicConnectionFactory";
+ public static final String INSTANCE_TOPIC = "instance/*";
+ // pre define a floating ip
+ public static final String FLOATING_IP_PROPERTY = "floatingIp";
+ public static final String DEFAULT_FLOATING_IP_POOL = "defaultFloatingIpPool";
+ public static final String OPENSTACK_NETWORKING_PROVIDER = "openstack.networking.provider";
+ public static final String OPENSTACK_NEUTRON_NETWORKING = "neutron";
- /**
- * XPath expressions
- */
- public static final String IAAS_PROVIDER_XPATH =
- "/" + CLOUD_CONTROLLER_ELEMENT + "/" + IAAS_PROVIDERS_ELEMENT + "/" + IAAS_PROVIDER_ELEMENT;
- public static final String PARTITION_XPATH =
- "/" + CLOUD_CONTROLLER_ELEMENT + "/" + PARTITIONS_ELEMENT + "/" + PARTITION_ELEMENT;
- public static final String REGION_XPATH =
- "/" + CLOUD_CONTROLLER_ELEMENT + "/" + IAAS_PROVIDERS_ELEMENT + "/" + IAAS_PROVIDER_ELEMENT + "/" +
- REGION_ELEMENT;
- public static final String ZONE_XPATH =
- "/" + CLOUD_CONTROLLER_ELEMENT + "/" + IAAS_PROVIDERS_ELEMENT + "/" + IAAS_PROVIDER_ELEMENT + "/" +
- REGION_ELEMENT + "/" + ZONE_ELEMENT;
- public static final String HOST_XPATH =
- "/" + CLOUD_CONTROLLER_ELEMENT + "/" + IAAS_PROVIDERS_ELEMENT + "/" + IAAS_PROVIDER_ELEMENT + "/" +
- REGION_ELEMENT + "/" + ZONE_ELEMENT + "/" + HOST_ELEMENT;
- public static final String PROPERTY_ELEMENT_XPATH = "/" + PROPERTY_ELEMENT;
- public static final String IMAGE_ID_ELEMENT_XPATH = "/" + IMAGE_ID_ELEMENT;
- public static final String SCALE_UP_ORDER_ELEMENT_XPATH = "/" + SCALE_UP_ORDER_ELEMENT;
- public static final String SCALE_DOWN_ORDER_ELEMENT_XPATH = "/" + SCALE_DOWN_ORDER_ELEMENT;
- public static final String PROVIDER_ELEMENT_XPATH = "/" + PROPERTY_ELEMENT;
- public static final String IDENTITY_ELEMENT_XPATH = "/" + IDENTITY_ELEMENT;
- public static final String CREDENTIAL_ELEMENT_XPATH = "/" + CREDENTIAL_ELEMENT;
- public static final String SERVICES_ELEMENT_XPATH = "/" + SERVICES_ELEMENT + "/" + SERVICE_ELEMENT;
- public static final String SERVICE_ELEMENT_XPATH = "/" + SERVICE_ELEMENT;
- public static final String CARTRIDGE_ELEMENT_XPATH = "/" + CARTRIDGE_ELEMENT;
- public static final String PAYLOAD_ELEMENT_XPATH = "/" + PAYLOAD_ELEMENT;
- public static final String HOST_ELEMENT_XPATH = "/" + HOST_ELEMENT;
- public static final String CARTRIDGES_ELEMENT_XPATH = "/" + CARTRIDGES_ELEMENT + "/" + CARTRIDGE_ELEMENT;
- public static final String IAAS_PROVIDER_ELEMENT_XPATH = "/" + IAAS_PROVIDER_ELEMENT;
- public static final String DEPLOYMENT_ELEMENT_XPATH = "/" + DEPLOYMENT_ELEMENT;
- public static final String PORT_MAPPING_ELEMENT_XPATH = "/" + PORT_MAPPING_ELEMENT;
- public static final String APP_TYPES_ELEMENT_XPATH = "/" + APP_TYPES_ELEMENT;
+ /**
+ * XPath expressions
+ */
+ public static final String IAAS_PROVIDER_XPATH =
+ "/" + CLOUD_CONTROLLER_ELEMENT + "/" + IAAS_PROVIDERS_ELEMENT + "/" + IAAS_PROVIDER_ELEMENT;
+ public static final String PARTITION_XPATH =
+ "/" + CLOUD_CONTROLLER_ELEMENT + "/" + PARTITIONS_ELEMENT + "/" + PARTITION_ELEMENT;
+ public static final String REGION_XPATH =
+ "/" + CLOUD_CONTROLLER_ELEMENT + "/" + IAAS_PROVIDERS_ELEMENT + "/" + IAAS_PROVIDER_ELEMENT + "/" +
+ REGION_ELEMENT;
+ public static final String ZONE_XPATH =
+ "/" + CLOUD_CONTROLLER_ELEMENT + "/" + IAAS_PROVIDERS_ELEMENT + "/" + IAAS_PROVIDER_ELEMENT + "/" +
+ REGION_ELEMENT + "/" + ZONE_ELEMENT;
+ public static final String HOST_XPATH =
+ "/" + CLOUD_CONTROLLER_ELEMENT + "/" + IAAS_PROVIDERS_ELEMENT + "/" + IAAS_PROVIDER_ELEMENT + "/" +
+ REGION_ELEMENT + "/" + ZONE_ELEMENT + "/" + HOST_ELEMENT;
+ public static final String PROPERTY_ELEMENT_XPATH = "/" + PROPERTY_ELEMENT;
+ public static final String IMAGE_ID_ELEMENT_XPATH = "/" + IMAGE_ID_ELEMENT;
+ public static final String SCALE_UP_ORDER_ELEMENT_XPATH = "/" + SCALE_UP_ORDER_ELEMENT;
+ public static final String SCALE_DOWN_ORDER_ELEMENT_XPATH = "/" + SCALE_DOWN_ORDER_ELEMENT;
+ public static final String PROVIDER_ELEMENT_XPATH = "/" + PROPERTY_ELEMENT;
+ public static final String IDENTITY_ELEMENT_XPATH = "/" + IDENTITY_ELEMENT;
+ public static final String CREDENTIAL_ELEMENT_XPATH = "/" + CREDENTIAL_ELEMENT;
+ public static final String SERVICES_ELEMENT_XPATH = "/" + SERVICES_ELEMENT + "/" + SERVICE_ELEMENT;
+ public static final String SERVICE_ELEMENT_XPATH = "/" + SERVICE_ELEMENT;
+ public static final String CARTRIDGE_ELEMENT_XPATH = "/" + CARTRIDGE_ELEMENT;
+ public static final String PAYLOAD_ELEMENT_XPATH = "/" + PAYLOAD_ELEMENT;
+ public static final String HOST_ELEMENT_XPATH = "/" + HOST_ELEMENT;
+ public static final String CARTRIDGES_ELEMENT_XPATH = "/" + CARTRIDGES_ELEMENT + "/" + CARTRIDGE_ELEMENT;
+ public static final String IAAS_PROVIDER_ELEMENT_XPATH = "/" + IAAS_PROVIDER_ELEMENT;
+ public static final String DEPLOYMENT_ELEMENT_XPATH = "/" + DEPLOYMENT_ELEMENT;
+ public static final String PORT_MAPPING_ELEMENT_XPATH = "/" + PORT_MAPPING_ELEMENT;
+ public static final String APP_TYPES_ELEMENT_XPATH = "/" + APP_TYPES_ELEMENT;
- public static final String DATA_PUBLISHER_XPATH = "/" + CLOUD_CONTROLLER_ELEMENT + "/" + DATA_PUBLISHER_ELEMENT;
- public static final String TOPOLOGY_SYNC_XPATH = "/" + CLOUD_CONTROLLER_ELEMENT + "/" + TOPOLOGY_SYNC_ELEMENT;
- public static final String DATA_PUBLISHER_CRON_XPATH = "/" + CLOUD_CONTROLLER_ELEMENT + "/" + CRON_ELEMENT;
- public static final String BAM_SERVER_ADMIN_USERNAME_XPATH =
- "/" + CLOUD_CONTROLLER_ELEMENT + "/" + BAM_SERVER_ADMIN_USERNAME_ELEMENT;
- public static final String BAM_SERVER_ADMIN_PASSWORD_XPATH =
- "/" + CLOUD_CONTROLLER_ELEMENT + "/" + BAM_SERVER_ADMIN_PASSWORD_ELEMENT;
+ public static final String DATA_PUBLISHER_XPATH = "/" + CLOUD_CONTROLLER_ELEMENT + "/" + DATA_PUBLISHER_ELEMENT;
+ public static final String TOPOLOGY_SYNC_XPATH = "/" + CLOUD_CONTROLLER_ELEMENT + "/" + TOPOLOGY_SYNC_ELEMENT;
+ public static final String DATA_PUBLISHER_CRON_XPATH = "/" + CLOUD_CONTROLLER_ELEMENT + "/" + CRON_ELEMENT;
+ public static final String BAM_SERVER_ADMIN_USERNAME_XPATH =
+ "/" + CLOUD_CONTROLLER_ELEMENT + "/" + BAM_SERVER_ADMIN_USERNAME_ELEMENT;
+ public static final String BAM_SERVER_ADMIN_PASSWORD_XPATH =
+ "/" + CLOUD_CONTROLLER_ELEMENT + "/" + BAM_SERVER_ADMIN_PASSWORD_ELEMENT;
- /**
- * Secret Manager related aliases.
- */
- public static final String ALIAS_ATTRIBUTE = "secretAlias";
- public static final String ALIAS_ATTRIBUTE_PREFIX = "svns";
- public static final String ALIAS_NAMESPACE = "http://org.wso2.securevault/configuration";
+ /**
+ * Secret Manager related aliases.
+ */
+ public static final String ALIAS_ATTRIBUTE = "secretAlias";
+ public static final String ALIAS_ATTRIBUTE_PREFIX = "svns";
+ public static final String ALIAS_NAMESPACE = "http://org.wso2.securevault/configuration";
- /**
- * Payload related constants
- */
- public static final String PAYLOAD_NAME = "payload";
- public static final String ENTRY_SEPARATOR = ",";
+ /**
+ * Payload related constants
+ */
+ public static final String PAYLOAD_NAME = "payload";
+ public static final String ENTRY_SEPARATOR = ",";
- /**
- * Publisher task related constants
- */
- public static final String DATA_PUB_TASK_TYPE = "CLOUD_CONTROLLER_DATA_PUBLISHER_TASK";
- // default is : data publisher will run in first second of every minute
- public static final String PUB_CRON_EXPRESSION = "1 * * * * ? *";
- public static final String DATA_PUB_TASK_NAME = "CartridgeInstanceDataPublisher";
- public static final String DEFAULT_BAM_SERVER_USER_NAME = "admin";
- public static final String DEFAULT_BAM_SERVER_PASSWORD = "admin";
- public static final String DEFAULT_CASSANDRA_URL = "localhost:9160";
- public static final String DEFAULT_CASSANDRA_USER = "admin";
- public static final String DEFAULT_CASSANDRA_PASSWORD = "admin";
- public static final String DEFAULT_CASSANDRA_CLUSTER_NAME = "Test Cluster";
- public static final String DEFAULT_CASSANDRA_KEY_SPACE = "EVENT_KS";
+ /**
+ * Publisher task related constants
+ */
+ public static final String DATA_PUB_TASK_TYPE = "CLOUD_CONTROLLER_DATA_PUBLISHER_TASK";
+ // default is : data publisher will run in first second of every minute
+ public static final String PUB_CRON_EXPRESSION = "1 * * * * ? *";
+ public static final String DATA_PUB_TASK_NAME = "CartridgeInstanceDataPublisher";
+ public static final String DEFAULT_BAM_SERVER_USER_NAME = "admin";
+ public static final String DEFAULT_BAM_SERVER_PASSWORD = "admin";
+ public static final String DEFAULT_CASSANDRA_URL = "localhost:9160";
+ public static final String DEFAULT_CASSANDRA_USER = "admin";
+ public static final String DEFAULT_CASSANDRA_PASSWORD = "admin";
+ public static final String DEFAULT_CASSANDRA_CLUSTER_NAME = "Test Cluster";
+ public static final String DEFAULT_CASSANDRA_KEY_SPACE = "EVENT_KS";
- /**
- * Directories
- */
- public static final String SERVICES_DIR =
- CarbonUtils.getCarbonRepository() + File.separator + "services" + File.separator;
+ /**
+ * Directories
+ */
+ public static final String SERVICES_DIR =
+ CarbonUtils.getCarbonRepository() + File.separator + "services" + File.separator;
- /**
- * Topology sync related constants
- */
- public static final String TOPOLOGY_FILE_PATH =
- CarbonUtils.getCarbonConfigDirPath() + File.separator + "service-topology.conf";
- public static final String TOPOLOGY_SYNC_CRON = "1 * * * * ? *";
- public static final String TOPOLOGY_SYNC_TASK_NAME = "TOPOLOGY_SYNC_TASK";
- public static final String TOPOLOGY_SYNC_TASK_TYPE = "TOPOLOGY_SYNC_TASK_TYPE";
- public static final String AMQP_CONNECTION_URL =
- "amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5672'";
- public static final String AMQP_INITIAL_CONTEXT_FACTORY = "org.wso2.andes.jndi.PropertiesFileInitialContextFactory";
- public static final String AMQP_TOPIC_CONNECTION_FACTORY = "qpidConnectionfactory";
+ /**
+ * Topology sync related constants
+ */
+ public static final String TOPOLOGY_FILE_PATH =
+ CarbonUtils.getCarbonConfigDirPath() + File.separator + "service-topology.conf";
+ public static final String TOPOLOGY_SYNC_CRON = "1 * * * * ? *";
+ public static final String TOPOLOGY_SYNC_TASK_NAME = "TOPOLOGY_SYNC_TASK";
+ public static final String TOPOLOGY_SYNC_TASK_TYPE = "TOPOLOGY_SYNC_TASK_TYPE";
+ public static final String AMQP_CONNECTION_URL =
+ "amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5672'";
+ public static final String AMQP_INITIAL_CONTEXT_FACTORY = "org.wso2.andes.jndi.PropertiesFileInitialContextFactory";
+ public static final String AMQP_TOPIC_CONNECTION_FACTORY = "qpidConnectionfactory";
- /**
- * Persistence
- */
- public static final String DATA_RESOURCE = "/cloud.controller/data";
- public static final String TOPOLOGY_RESOURCE = "/cloud.controller/topology";
- public static final String AVAILABILITY_ZONE = "availabilityZone";
- public static final String KEY_PAIR = "keyPair";
- public static final String HOST = "host";
- public static final String SECURITY_GROUP_IDS = "securityGroupIds";
- public static final String SECURITY_GROUPS = "securityGroups";
- public static final String SUBNET_ID = "subnetId";
- public static final String TAGS = "tags";
- public static final String TAGS_AS_KEY_VALUE_PAIRS_PREFIX = "tag:";
- public static final String AUTO_ASSIGN_IP = "autoAssignIp";
- public static final String BLOCK_UNTIL_RUNNING = "blockUntilRunning";
- public static final String INSTANCE_TYPE = "instanceType";
- public static final String ASSOCIATE_PUBLIC_IP_ADDRESS = "associatePublicIpAddress";
- public static final String LB_CLUSTER_ID_COL = "lbclusterId";
- public static final String NETWORK_INTERFACES = "networkInterfaces";
- public static final String NETWORK_FIXED_IP = "fixedIp";
- public static final String NETWORK_PORT = "portUuid";
- public static final String NETWORK_UUID = "networkUuid";
+ /**
+ * Persistence
+ */
+ public static final String DATA_RESOURCE = "/cloud.controller/data";
+ public static final String TOPOLOGY_RESOURCE = "/cloud.controller/topology";
+ public static final String AVAILABILITY_ZONE = "availabilityZone";
+ public static final String KEY_PAIR = "keyPair";
+ public static final String HOST = "host";
+ public static final String SECURITY_GROUP_IDS = "securityGroupIds";
+ public static final String SECURITY_GROUPS = "securityGroups";
+ public static final String SUBNET_ID = "subnetId";
+ public static final String TAGS = "tags";
+ public static final String TAGS_AS_KEY_VALUE_PAIRS_PREFIX = "tag:";
+ public static final String AUTO_ASSIGN_IP = "autoAssignIp";
+ public static final String BLOCK_UNTIL_RUNNING = "blockUntilRunning";
+ public static final String INSTANCE_TYPE = "instanceType";
+ public static final String ASSOCIATE_PUBLIC_IP_ADDRESS = "associatePublicIpAddress";
+ public static final String LB_CLUSTER_ID_COL = "lbclusterId";
+ public static final String NETWORK_INTERFACES = "networkInterfaces";
+ public static final String NETWORK_FIXED_IP = "fixedIp";
+ public static final String NETWORK_PORT = "portUuid";
+ public static final String NETWORK_UUID = "networkUuid";
- // CloudStack specific
- public static final String USER_NAME = "username";
- public static final String DOMAIN_ID = "domainId";
- public static final String DISK_OFFERING = "diskOffering";
- public static final String NETWORK_IDS = "networkIds";
+ // CloudStack specific
+ public static final String USER_NAME = "username";
+ public static final String DOMAIN_ID = "domainId";
+ public static final String DISK_OFFERING = "diskOffering";
+ public static final String NETWORK_IDS = "networkIds";
- public static final String IS_LOAD_BALANCER = "load.balancer";
+ public static final String IS_LOAD_BALANCER = "load.balancer";
- /**
- * PortRange min max
- */
- public static final int PORT_RANGE_MAX = 65535;
- public static final int PORT_RANGE_MIN = 1;
+ /**
+ * PortRange min max
+ */
+ public static final int PORT_RANGE_MAX = 65535;
+ public static final int PORT_RANGE_MIN = 1;
- public static final String KUBERNETES_PARTITION_PROVIDER = "kubernetes";
+ public static final String KUBERNETES_PARTITION_PROVIDER = "kubernetes";
- /**
- * Load balancing ip type enumeration values
- */
- public static final String LOADBALANCING_IP_TYPE_PRIVATE = "private";
- public static final String LOADBALANCING_IP_TYPE_PUBLIC = "public";
+ /**
+ * Load balancing ip type enumeration values
+ */
+ public static final String LOADBALANCING_IP_TYPE_PRIVATE = "private";
+ public static final String LOADBALANCING_IP_TYPE_PUBLIC = "public";
}
[10/18] stratos git commit: Publishing events for Metering Service
Implementation
Posted by im...@apache.org.
Publishing events for Metering Service Implementation
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/632a3a43
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/632a3a43
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/632a3a43
Branch: refs/heads/master
Commit: 632a3a4319ea55bd7bef7c95442e5fe9878b0898
Parents: 07e8619 2fd289b
Author: Thanuja <th...@wso2.com>
Authored: Wed Jul 22 17:59:57 2015 +0530
Committer: Thanuja <th...@wso2.com>
Committed: Wed Jul 22 17:59:57 2015 +0530
----------------------------------------------------------------------
----------------------------------------------------------------------
[04/18] stratos git commit: Metering Service Implementation
Posted by im...@apache.org.
Metering Service Implementation
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/2fd289b8
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/2fd289b8
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/2fd289b8
Branch: refs/heads/master
Commit: 2fd289b8c6b7f20d56f45e574f77940b3749cb4b
Parents: 00ed5fa
Author: Thanuja <th...@wso2.com>
Authored: Wed Jul 22 14:31:13 2015 +0530
Committer: Thanuja <th...@wso2.com>
Committed: Wed Jul 22 14:31:13 2015 +0530
----------------------------------------------------------------------
.../client/AutoscalerCloudControllerClient.java | 410 +++++-----
.../autoscaler/rule/RuleTasksDelegator.java | 740 ++++++++++---------
.../messaging/topology/TopologyBuilder.java | 454 ++++++------
.../impl/CloudControllerServiceImpl.java | 7 +-
.../impl/CloudControllerServiceUtil.java | 13 +-
.../services/impl/InstanceCreator.java | 223 +++---
.../publisher/BAMUsageDataPublisher.java | 26 +-
.../util/CloudControllerConstants.java | 64 +-
.../common/constants/StratosConstants.java | 394 +++++-----
.../modules/healthstatspublisher/healthstats.py | 6 +-
.../streamdefinitions/stream-manager-config.xml | 486 ++++++------
.../src/main/conf/drools/dependent-scaling.drl | 4 +-
.../src/main/conf/drools/mincheck.drl | 4 +-
.../src/main/conf/drools/scaling.drl | 13 +-
.../main/resources/CloudControllerService.wsdl | 450 ++++++-----
15 files changed, 1732 insertions(+), 1562 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/2fd289b8/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/AutoscalerCloudControllerClient.java
----------------------------------------------------------------------
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 f944a9f..8f20ff1 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
@@ -48,194 +48,224 @@ import java.util.List;
*/
public class AutoscalerCloudControllerClient {
- private static final Log log = LogFactory.getLog(AutoscalerCloudControllerClient.class);
-
- 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();
- int port = conf.getInt("autoscaler.cloudController.port", AutoscalerConstants.CLOUD_CONTROLLER_DEFAULT_PORT);
- String hostname = conf.getString("autoscaler.cloudController.hostname", "localhost");
- String epr = "https://" + hostname + ":" + port + "/" + AutoscalerConstants.CLOUD_CONTROLLER_SERVICE_SFX;
- int cloudControllerClientTimeout = conf.getInt("autoscaler.cloudController.clientTimeout", 180000);
-
- stub = new CloudControllerServiceStub(epr);
- stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, cloudControllerClientTimeout);
- stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT,
- cloudControllerClientTimeout);
- } catch (Exception e) {
- log.error("Could not initialize cloud controller client", e);
- }
- }
-
- public synchronized MemberContext startInstance(PartitionRef partition,
- String clusterId, String clusterInstanceId,
- String networkPartitionId, boolean isPrimary,
- int minMemberCount) throws SpawningException {
- try {
- if (log.isInfoEnabled()) {
- log.info(String.format("Trying to spawn an instance via cloud controller: " +
- "[cluster] %s [partition] %s [network-partition-id] %s",
- clusterId, partition.getId(), networkPartitionId));
- }
-
- XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
- long expiryTime = conf.getLong(StratosConstants.OBSOLETED_MEMBER_EXPIRY_TIMEOUT, 86400000);
- if (log.isDebugEnabled()) {
- log.debug("Member obsolete expiry time is set to: " + expiryTime);
- }
-
- InstanceContext instanceContext = new InstanceContext();
- instanceContext.setClusterId(clusterId);
- instanceContext.setClusterInstanceId(clusterInstanceId);
- instanceContext.setPartition(AutoscalerObjectConverter.convertPartitionToCCPartition(partition));
- instanceContext.setInitTime(System.currentTimeMillis());
- instanceContext.setObsoleteExpiryTime(expiryTime);
- instanceContext.setNetworkPartitionId(networkPartitionId);
-
- Properties memberContextProps = new Properties();
- Property isPrimaryProp = new Property();
- isPrimaryProp.setName("PRIMARY");
- isPrimaryProp.setValue(String.valueOf(isPrimary));
-
- Property minCountProp = new Property();
- minCountProp.setName(StratosConstants.MIN_COUNT);
- minCountProp.setValue(String.valueOf(minMemberCount));
-
- memberContextProps.addProperty(isPrimaryProp);
- memberContextProps.addProperty(minCountProp);
- instanceContext.setProperties(AutoscalerUtil.toStubProperties(memberContextProps));
-
- long startTime = System.currentTimeMillis();
- MemberContext memberContext = stub.startInstance(instanceContext);
-
- if (log.isDebugEnabled()) {
- long endTime = System.currentTimeMillis();
- log.debug(String.format("Service call startInstance() returned in %dms", (endTime - startTime)));
- }
- return memberContext;
- } catch (CloudControllerServiceCartridgeNotFoundExceptionException e) {
- String message = e.getFaultMessage().getCartridgeNotFoundException().getMessage();
- log.error(message, e);
- throw new SpawningException(message, e);
- } catch (RemoteException e) {
- log.error(e.getMessage(), e);
- throw new SpawningException(e.getMessage(), e);
- } catch (CloudControllerServiceInvalidIaasProviderExceptionException e) {
- String message = e.getFaultMessage().getInvalidIaasProviderException().getMessage();
- log.error(message, e);
- throw new SpawningException(message, e);
- } catch (CloudControllerServiceCloudControllerExceptionException e) {
- String message = e.getMessage();
- log.error(message, e);
- throw new SpawningException(message, e);
- }
- }
-
- public synchronized void createApplicationClusters(String appId,
- ApplicationClusterContext[] applicationClusterContexts) {
- List<org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext> contextDTOs =
- new ArrayList<org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext>();
- if (applicationClusterContexts != null) {
- for (ApplicationClusterContext applicationClusterContext : applicationClusterContexts) {
- if (applicationClusterContext != null) {
- org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext dto =
- new org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext();
- dto.setClusterId(applicationClusterContext.getClusterId());
- dto.setAutoscalePolicyName(applicationClusterContext.getAutoscalePolicyName());
- dto.setDeploymentPolicyName(applicationClusterContext.getDeploymentPolicyName());
- dto.setCartridgeType(applicationClusterContext.getCartridgeType());
- dto.setHostName(applicationClusterContext.getHostName());
- dto.setTenantRange(applicationClusterContext.getTenantRange());
- dto.setTextPayload(applicationClusterContext.getTextPayload());
- dto.setProperties(AutoscalerUtil.toStubProperties(applicationClusterContext.getProperties()));
- dto.setDependencyClusterIds(applicationClusterContext.getDependencyClusterIds());
- if (applicationClusterContext.getPersistenceContext() != null) {
- dto.setVolumeRequired(true);
- dto.setVolumes(convertVolumesToStubVolumes(
- applicationClusterContext.getPersistenceContext().getVolumes()));
- }
- contextDTOs.add(dto);
- }
- }
- }
-
- org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext[] applicationClusterContextDTOs =
- new org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext[contextDTOs.size()];
- contextDTOs.toArray(applicationClusterContextDTOs);
- try {
- stub.createApplicationClusters(appId, applicationClusterContextDTOs);
- } catch (RemoteException e) {
- String msg = e.getMessage();
- log.error(msg, e);
- } catch (CloudControllerServiceApplicationClusterRegistrationExceptionException e) {
- String msg = e.getMessage();
- log.error(msg, e);
- }
- }
-
-
- private Volume[] convertVolumesToStubVolumes(VolumeContext[] volumeContexts) {
-
- ArrayList<Volume> volumes = new ArrayList<Volume>();
- for (VolumeContext volumeContext : volumeContexts) {
- Volume volume = new Volume();
- volume.setRemoveOntermination(volumeContext.isRemoveOntermination());
- volume.setMappingPath(volumeContext.getMappingPath());
- volume.setId(volumeContext.getId());
- volume.setDevice(volumeContext.getDevice());
- volume.setIaasType(volumeContext.getIaasType());
- volume.setSnapshotId(volumeContext.getSnapshotId());
- volume.setVolumeId(volumeContext.getVolumeId());
- volume.setSize(volumeContext.getSize());
- volumes.add(volume);
- }
- return volumes.toArray(new Volume[volumes.size()]);
- }
-
- public void terminateInstance(String memberId) throws Exception {
- if (log.isInfoEnabled()) {
- log.info(String.format("Terminating instance via cloud controller: [member] %s", memberId));
- }
- long startTime = System.currentTimeMillis();
- stub.terminateInstance(memberId);
- if (log.isDebugEnabled()) {
- long endTime = System.currentTimeMillis();
- log.debug(String.format("Service call terminateInstance() returned in %dms", (endTime - startTime)));
- }
- }
-
- public void terminateInstanceForcefully(String memberId) throws Exception {
- if (log.isDebugEnabled()) {
- log.debug(String.format("Terminating instance forcefully via cloud controller: [member] %s", memberId));
- }
- stub.terminateInstanceForcefully(memberId);
- }
-
- public void terminateAllInstances(String clusterId) throws RemoteException,
- CloudControllerServiceInvalidClusterExceptionException {
- if (log.isInfoEnabled()) {
- log.info(String.format("Terminating all instances of cluster via cloud controller: [cluster] %s", clusterId));
- }
- long startTime = System.currentTimeMillis();
- stub.terminateInstances(clusterId);
-
- if (log.isDebugEnabled()) {
- long endTime = System.currentTimeMillis();
- log.debug(String.format("Service call terminateInstances() returned in %dms", (endTime - startTime)));
- }
- }
+ private static final Log log = LogFactory.getLog(AutoscalerCloudControllerClient.class);
+
+ 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();
+ int port = conf.getInt("autoscaler.cloudController.port",
+ AutoscalerConstants.CLOUD_CONTROLLER_DEFAULT_PORT);
+ String hostname = conf.getString("autoscaler.cloudController.hostname", "localhost");
+ String epr = "https://" + hostname + ":" + port + "/" +
+ AutoscalerConstants.CLOUD_CONTROLLER_SERVICE_SFX;
+ int cloudControllerClientTimeout =
+ conf.getInt("autoscaler.cloudController.clientTimeout", 180000);
+
+ stub = new CloudControllerServiceStub(epr);
+ stub._getServiceClient().getOptions()
+ .setProperty(HTTPConstants.SO_TIMEOUT, cloudControllerClientTimeout);
+ stub._getServiceClient().getOptions()
+ .setProperty(HTTPConstants.CONNECTION_TIMEOUT, cloudControllerClientTimeout);
+ } catch (Exception e) {
+ log.error("Could not initialize cloud controller client", e);
+ }
+ }
+
+ public synchronized MemberContext startInstance(PartitionRef partition, String clusterId,
+ String clusterInstanceId,
+ String networkPartitionId, boolean isPrimary,
+ int minMemberCount, String autoscalingReason,
+ long scalingTime) throws SpawningException {
+ try {
+ if (log.isInfoEnabled()) {
+ log.info(String.format("Trying to spawn an instance via cloud controller: " +
+ "[cluster] %s [partition] %s [network-partition-id] %s",
+ clusterId, partition.getId(), networkPartitionId));
+ }
+
+ XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
+ long expiryTime =
+ conf.getLong(StratosConstants.OBSOLETED_MEMBER_EXPIRY_TIMEOUT, 86400000);
+ if (log.isDebugEnabled()) {
+ log.debug("Member obsolete expiry time is set to: " + expiryTime);
+ }
+
+ InstanceContext instanceContext = new InstanceContext();
+ instanceContext.setClusterId(clusterId);
+ instanceContext.setClusterInstanceId(clusterInstanceId);
+ instanceContext.setPartition(
+ AutoscalerObjectConverter.convertPartitionToCCPartition(partition));
+ instanceContext.setInitTime(System.currentTimeMillis());
+ instanceContext.setObsoleteExpiryTime(expiryTime);
+ instanceContext.setNetworkPartitionId(networkPartitionId);
+
+ Properties memberContextProps = new Properties();
+ Property isPrimaryProp = new Property();
+ isPrimaryProp.setName("PRIMARY");
+ isPrimaryProp.setValue(String.valueOf(isPrimary));
+
+ Property minCountProp = new Property();
+ minCountProp.setName(StratosConstants.MIN_COUNT);
+ minCountProp.setValue(String.valueOf(minMemberCount));
+
+ Property autoscalingReasonProp = new Property();
+ autoscalingReasonProp.setName(StratosConstants.SCALING_REASON);
+ autoscalingReasonProp.setValue(autoscalingReason);
+
+ Property scalingTimeProp = new Property();
+ scalingTimeProp.setName(StratosConstants.SCALING_TIME);
+ scalingTimeProp.setValue(String.valueOf(scalingTime));
+
+ memberContextProps.addProperty(isPrimaryProp);
+ memberContextProps.addProperty(minCountProp);
+ memberContextProps.addProperty(autoscalingReasonProp);
+ memberContextProps.addProperty(scalingTimeProp);
+ instanceContext.setProperties(AutoscalerUtil.toStubProperties(memberContextProps));
+
+ long startTime = System.currentTimeMillis();
+ MemberContext memberContext = stub.startInstance(instanceContext);
+
+ if (log.isDebugEnabled()) {
+ long endTime = System.currentTimeMillis();
+ log.debug(String.format("Service call startInstance() returned in %dms",
+ (endTime - startTime)));
+ }
+ return memberContext;
+ } catch (CloudControllerServiceCartridgeNotFoundExceptionException e) {
+ String message = e.getFaultMessage().getCartridgeNotFoundException().getMessage();
+ log.error(message, e);
+ throw new SpawningException(message, e);
+ } catch (RemoteException e) {
+ log.error(e.getMessage(), e);
+ throw new SpawningException(e.getMessage(), e);
+ } catch (CloudControllerServiceInvalidIaasProviderExceptionException e) {
+ String message = e.getFaultMessage().getInvalidIaasProviderException().getMessage();
+ log.error(message, e);
+ throw new SpawningException(message, e);
+ } catch (CloudControllerServiceCloudControllerExceptionException e) {
+ String message = e.getMessage();
+ log.error(message, e);
+ throw new SpawningException(message, e);
+ }
+ }
+
+ public synchronized void createApplicationClusters(String appId,
+ ApplicationClusterContext[] applicationClusterContexts) {
+ List<org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext>
+ contextDTOs =
+ new ArrayList<org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext>();
+ if (applicationClusterContexts != null) {
+ for (ApplicationClusterContext applicationClusterContext : applicationClusterContexts) {
+ if (applicationClusterContext != null) {
+ org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext dto =
+ new org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext();
+ dto.setClusterId(applicationClusterContext.getClusterId());
+ dto.setAutoscalePolicyName(applicationClusterContext.getAutoscalePolicyName());
+ dto.setDeploymentPolicyName(
+ applicationClusterContext.getDeploymentPolicyName());
+ dto.setCartridgeType(applicationClusterContext.getCartridgeType());
+ dto.setHostName(applicationClusterContext.getHostName());
+ dto.setTenantRange(applicationClusterContext.getTenantRange());
+ dto.setTextPayload(applicationClusterContext.getTextPayload());
+ dto.setProperties(AutoscalerUtil.toStubProperties(
+ applicationClusterContext.getProperties()));
+ dto.setDependencyClusterIds(
+ applicationClusterContext.getDependencyClusterIds());
+ if (applicationClusterContext.getPersistenceContext() != null) {
+ dto.setVolumeRequired(true);
+ dto.setVolumes(convertVolumesToStubVolumes(
+ applicationClusterContext.getPersistenceContext().getVolumes()));
+ }
+ contextDTOs.add(dto);
+ }
+ }
+ }
+
+ org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext[]
+ applicationClusterContextDTOs =
+ new org.apache.stratos.cloud.controller.stub.domain.ApplicationClusterContext[contextDTOs
+ .size()];
+ contextDTOs.toArray(applicationClusterContextDTOs);
+ try {
+ stub.createApplicationClusters(appId, applicationClusterContextDTOs);
+ } catch (RemoteException e) {
+ String msg = e.getMessage();
+ log.error(msg, e);
+ } catch (CloudControllerServiceApplicationClusterRegistrationExceptionException e) {
+ String msg = e.getMessage();
+ log.error(msg, e);
+ }
+ }
+
+ private Volume[] convertVolumesToStubVolumes(VolumeContext[] volumeContexts) {
+
+ ArrayList<Volume> volumes = new ArrayList<Volume>();
+ for (VolumeContext volumeContext : volumeContexts) {
+ Volume volume = new Volume();
+ volume.setRemoveOntermination(volumeContext.isRemoveOntermination());
+ volume.setMappingPath(volumeContext.getMappingPath());
+ volume.setId(volumeContext.getId());
+ volume.setDevice(volumeContext.getDevice());
+ volume.setIaasType(volumeContext.getIaasType());
+ volume.setSnapshotId(volumeContext.getSnapshotId());
+ volume.setVolumeId(volumeContext.getVolumeId());
+ volume.setSize(volumeContext.getSize());
+ volumes.add(volume);
+ }
+ return volumes.toArray(new Volume[volumes.size()]);
+ }
+
+ public void terminateInstance(String memberId) throws Exception {
+ if (log.isInfoEnabled()) {
+ log.info(String.format("Terminating instance via cloud controller: [member] %s",
+ memberId));
+ }
+ long startTime = System.currentTimeMillis();
+ stub.terminateInstance(memberId);
+ if (log.isDebugEnabled()) {
+ long endTime = System.currentTimeMillis();
+ log.debug(String.format("Service call terminateInstance() returned in %dms",
+ (endTime - startTime)));
+ }
+ }
+
+ public void terminateInstanceForcefully(String memberId) throws Exception {
+ if (log.isDebugEnabled()) {
+ log.debug(String.format(
+ "Terminating instance forcefully via cloud controller: [member] %s", memberId));
+ }
+ stub.terminateInstanceForcefully(memberId);
+ }
+
+ public void terminateAllInstances(String clusterId)
+ throws RemoteException, CloudControllerServiceInvalidClusterExceptionException {
+ if (log.isInfoEnabled()) {
+ log.info(String.format(
+ "Terminating all instances of cluster via cloud controller: [cluster] %s",
+ clusterId));
+ }
+ long startTime = System.currentTimeMillis();
+ stub.terminateInstances(clusterId);
+
+ if (log.isDebugEnabled()) {
+ long endTime = System.currentTimeMillis();
+ log.debug(String.format("Service call terminateInstances() returned in %dms",
+ (endTime - startTime)));
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/2fd289b8/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java
----------------------------------------------------------------------
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 51443a1..83cfb18 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
@@ -36,7 +36,6 @@ import org.apache.stratos.autoscaler.context.partition.network.ClusterLevelNetwo
import org.apache.stratos.autoscaler.event.publisher.InstanceNotificationPublisher;
import org.apache.stratos.autoscaler.monitor.cluster.ClusterMonitor;
import org.apache.stratos.cloud.controller.stub.domain.MemberContext;
-import org.apache.stratos.common.client.CloudControllerServiceClient;
import org.apache.stratos.common.constants.StratosConstants;
/**
@@ -44,347 +43,400 @@ import org.apache.stratos.common.constants.StratosConstants;
*/
public class RuleTasksDelegator {
- private static boolean arspiIsSet = false;
-
- private static final Log log = LogFactory.getLog(RuleTasksDelegator.class);
-
- public double getPredictedValueForNextMinute(float average, float gradient, float secondDerivative, int timeInterval) {
- double predictedValue;
-// 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;
- }
-
-
- public int getNumberOfInstancesRequiredBasedOnRif(float rifPredictedValue, float rifThreshold) {
-
- if (rifThreshold != 0) {
-
- float requiredNumberOfInstances = rifPredictedValue / rifThreshold;
- return (int) Math.ceil(requiredNumberOfInstances);
- } else {
- log.error("Request in flight threshold is Zero");
- return 0;
- }
-
- }
-
- public int getNumberOfInstancesRequiredBasedOnMemoryConsumption(float threshold, double predictedValue,
- int min, int max) {
- double numberOfAdditionalInstancesRequired = 0;
- if (predictedValue != threshold) {
-
- float scalingRange = 100 - threshold;
- int instanceRange = max - min;
-
- if (instanceRange != 0) {
-
- float gradient = scalingRange / instanceRange;
- numberOfAdditionalInstancesRequired = (predictedValue - threshold) / gradient;
- }
-
- if (predictedValue < threshold) {
- //Since predicted-value is less, it can be scale-down
- return min - 1;
- }
- }
-
- return (int) Math.ceil(min + numberOfAdditionalInstancesRequired);
- }
-
- public int getNumberOfInstancesRequiredBasedOnLoadAverage(float threshold, double predictedValue,
- int min) {
-
- double numberOfInstances;
- if (threshold != 0) {
-
- numberOfInstances = (min * predictedValue) / threshold;
- return (int) Math.ceil(numberOfInstances);
- }
-
- return min;
- }
-
- public int getMaxNumberOfInstancesRequired(int numberOfInstancesRequiredBasedOnRif,
- int numberOfInstancesRequiredBasedOnMemoryConsumption,
- boolean mcReset, int numberOfInstancesReuquiredBasedOnLoadAverage,
- boolean laReset) {
- int numberOfInstances = 0;
-
- int rifBasedRequiredInstances = 0;
- int mcBasedRequiredInstances = 0;
- int laBasedRequiredInstances = 0;
- if (arspiIsSet) {
- rifBasedRequiredInstances = numberOfInstancesRequiredBasedOnRif;
- }
- if (mcReset) {
- mcBasedRequiredInstances = numberOfInstancesRequiredBasedOnMemoryConsumption;
- }
- if (laReset) {
- laBasedRequiredInstances = numberOfInstancesReuquiredBasedOnLoadAverage;
- }
- numberOfInstances = Math.max(Math.max(numberOfInstancesRequiredBasedOnMemoryConsumption,
- numberOfInstancesReuquiredBasedOnLoadAverage), numberOfInstancesRequiredBasedOnRif);
- return numberOfInstances;
- }
-
- public PartitionAlgorithm getPartitionAlgorithm(String partitionAlgorithm) {
-
- PartitionAlgorithm autoscaleAlgorithm = null;
- //FIXME to not parse for algo when partition is chosen by the parent
-
- if (partitionAlgorithm == null) {
- //Send one after another as default
- partitionAlgorithm = StratosConstants.PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID;
- }
- if (log.isDebugEnabled()) {
- log.debug(String.format("Retrieving partition algorithm [Partition algorithm]: %s", partitionAlgorithm));
- }
- if (StratosConstants.PARTITION_ROUND_ROBIN_ALGORITHM_ID.equals(partitionAlgorithm)) {
- autoscaleAlgorithm = new RoundRobin();
- } else if (StratosConstants.PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID.equals(partitionAlgorithm)) {
- autoscaleAlgorithm = new OneAfterAnother();
- } else {
- if (log.isErrorEnabled()) {
- log.error(String.format("Partition algorithm %s could not be identified !", partitionAlgorithm));
- }
- }
- return autoscaleAlgorithm;
- }
-
- public void delegateInstanceCleanup(String memberId) {
- try {
- // send the instance notification event.
- InstanceNotificationPublisher.getInstance().sendInstanceCleanupEventForMember(memberId);
- log.info("Instance clean up event sent for [member] " + memberId);
-
- } catch (Exception e) {
- log.error("Cannot terminate instance", e);
- }
- }
-
- /**
- * Invoked from drools to start an instance.
- *
- * @param clusterMonitorPartitionContext Cluster monitor partition context
- * @param clusterId Cluster id
- * @param clusterInstanceId Instance id
- * @param isPrimary Is a primary member
- */
- public void delegateSpawn(ClusterLevelPartitionContext clusterMonitorPartitionContext, String clusterId,
- String clusterInstanceId, boolean isPrimary) {
-
- try {
- String nwPartitionId = clusterMonitorPartitionContext.getNetworkPartitionId();
-
- // Calculate accumulation of minimum counts of all the partition of current network partition
- int minimumCountOfNetworkPartition;
- ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getClusterMonitor(clusterId);
- ClusterContext clusterContext = clusterMonitor.getClusterContext();
- ClusterLevelNetworkPartitionContext clusterLevelNetworkPartitionContext =
- clusterContext.getNetworkPartitionCtxt(nwPartitionId);
- ClusterInstanceContext clusterInstanceContext =
- (ClusterInstanceContext) clusterLevelNetworkPartitionContext.
- getInstanceContext(clusterInstanceId);
- minimumCountOfNetworkPartition = clusterInstanceContext.getMinInstanceCount();
-
- MemberContext memberContext =
- AutoscalerCloudControllerClient.getInstance()
- .startInstance(clusterMonitorPartitionContext.getPartition(),
- clusterId,
- clusterInstanceId, clusterMonitorPartitionContext.getNetworkPartitionId(),
- isPrimary,
- minimumCountOfNetworkPartition);
- if (memberContext != null) {
- ClusterLevelPartitionContext partitionContext = clusterInstanceContext.
- getPartitionCtxt(clusterMonitorPartitionContext.getPartitionId());
- partitionContext.addPendingMember(memberContext);
- partitionContext.addMemberStatsContext(new MemberStatsContext(memberContext.getMemberId()));
- if (log.isDebugEnabled()) {
- log.debug(String.format("Pending member added, [member] %s [partition] %s", memberContext.getMemberId(),
- memberContext.getPartition().getId()));
- }
-
- } else {
- if (log.isErrorEnabled()) {
- log.error("Member context returned from cloud controller is null");
- }
- }
- } catch (Exception e) {
- String message = String.format("Could not start instance: [cluster-id] %s [instance-id] %s",
- clusterId, clusterInstanceId);
- log.error(message, e);
- throw new RuntimeException(message, e);
- }
- }
-
- public void delegateScalingDependencyNotification(String clusterId, String networkPartitionId, String instanceId,
- int requiredInstanceCount, int minimumInstanceCount) {
-
- if (log.isDebugEnabled()) {
- log.debug("Scaling dependent notification is going to the [parentInstance] " + instanceId);
- }
- //Notify parent for checking scaling dependencies
- ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getClusterMonitor(clusterId);
- float fMinimumInstanceCount = minimumInstanceCount;
- float factor = requiredInstanceCount / fMinimumInstanceCount;
- clusterMonitor.sendClusterScalingEvent(networkPartitionId, instanceId, factor);
- }
-
- public void delegateScalingOverMaxNotification(String clusterId, String networkPartitionId, String instanceId) {
- if (log.isDebugEnabled()) {
- log.debug("Scaling max out notification is going to the [parentInstance] " + instanceId);
- }
- //Notify parent for checking scaling dependencies
- ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getClusterMonitor(clusterId);
- clusterMonitor.sendScalingOverMaxEvent(networkPartitionId, instanceId);
- }
-
- public void delegateScalingDownBeyondMinNotification(String clusterId, String networkPartitionId, String instanceId) {
- if (log.isDebugEnabled()) {
- log.debug("Scaling down lower min notification is going to the [parentInstance] " + instanceId);
- }
- //Notify parent for checking scaling dependencies
- ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().getClusterMonitor(clusterId);
- clusterMonitor.sendScalingDownBeyondMinEvent(networkPartitionId, instanceId);
- }
-
- public void delegateTerminate(ClusterLevelPartitionContext clusterMonitorPartitionContext, String memberId) {
-
- try {
- //Moving member to pending termination list
- if (clusterMonitorPartitionContext.activeMemberAvailable(memberId)) {
-
- log.info(String.format("[scale-down] Moving active member to termination pending list [member id] %s " +
- "[partition] %s [network partition] %s", memberId,
- clusterMonitorPartitionContext.getPartitionId(),
- clusterMonitorPartitionContext.getNetworkPartitionId()));
- clusterMonitorPartitionContext.moveActiveMemberToTerminationPendingMembers(memberId);
- clusterMonitorPartitionContext.removeMemberStatsContext(memberId);
- } else if (clusterMonitorPartitionContext.pendingMemberAvailable(memberId)) {
-
- log.info(String.format("[scale-down] Moving pending member to termination pending list [member id] %s " +
- "[partition] %s [network partition] %s", memberId,
- clusterMonitorPartitionContext.getPartitionId(),
- clusterMonitorPartitionContext.getNetworkPartitionId()));
- clusterMonitorPartitionContext.movePendingMemberToObsoleteMembers(memberId);
- clusterMonitorPartitionContext.removeMemberStatsContext(memberId);
- }
- } catch (Exception e) {
- log.error("[scale-down] Cannot move member to termination pending list ", e);
- }
- }
-
- public void delegateTerminateDependency(ClusterLevelPartitionContext clusterMonitorPartitionContext, String memberId) {
- try {
- //calling SM to send the instance notification event.
- if (log.isDebugEnabled()) {
- log.debug("delegateTerminateDependency:memberId:" + memberId);
- }
- //InstanceNotificationClient.getInstance().sendMemberCleanupEvent(memberId);
- //partitionContext.moveActiveMemberToTerminationPendingMembers(memberId);
- //CloudControllerClient.getInstance().terminate(memberId);
- } catch (Exception e) {
- log.error("Cannot terminate instance", e);
- }
- }
-
- public void terminateObsoleteInstance(String memberId) {
- try {
- AutoscalerCloudControllerClient.getInstance().terminateInstance(memberId);
- } catch (Exception e) {
- log.error("Cannot terminate instance", e);
- }
- }
-
- //Grouping
- public void delegateTerminateAll(String clusterId) {
- try {
- if (log.isDebugEnabled()) {
- log.debug("delegateTerminateAll - begin");
- }
- AutoscalerCloudControllerClient.getInstance().terminateAllInstances(clusterId);
- if (log.isDebugEnabled()) {
- log.debug("delegateTerminateAll - done");
- }
- } catch (Exception e) {
- log.error("Cannot terminate instance", e);
- }
- }
-
- public int getPredictedReplicasForStat(int minReplicas, float statUpperLimit, float statPredictedValue) {
- if (statUpperLimit == 0) {
- return 0;
- }
- float predictedValue = ((minReplicas / statUpperLimit) * statPredictedValue);
- return (int) Math.ceil(predictedValue);
- }
-
- public double getLoadAveragePredictedValue(ClusterInstanceContext clusterInstanceContext) {
- double loadAveragePredicted = 0.0d;
- int totalMemberCount = 0;
- for (ClusterLevelPartitionContext partitionContext : clusterInstanceContext.getPartitionCtxts()) {
- for (MemberStatsContext memberStatsContext : partitionContext.getMemberStatsContexts().values()) {
-
- float memberAverageLoadAverage = memberStatsContext.getLoadAverage().getAverage();
- float memberGredientLoadAverage = memberStatsContext.getLoadAverage().getGradient();
- float memberSecondDerivativeLoadAverage = memberStatsContext.getLoadAverage().getSecondDerivative();
-
- double memberPredictedLoadAverage = getPredictedValueForNextMinute(memberAverageLoadAverage,
- memberGredientLoadAverage, memberSecondDerivativeLoadAverage, 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("Predicted load average : " + loadAveragePredicted / totalMemberCount);
- return loadAveragePredicted / totalMemberCount;
- } else {
- 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()) {
-
- float memberMemoryConsumptionAverage = memberStatsContext.getMemoryConsumption().getAverage();
- float memberMemoryConsumptionGredient = memberStatsContext.getMemoryConsumption().getGradient();
- float memberMemoryConsumptionSecondDerivative = memberStatsContext.getMemoryConsumption().getSecondDerivative();
-
- double memberPredictedMemoryConsumption = getPredictedValueForNextMinute(memberMemoryConsumptionAverage,
- memberMemoryConsumptionGredient, memberMemoryConsumptionSecondDerivative, 1);
-
- 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("Predicted memory consumption : " + memoryConsumptionPredicted / totalMemberCount);
- return memoryConsumptionPredicted / totalMemberCount;
- } else {
- return 0;
- }
- }
+ private static boolean arspiIsSet = false;
+
+ private static final Log log = LogFactory.getLog(RuleTasksDelegator.class);
+
+ public double getPredictedValueForNextMinute(float average, float gradient,
+ float secondDerivative, int timeInterval) {
+ double predictedValue;
+ // 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;
+ }
+
+ public int getNumberOfInstancesRequiredBasedOnRif(float rifPredictedValue, float rifThreshold) {
+
+ if (rifThreshold != 0) {
+
+ float requiredNumberOfInstances = rifPredictedValue / rifThreshold;
+ return (int) Math.ceil(requiredNumberOfInstances);
+ } else {
+ log.error("Request in flight threshold is Zero");
+ return 0;
+ }
+
+ }
+
+ public int getNumberOfInstancesRequiredBasedOnMemoryConsumption(float threshold,
+ double predictedValue, int min,
+ int max) {
+ double numberOfAdditionalInstancesRequired = 0;
+ if (predictedValue != threshold) {
+
+ float scalingRange = 100 - threshold;
+ int instanceRange = max - min;
+
+ if (instanceRange != 0) {
+
+ float gradient = scalingRange / instanceRange;
+ numberOfAdditionalInstancesRequired = (predictedValue - threshold) / gradient;
+ }
+
+ if (predictedValue < threshold) {
+ //Since predicted-value is less, it can be scale-down
+ return min - 1;
+ }
+ }
+
+ return (int) Math.ceil(min + numberOfAdditionalInstancesRequired);
+ }
+
+ public int getNumberOfInstancesRequiredBasedOnLoadAverage(float threshold,
+ double predictedValue, int min) {
+
+ double numberOfInstances;
+ if (threshold != 0) {
+
+ numberOfInstances = (min * predictedValue) / threshold;
+ return (int) Math.ceil(numberOfInstances);
+ }
+
+ return min;
+ }
+
+ public int getMaxNumberOfInstancesRequired(int numberOfInstancesRequiredBasedOnRif,
+ int numberOfInstancesRequiredBasedOnMemoryConsumption,
+ boolean mcReset,
+ int numberOfInstancesReuquiredBasedOnLoadAverage,
+ boolean laReset) {
+ int numberOfInstances = 0;
+
+ int rifBasedRequiredInstances = 0;
+ int mcBasedRequiredInstances = 0;
+ int laBasedRequiredInstances = 0;
+ if (arspiIsSet) {
+ rifBasedRequiredInstances = numberOfInstancesRequiredBasedOnRif;
+ }
+ if (mcReset) {
+ mcBasedRequiredInstances = numberOfInstancesRequiredBasedOnMemoryConsumption;
+ }
+ if (laReset) {
+ laBasedRequiredInstances = numberOfInstancesReuquiredBasedOnLoadAverage;
+ }
+ numberOfInstances = Math.max(Math.max(numberOfInstancesRequiredBasedOnMemoryConsumption,
+ numberOfInstancesReuquiredBasedOnLoadAverage),
+ numberOfInstancesRequiredBasedOnRif);
+ return numberOfInstances;
+ }
+
+ public PartitionAlgorithm getPartitionAlgorithm(String partitionAlgorithm) {
+
+ PartitionAlgorithm autoscaleAlgorithm = null;
+ //FIXME to not parse for algo when partition is chosen by the parent
+
+ if (partitionAlgorithm == null) {
+ //Send one after another as default
+ partitionAlgorithm = StratosConstants.PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Retrieving partition algorithm [Partition algorithm]: %s",
+ partitionAlgorithm));
+ }
+ if (StratosConstants.PARTITION_ROUND_ROBIN_ALGORITHM_ID.equals(partitionAlgorithm)) {
+ autoscaleAlgorithm = new RoundRobin();
+ } else if (StratosConstants.PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID
+ .equals(partitionAlgorithm)) {
+ autoscaleAlgorithm = new OneAfterAnother();
+ } else {
+ if (log.isErrorEnabled()) {
+ log.error(String.format("Partition algorithm %s could not be identified !",
+ partitionAlgorithm));
+ }
+ }
+ return autoscaleAlgorithm;
+ }
+
+ public void delegateInstanceCleanup(String memberId) {
+ try {
+ // send the instance notification event.
+ InstanceNotificationPublisher.getInstance().sendInstanceCleanupEventForMember(memberId);
+ log.info("Instance clean up event sent for [member] " + memberId);
+
+ } catch (Exception e) {
+ log.error("Cannot terminate instance", e);
+ }
+ }
+
+ /**
+ * Invoked from drools to start an instance.
+ *
+ * @param clusterMonitorPartitionContext Cluster monitor partition context
+ * @param clusterId Cluster id
+ * @param clusterInstanceId Instance id
+ * @param isPrimary Is a primary member
+ */
+ public void delegateSpawn(ClusterLevelPartitionContext clusterMonitorPartitionContext,
+ String clusterId, String clusterInstanceId, boolean isPrimary,
+ String autoscalingReason, long scalingTime) {
+
+ try {
+ String nwPartitionId = clusterMonitorPartitionContext.getNetworkPartitionId();
+
+ // Calculate accumulation of minimum counts of all the partition of current network partition
+ int minimumCountOfNetworkPartition;
+ ClusterMonitor clusterMonitor =
+ AutoscalerContext.getInstance().getClusterMonitor(clusterId);
+ ClusterContext clusterContext = clusterMonitor.getClusterContext();
+ ClusterLevelNetworkPartitionContext clusterLevelNetworkPartitionContext =
+ clusterContext.getNetworkPartitionCtxt(nwPartitionId);
+ ClusterInstanceContext clusterInstanceContext =
+ (ClusterInstanceContext) clusterLevelNetworkPartitionContext.
+ getInstanceContext(
+ clusterInstanceId);
+ minimumCountOfNetworkPartition = clusterInstanceContext.getMinInstanceCount();
+
+ MemberContext memberContext = AutoscalerCloudControllerClient.getInstance()
+ .startInstance(
+ clusterMonitorPartitionContext
+ .getPartition(),
+ clusterId,
+ clusterInstanceId,
+ clusterMonitorPartitionContext
+ .getNetworkPartitionId(),
+ isPrimary,
+ minimumCountOfNetworkPartition,
+ autoscalingReason,
+ scalingTime);
+ if (memberContext != null) {
+ ClusterLevelPartitionContext partitionContext = clusterInstanceContext.
+ getPartitionCtxt(
+ clusterMonitorPartitionContext
+ .getPartitionId());
+ partitionContext.addPendingMember(memberContext);
+ partitionContext
+ .addMemberStatsContext(new MemberStatsContext(memberContext.getMemberId()));
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Pending member added, [member] %s [partition] %s",
+ memberContext.getMemberId(),
+ memberContext.getPartition().getId()));
+ }
+
+ } else {
+ if (log.isErrorEnabled()) {
+ log.error("Member context returned from cloud controller is null");
+ }
+ }
+ } catch (Exception e) {
+ String message =
+ String.format("Could not start instance: [cluster-id] %s [instance-id] %s",
+ clusterId, clusterInstanceId);
+ log.error(message, e);
+ throw new RuntimeException(message, e);
+ }
+ }
+
+ public void delegateScalingDependencyNotification(String clusterId, String networkPartitionId,
+ String instanceId, int requiredInstanceCount,
+ int minimumInstanceCount) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Scaling dependent notification is going to the [parentInstance] " +
+ instanceId);
+ }
+ //Notify parent for checking scaling dependencies
+ ClusterMonitor clusterMonitor =
+ AutoscalerContext.getInstance().getClusterMonitor(clusterId);
+ float fMinimumInstanceCount = minimumInstanceCount;
+ float factor = requiredInstanceCount / fMinimumInstanceCount;
+ clusterMonitor.sendClusterScalingEvent(networkPartitionId, instanceId, factor);
+ }
+
+ public void delegateScalingOverMaxNotification(String clusterId, String networkPartitionId,
+ String instanceId) {
+ if (log.isDebugEnabled()) {
+ log.debug(
+ "Scaling max out notification is going to the [parentInstance] " + instanceId);
+ }
+ //Notify parent for checking scaling dependencies
+ ClusterMonitor clusterMonitor =
+ AutoscalerContext.getInstance().getClusterMonitor(clusterId);
+ clusterMonitor.sendScalingOverMaxEvent(networkPartitionId, instanceId);
+ }
+
+ public void delegateScalingDownBeyondMinNotification(String clusterId,
+ String networkPartitionId,
+ String instanceId) {
+ if (log.isDebugEnabled()) {
+ log.debug("Scaling down lower min notification is going to the [parentInstance] " +
+ instanceId);
+ }
+ //Notify parent for checking scaling dependencies
+ ClusterMonitor clusterMonitor =
+ AutoscalerContext.getInstance().getClusterMonitor(clusterId);
+ clusterMonitor.sendScalingDownBeyondMinEvent(networkPartitionId, instanceId);
+ }
+
+ public void delegateTerminate(ClusterLevelPartitionContext clusterMonitorPartitionContext,
+ String memberId) {
+
+ try {
+ //Moving member to pending termination list
+ if (clusterMonitorPartitionContext.activeMemberAvailable(memberId)) {
+
+ log.info(String.format(
+ "[scale-down] Moving active member to termination pending list [member id] %s " +
+ "[partition] %s [network partition] %s", memberId,
+ clusterMonitorPartitionContext.getPartitionId(),
+ clusterMonitorPartitionContext.getNetworkPartitionId()));
+ clusterMonitorPartitionContext
+ .moveActiveMemberToTerminationPendingMembers(memberId);
+ clusterMonitorPartitionContext.removeMemberStatsContext(memberId);
+ } else if (clusterMonitorPartitionContext.pendingMemberAvailable(memberId)) {
+
+ log.info(String.format(
+ "[scale-down] Moving pending member to termination pending list [member id] %s " +
+ "[partition] %s [network partition] %s", memberId,
+ clusterMonitorPartitionContext.getPartitionId(),
+ clusterMonitorPartitionContext.getNetworkPartitionId()));
+ clusterMonitorPartitionContext.movePendingMemberToObsoleteMembers(memberId);
+ clusterMonitorPartitionContext.removeMemberStatsContext(memberId);
+ }
+ } catch (Exception e) {
+ log.error("[scale-down] Cannot move member to termination pending list ", e);
+ }
+ }
+
+ public void delegateTerminateDependency(
+ ClusterLevelPartitionContext clusterMonitorPartitionContext, String memberId) {
+ try {
+ //calling SM to send the instance notification event.
+ if (log.isDebugEnabled()) {
+ log.debug("delegateTerminateDependency:memberId:" + memberId);
+ }
+ //InstanceNotificationClient.getInstance().sendMemberCleanupEvent(memberId);
+ //partitionContext.moveActiveMemberToTerminationPendingMembers(memberId);
+ //CloudControllerClient.getInstance().terminate(memberId);
+ } catch (Exception e) {
+ log.error("Cannot terminate instance", e);
+ }
+ }
+
+ public void terminateObsoleteInstance(String memberId) {
+ try {
+ AutoscalerCloudControllerClient.getInstance().terminateInstance(memberId);
+ } catch (Exception e) {
+ log.error("Cannot terminate instance", e);
+ }
+ }
+
+ //Grouping
+ public void delegateTerminateAll(String clusterId) {
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("delegateTerminateAll - begin");
+ }
+ AutoscalerCloudControllerClient.getInstance().terminateAllInstances(clusterId);
+ if (log.isDebugEnabled()) {
+ log.debug("delegateTerminateAll - done");
+ }
+ } catch (Exception e) {
+ log.error("Cannot terminate instance", e);
+ }
+ }
+
+ public int getPredictedReplicasForStat(int minReplicas, float statUpperLimit,
+ float statPredictedValue) {
+ if (statUpperLimit == 0) {
+ return 0;
+ }
+ float predictedValue = ((minReplicas / statUpperLimit) * statPredictedValue);
+ return (int) Math.ceil(predictedValue);
+ }
+
+ public double getLoadAveragePredictedValue(ClusterInstanceContext clusterInstanceContext) {
+ double loadAveragePredicted = 0.0d;
+ int totalMemberCount = 0;
+ for (ClusterLevelPartitionContext partitionContext : clusterInstanceContext
+ .getPartitionCtxts()) {
+ for (MemberStatsContext memberStatsContext : partitionContext.getMemberStatsContexts()
+ .values()) {
+
+ float memberAverageLoadAverage = memberStatsContext.getLoadAverage().getAverage();
+ float memberGredientLoadAverage = memberStatsContext.getLoadAverage().getGradient();
+ float memberSecondDerivativeLoadAverage =
+ memberStatsContext.getLoadAverage().getSecondDerivative();
+
+ double memberPredictedLoadAverage =
+ getPredictedValueForNextMinute(memberAverageLoadAverage,
+ memberGredientLoadAverage,
+ memberSecondDerivativeLoadAverage, 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("Predicted load average : " + loadAveragePredicted / totalMemberCount);
+ return loadAveragePredicted / totalMemberCount;
+ } else {
+ 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()) {
+
+ float memberMemoryConsumptionAverage =
+ memberStatsContext.getMemoryConsumption().getAverage();
+ float memberMemoryConsumptionGredient =
+ memberStatsContext.getMemoryConsumption().getGradient();
+ float memberMemoryConsumptionSecondDerivative =
+ memberStatsContext.getMemoryConsumption().getSecondDerivative();
+
+ double memberPredictedMemoryConsumption =
+ getPredictedValueForNextMinute(memberMemoryConsumptionAverage,
+ memberMemoryConsumptionGredient,
+ memberMemoryConsumptionSecondDerivative, 1);
+
+ 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("Predicted memory consumption : " +
+ memoryConsumptionPredicted / totalMemberCount);
+ return memoryConsumptionPredicted / totalMemberCount;
+ } else {
+ return 0;
+ }
+ }
}
[14/18] stratos git commit: Formatting the code
Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/218b5fdc/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java
index 64c264a..3c6716c 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceUtil.java
@@ -42,71 +42,71 @@ import java.util.Properties;
*/
public class CloudControllerServiceUtil {
- private static final Log log = LogFactory.getLog(CloudControllerServiceUtil.class);
-
- public static Iaas buildIaas(IaasProvider iaasProvider) throws InvalidIaasProviderException {
- return iaasProvider.getIaas();
- }
-
- /**
- * Update the topology, publish statistics to BAM, remove member context
- * and persist cloud controller context.
- *
- * @param memberContext
- */
- public static void executeMemberTerminationPostProcess(MemberContext memberContext) {
- if (memberContext == null) {
- return;
- }
-
- String partitionId = memberContext.getPartition() == null ? null : memberContext.getPartition().getId();
-
- // Update the topology
- TopologyBuilder.handleMemberTerminated(memberContext.getCartridgeType(), memberContext.getClusterId(),
- memberContext.getNetworkPartitionId(), partitionId,
- memberContext.getMemberId());
-
- Long timeStamp = System.currentTimeMillis();
- // Publish statistics to BAM
- BAMUsageDataPublisher.publish(memberContext.getMemberId(), partitionId, memberContext.getNetworkPartitionId(),
- memberContext.getClusterId(), memberContext.getClusterInstanceId(),
- memberContext.getCartridgeType(), MemberStatus.Terminated.toString(), timeStamp,
- null, null, null);
-
- // Remove member context
- CloudControllerContext.getInstance()
- .removeMemberContext(memberContext.getClusterId(), memberContext.getMemberId());
-
- // Persist cloud controller context
- CloudControllerContext.getInstance().persist();
- }
-
- public static boolean isValidIpAddress(String ip) {
- boolean isValid = InetAddresses.isInetAddress(ip);
- return isValid;
- }
-
- public static IaasProvider validatePartitionAndGetIaasProvider(Partition partition, IaasProvider iaasProvider)
- throws InvalidPartitionException {
- if (iaasProvider != null) {
- // if this is a IaaS based partition
- Iaas iaas = iaasProvider.getIaas();
- PartitionValidator validator = iaas.getPartitionValidator();
- validator.setIaasProvider(iaasProvider);
- Properties partitionProperties = CloudControllerUtil.toJavaUtilProperties(partition.getProperties());
- iaasProvider = validator.validate(partition, partitionProperties);
- return iaasProvider;
-
- } else {
- String msg = "Partition is not valid: [partition-id] " + partition.getId();
- log.error(msg);
- throw new InvalidPartitionException(msg);
- }
- }
-
- public static boolean validatePartition(Partition partition, IaasProvider iaasProvider)
- throws InvalidPartitionException {
- validatePartitionAndGetIaasProvider(partition, iaasProvider);
- return true;
- }
+ private static final Log log = LogFactory.getLog(CloudControllerServiceUtil.class);
+
+ public static Iaas buildIaas(IaasProvider iaasProvider) throws InvalidIaasProviderException {
+ return iaasProvider.getIaas();
+ }
+
+ /**
+ * Update the topology, publish statistics to BAM, remove member context
+ * and persist cloud controller context.
+ *
+ * @param memberContext
+ */
+ public static void executeMemberTerminationPostProcess(MemberContext memberContext) {
+ if (memberContext == null) {
+ return;
+ }
+
+ String partitionId = memberContext.getPartition() == null ? null : memberContext.getPartition().getId();
+
+ // Update the topology
+ TopologyBuilder.handleMemberTerminated(memberContext.getCartridgeType(), memberContext.getClusterId(),
+ memberContext.getNetworkPartitionId(), partitionId,
+ memberContext.getMemberId());
+
+ Long timeStamp = System.currentTimeMillis();
+ // Publish statistics to BAM
+ BAMUsageDataPublisher.publish(memberContext.getMemberId(), partitionId, memberContext.getNetworkPartitionId(),
+ memberContext.getClusterId(), memberContext.getClusterInstanceId(),
+ memberContext.getCartridgeType(), MemberStatus.Terminated.toString(), timeStamp,
+ null, null, null);
+
+ // Remove member context
+ CloudControllerContext.getInstance()
+ .removeMemberContext(memberContext.getClusterId(), memberContext.getMemberId());
+
+ // Persist cloud controller context
+ CloudControllerContext.getInstance().persist();
+ }
+
+ public static boolean isValidIpAddress(String ip) {
+ boolean isValid = InetAddresses.isInetAddress(ip);
+ return isValid;
+ }
+
+ public static IaasProvider validatePartitionAndGetIaasProvider(Partition partition, IaasProvider iaasProvider)
+ throws InvalidPartitionException {
+ if (iaasProvider != null) {
+ // if this is a IaaS based partition
+ Iaas iaas = iaasProvider.getIaas();
+ PartitionValidator validator = iaas.getPartitionValidator();
+ validator.setIaasProvider(iaasProvider);
+ Properties partitionProperties = CloudControllerUtil.toJavaUtilProperties(partition.getProperties());
+ iaasProvider = validator.validate(partition, partitionProperties);
+ return iaasProvider;
+
+ } else {
+ String msg = "Partition is not valid: [partition-id] " + partition.getId();
+ log.error(msg);
+ throw new InvalidPartitionException(msg);
+ }
+ }
+
+ public static boolean validatePartition(Partition partition, IaasProvider iaasProvider)
+ throws InvalidPartitionException {
+ validatePartitionAndGetIaasProvider(partition, iaasProvider);
+ return true;
+ }
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/218b5fdc/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/statistics/publisher/BAMUsageDataPublisher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/statistics/publisher/BAMUsageDataPublisher.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/statistics/publisher/BAMUsageDataPublisher.java
index c69feef..675de25 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/statistics/publisher/BAMUsageDataPublisher.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/statistics/publisher/BAMUsageDataPublisher.java
@@ -46,183 +46,183 @@ import java.util.List;
*/
public class BAMUsageDataPublisher {
- private static final Log log = LogFactory.getLog(BAMUsageDataPublisher.class);
-
- private static AsyncDataPublisher dataPublisher;
- private static StreamDefinition streamDefinition;
- private static final String cloudControllerEventStreamVersion = "1.0.0";
-
- public static void publish(String memberId, String partitionId, String networkId, String clusterId,
- String clusterInstanceId, String serviceName, String status, Long timeStamp,
- String autoscalingReason, Long scalingTime, InstanceMetadata metadata) {
- if (!CloudControllerConfig.getInstance().isBAMDataPublisherEnabled()) {
- return;
- }
- log.debug(CloudControllerConstants.DATA_PUB_TASK_NAME + " cycle started.");
-
- if (dataPublisher == null) {
- createDataPublisher();
-
- //If we cannot create a data publisher we should give up
- //this means data will not be published
- if (dataPublisher == null) {
- log.error("Data Publisher cannot be created or found.");
- release();
- return;
- }
- }
-
- MemberContext memberContext = CloudControllerContext.getInstance().getMemberContextOfMemberId(memberId);
- String cartridgeType = memberContext.getCartridgeType();
- Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType);
- String instanceType =
- CloudControllerContext.getInstance().getIaasProviderOfPartition(cartridgeType, partitionId)
- .getProperty(CloudControllerConstants.INSTANCE_TYPE);
-
- //Construct the data to be published
- List<Object> payload = new ArrayList<Object>();
- // Payload values
- payload.add(timeStamp);
- payload.add(memberId);
- payload.add(serviceName);
- payload.add(clusterId);
- payload.add(clusterInstanceId);
- payload.add(handleNull(memberContext.getLbClusterId()));
- payload.add(handleNull(partitionId));
- payload.add(handleNull(networkId));
- payload.add(handleNull(instanceType));
- payload.add(handleNull(autoscalingReason));
- payload.add(handleNull(scalingTime));
- if (cartridge != null) {
- payload.add(handleNull(String.valueOf(cartridge.isMultiTenant())));
- } else {
- payload.add("");
- }
- payload.add(handleNull(memberContext.getPartition().getProvider()));
- payload.add(handleNull(status));
-
- if (metadata != null) {
- payload.add(metadata.getHostname());
- payload.add(metadata.getHypervisor());
- payload.add(String.valueOf(metadata.getRam()));
- payload.add(metadata.getImageId());
- payload.add(metadata.getLoginPort());
- payload.add(metadata.getOperatingSystemName());
- payload.add(metadata.getOperatingSystemVersion());
- payload.add(metadata.getOperatingSystemArchitecture());
- payload.add(String.valueOf(metadata.isOperatingSystem64bit()));
- } else {
- payload.add("");
- payload.add("");
- payload.add("");
- payload.add("");
- payload.add(0);
- payload.add("");
- payload.add("");
- payload.add("");
- payload.add("");
- }
-
- payload.add(handleNull(Arrays.toString(memberContext.getPrivateIPs())));
- payload.add(handleNull(Arrays.toString(memberContext.getPublicIPs())));
- payload.add(handleNull(Arrays.toString(memberContext.getAllocatedIPs())));
-
- Event event = new Event();
- event.setPayloadData(payload.toArray());
- event.setArbitraryDataMap(new HashMap<String, String>());
-
- try {
- if (log.isDebugEnabled()) {
- log.debug(String.format("Publishing BAM event: [stream] %s [version] %s", streamDefinition.getName(),
- streamDefinition.getVersion()));
- }
- dataPublisher.publish(streamDefinition.getName(), streamDefinition.getVersion(), event);
- } catch (AgentException e) {
- if (log.isErrorEnabled()) {
- log.error(String.format("Could not publish BAM event: [stream] %s [version] %s",
- streamDefinition.getName(), streamDefinition.getVersion()), e);
- }
- }
- }
-
- private static void release() {
- CloudControllerContext.getInstance().setPublisherRunning(false);
- }
-
- private static StreamDefinition initializeStream() throws Exception {
- streamDefinition = new StreamDefinition(CloudControllerConstants.CLOUD_CONTROLLER_EVENT_STREAM,
- cloudControllerEventStreamVersion);
- streamDefinition.setNickName("cloud.controller");
- streamDefinition.setDescription("Instances booted up by the Cloud Controller");
- // Payload definition
- List<Attribute> payloadData = new ArrayList<Attribute>();
- payloadData.add(new Attribute(CloudControllerConstants.TIME_STAMP, AttributeType.LONG));
- payloadData.add(new Attribute(CloudControllerConstants.MEMBER_ID_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.CARTRIDGE_TYPE_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.CLUSTER_ID_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.CLUSTER_INSTANCE_ID_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.LB_CLUSTER_ID_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.PARTITION_ID_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.NETWORK_ID_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.INSTANCE_TYPE, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.SCALING_REASON, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.SCALING_TIME, AttributeType.LONG));
- payloadData.add(new Attribute(CloudControllerConstants.IS_MULTI_TENANT_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.IAAS_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.STATUS_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.HOST_NAME_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.HYPERVISOR_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.RAM_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.IMAGE_ID_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.LOGIN_PORT_COL, AttributeType.INT));
- payloadData.add(new Attribute(CloudControllerConstants.OS_NAME_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.OS_VERSION_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.OS_ARCH_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.OS_BIT_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.PRIV_IP_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.PUB_IP_COL, AttributeType.STRING));
- payloadData.add(new Attribute(CloudControllerConstants.ALLOCATE_IP_COL, AttributeType.STRING));
- streamDefinition.setPayloadData(payloadData);
- return streamDefinition;
- }
-
- private static void createDataPublisher() {
- //creating the agent
-
- ServerConfiguration serverConfig = CarbonUtils.getServerConfiguration();
- String trustStorePath = serverConfig.getFirstProperty("Security.TrustStore.Location");
- String trustStorePassword = serverConfig.getFirstProperty("Security.TrustStore.Password");
- String bamServerUrl = serverConfig.getFirstProperty("BamServerURL");
- String adminUsername = CloudControllerConfig.getInstance().getDataPubConfig().getBamUsername();
- String adminPassword = CloudControllerConfig.getInstance().getDataPubConfig().getBamPassword();
-
- System.setProperty("javax.net.ssl.trustStore", trustStorePath);
- System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
-
- try {
- dataPublisher = new AsyncDataPublisher("tcp://" + bamServerUrl + "", adminUsername, adminPassword);
- CloudControllerContext.getInstance().setDataPublisher(dataPublisher);
- initializeStream();
- dataPublisher.addStreamDefinition(streamDefinition);
- } catch (Exception e) {
- String msg = "Unable to create a data publisher to " + bamServerUrl +
- ". Usage Agent will not function properly. ";
- log.error(msg, e);
- throw new CloudControllerException(msg, e);
- }
- }
-
- private static String handleNull(String val) {
- if (val == null) {
- return "";
- }
- return val;
- }
-
- private static Long handleNull(Long val) {
- if (val == null) {
- return -1L;
- }
- return val;
- }
+ private static final Log log = LogFactory.getLog(BAMUsageDataPublisher.class);
+
+ private static AsyncDataPublisher dataPublisher;
+ private static StreamDefinition streamDefinition;
+ private static final String cloudControllerEventStreamVersion = "1.0.0";
+
+ public static void publish(String memberId, String partitionId, String networkId, String clusterId,
+ String clusterInstanceId, String serviceName, String status, Long timeStamp,
+ String autoscalingReason, Long scalingTime, InstanceMetadata metadata) {
+ if (!CloudControllerConfig.getInstance().isBAMDataPublisherEnabled()) {
+ return;
+ }
+ log.debug(CloudControllerConstants.DATA_PUB_TASK_NAME + " cycle started.");
+
+ if (dataPublisher == null) {
+ createDataPublisher();
+
+ //If we cannot create a data publisher we should give up
+ //this means data will not be published
+ if (dataPublisher == null) {
+ log.error("Data Publisher cannot be created or found.");
+ release();
+ return;
+ }
+ }
+
+ MemberContext memberContext = CloudControllerContext.getInstance().getMemberContextOfMemberId(memberId);
+ String cartridgeType = memberContext.getCartridgeType();
+ Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType);
+ String instanceType =
+ CloudControllerContext.getInstance().getIaasProviderOfPartition(cartridgeType, partitionId)
+ .getProperty(CloudControllerConstants.INSTANCE_TYPE);
+
+ //Construct the data to be published
+ List<Object> payload = new ArrayList<Object>();
+ // Payload values
+ payload.add(timeStamp);
+ payload.add(memberId);
+ payload.add(serviceName);
+ payload.add(clusterId);
+ payload.add(clusterInstanceId);
+ payload.add(handleNull(memberContext.getLbClusterId()));
+ payload.add(handleNull(partitionId));
+ payload.add(handleNull(networkId));
+ payload.add(handleNull(instanceType));
+ payload.add(handleNull(autoscalingReason));
+ payload.add(handleNull(scalingTime));
+ if (cartridge != null) {
+ payload.add(handleNull(String.valueOf(cartridge.isMultiTenant())));
+ } else {
+ payload.add("");
+ }
+ payload.add(handleNull(memberContext.getPartition().getProvider()));
+ payload.add(handleNull(status));
+
+ if (metadata != null) {
+ payload.add(metadata.getHostname());
+ payload.add(metadata.getHypervisor());
+ payload.add(String.valueOf(metadata.getRam()));
+ payload.add(metadata.getImageId());
+ payload.add(metadata.getLoginPort());
+ payload.add(metadata.getOperatingSystemName());
+ payload.add(metadata.getOperatingSystemVersion());
+ payload.add(metadata.getOperatingSystemArchitecture());
+ payload.add(String.valueOf(metadata.isOperatingSystem64bit()));
+ } else {
+ payload.add("");
+ payload.add("");
+ payload.add("");
+ payload.add("");
+ payload.add(0);
+ payload.add("");
+ payload.add("");
+ payload.add("");
+ payload.add("");
+ }
+
+ payload.add(handleNull(Arrays.toString(memberContext.getPrivateIPs())));
+ payload.add(handleNull(Arrays.toString(memberContext.getPublicIPs())));
+ payload.add(handleNull(Arrays.toString(memberContext.getAllocatedIPs())));
+
+ Event event = new Event();
+ event.setPayloadData(payload.toArray());
+ event.setArbitraryDataMap(new HashMap<String, String>());
+
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Publishing BAM event: [stream] %s [version] %s", streamDefinition.getName(),
+ streamDefinition.getVersion()));
+ }
+ dataPublisher.publish(streamDefinition.getName(), streamDefinition.getVersion(), event);
+ } catch (AgentException e) {
+ if (log.isErrorEnabled()) {
+ log.error(String.format("Could not publish BAM event: [stream] %s [version] %s",
+ streamDefinition.getName(), streamDefinition.getVersion()), e);
+ }
+ }
+ }
+
+ private static void release() {
+ CloudControllerContext.getInstance().setPublisherRunning(false);
+ }
+
+ private static StreamDefinition initializeStream() throws Exception {
+ streamDefinition = new StreamDefinition(CloudControllerConstants.CLOUD_CONTROLLER_EVENT_STREAM,
+ cloudControllerEventStreamVersion);
+ streamDefinition.setNickName("cloud.controller");
+ streamDefinition.setDescription("Instances booted up by the Cloud Controller");
+ // Payload definition
+ List<Attribute> payloadData = new ArrayList<Attribute>();
+ payloadData.add(new Attribute(CloudControllerConstants.TIME_STAMP, AttributeType.LONG));
+ payloadData.add(new Attribute(CloudControllerConstants.MEMBER_ID_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.CARTRIDGE_TYPE_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.CLUSTER_ID_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.CLUSTER_INSTANCE_ID_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.LB_CLUSTER_ID_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.PARTITION_ID_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.NETWORK_ID_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.INSTANCE_TYPE, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.SCALING_REASON, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.SCALING_TIME, AttributeType.LONG));
+ payloadData.add(new Attribute(CloudControllerConstants.IS_MULTI_TENANT_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.IAAS_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.STATUS_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.HOST_NAME_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.HYPERVISOR_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.RAM_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.IMAGE_ID_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.LOGIN_PORT_COL, AttributeType.INT));
+ payloadData.add(new Attribute(CloudControllerConstants.OS_NAME_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.OS_VERSION_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.OS_ARCH_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.OS_BIT_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.PRIV_IP_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.PUB_IP_COL, AttributeType.STRING));
+ payloadData.add(new Attribute(CloudControllerConstants.ALLOCATE_IP_COL, AttributeType.STRING));
+ streamDefinition.setPayloadData(payloadData);
+ return streamDefinition;
+ }
+
+ private static void createDataPublisher() {
+ //creating the agent
+
+ ServerConfiguration serverConfig = CarbonUtils.getServerConfiguration();
+ String trustStorePath = serverConfig.getFirstProperty("Security.TrustStore.Location");
+ String trustStorePassword = serverConfig.getFirstProperty("Security.TrustStore.Password");
+ String bamServerUrl = serverConfig.getFirstProperty("BamServerURL");
+ String adminUsername = CloudControllerConfig.getInstance().getDataPubConfig().getBamUsername();
+ String adminPassword = CloudControllerConfig.getInstance().getDataPubConfig().getBamPassword();
+
+ System.setProperty("javax.net.ssl.trustStore", trustStorePath);
+ System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
+
+ try {
+ dataPublisher = new AsyncDataPublisher("tcp://" + bamServerUrl + "", adminUsername, adminPassword);
+ CloudControllerContext.getInstance().setDataPublisher(dataPublisher);
+ initializeStream();
+ dataPublisher.addStreamDefinition(streamDefinition);
+ } catch (Exception e) {
+ String msg = "Unable to create a data publisher to " + bamServerUrl +
+ ". Usage Agent will not function properly. ";
+ log.error(msg, e);
+ throw new CloudControllerException(msg, e);
+ }
+ }
+
+ private static String handleNull(String val) {
+ if (val == null) {
+ return "";
+ }
+ return val;
+ }
+
+ private static Long handleNull(Long val) {
+ if (val == null) {
+ return -1L;
+ }
+ return val;
+ }
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/218b5fdc/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java
index 9cf2007..669a96a 100644
--- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java
+++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java
@@ -20,190 +20,190 @@ package org.apache.stratos.common.constants;
public class StratosConstants {
- public static final String CLOUD_SERVICE_IS_ACTIVE_PROP_KEY = "active";
-
- public static final String CLOUD_SERVICE_INFO_STORE_PATH =
- "/repository/components/org.apache.stratos/cloud-manager/cloud-services";
-
- public static final String TENANT_USER_VALIDATION_STORE_PATH = "/repository/components/org.wso2.carbon.validations";
- public static final String ADMIN_EMAIL_VERIFICATION_FLAG_PATH =
- "/repository/components/org.wso2.carbon.email-confirmation-flag";
- public static final String TENANT_DOMAIN_VERIFICATION_FLAG_PATH =
- "/repository/components/org.wso2.carbon.domain-confirmation-flag";
-
- public static final String DOMAIN_VALIDATOR_INFO_PATH =
- "/repository/components/org.wso2.carbon.domain-validator-info";
-
- public static final String TENANT_CREATION_THEME_PAGE_TOKEN =
- "/repository/components/org.wso2.carbon.theme-page-token";
-
- public static final String TENANT_PACKAGE_INFO_PATH = "/repository/components/org.wso2.carbon.package-info";
-
- public static final String ALL_THEMES_PATH = "/repository/components/org.wso2.carbon.all-themes";
-
- public static final String THROTTLING_RULES_PATH = "/repository/components/org.wso2.carbon.throttling-rules";
-
- public static final String ORIGINATED_SERVICE_PATH = "/repository/components/org.wso2.carbon.originated-service";
-
- public static final String PATH_SEPARATOR = "/";
-
- public static final String CLOUD_SERVICE_ICONS_STORE_PATH =
- "/repository/components/org.wso2.carbon.cloud-manager/" + "cloud-services-icons";
-
- public static final String VALIDATION_KEY_RESOURCE_NAME = "validation-key";
- public static final String INCOMING_PATH_DIR = "incoming";
- public static final String OUTGOING_PATH_DIR = "outgoing";
- public static final String MULTITENANCY_SCHEDULED_TASK_ID = "multitenancyScheduledTask";
- public static final String MULTITENANCY_VIEWING_TASK_ID = "multitenancyViewingTask";
-
- public static final String INVALID_TENANT = "invalidTenant";
- public static final String INACTIVE_TENANT = "inactiveTenant";
- public static final String ACTIVE_TENANT = "activeTenant";
- public static final String IS_EMAIL_VALIDATED = "isEmailValidated";
- public static final String IS_CREDENTIALS_ALREADY_RESET = "isCredentialsReset";
- public static final String TENANT_ADMIN = "tenantAdminUsername";
-
- public static final String CLOUD_MANAGER_SERVICE = "Apache Stratos Controller";
- public static final String CLOUD_IDENTITY_SERVICE = "WSO2 Stratos Identity";
- public static final String CLOUD_GOVERNANCE_SERVICE = "WSO2 Stratos Governance";
- public static final String CLOUD_ESB_SERVICE = "WSO2 Stratos Enterprise Service Bus";
-
- // keystore mgt related Constants
- public static final String TENANT_KS = "/repository/security/key-stores/";
- public static final String TENANT_PUB_KEY = "/repository/security/pub-key";
- public static final String PROP_TENANT_KS_TYPE = "key-store-type";
- public static final String PROP_TENANT_KS_PASSWD = "key-store-password";
- public static final String PROP_TENANT_KS_PRIV_KEY_PASSWD = "priv-key-password";
- public static final String PROP_TENANT_KS_ALIAS = "alias";
-
- // constants related to redirection
-
- public static final String UNVERIFIED_ACCOUNT_DOMAIN_SUFFIX = "-unverified";
- public static final String TENANT_SPECIFIC_URL_RESOLVED = "tenant-sepcific-url-resolved";
- public static final String SUFFIXED_UNVERIFIED_SESSION_FLAG = "temp-suffixed-unverified";
-
- // metering constants
- public static final String THROTTLING_ALL_ACTION = "all_actions";
- public static final String THROTTLING_IN_DATA_ACTION = "in_data_action";
- //this covers registry capacity + registry bandwidth
- public static final String THROTTLING_OUT_DATA_ACTION = "out_data_action"; //this covers registry bandwidth
- public static final String THROTTLING_ADD_USER_ACTION = "add_user_action";
- public static final String THROTTLING_SERVICE_IN_BANDWIDTH_ACTION = "service_in_bandwith_action";
- public static final String THROTTLING_SERVICE_OUT_BANDWIDTH_ACTION = "service_out_bandwith_action";
- public static final String THROTTLING_WEBAPP_IN_BANDWIDTH_ACTION = "webapp_in_bandwith_action";
- public static final String THROTTLING_WEBAPP_OUT_BANDWIDTH_ACTION = "webapp_out_bandwith_action";
- public static final String THROTTLING_SERVICE_REQUEST_ACTION = "service_request_action";
- public static final String THROTTLING_SERVICE_RESPONSE_ACTION = "service_response_action";
-
- // the session attribute to keep track whether the registry action validated
- // and the usage persisted
- public static final String REGISTRY_ACTION_VALIDATED_SESSION_ATTR = "registryActionValidated";
- public static final String REGISTRY_USAGE_PERSISTED_SESSION_ATTR = "usagePersited";
-
- // Metering servlet attributes
- public static final String SERVICE_NAME_SERVLET_ATTR = "meteringServiceName";
- public static final String TENANT_ID_SERVLET_ATTR = "tenantId";
- public static final String ADMIN_SERVICE_SERVLET_ATTR = "adminService";
-
- // * as a Service impl related constants
- public static final String ORIGINATED_SERVICE = "originatedService";
-
- // Configuration file name
- public static final String STRATOS_CONF_FILE = "stratos.xml";
- //public static final String STRATOS_CONF_LOC = "repository/conf/";
- //public static final String STRATOS_CONF_FILE_WITH_PATH = STRATOS_CONF_LOC + STRATOS_CONF_FILE;
-
- // EULA location
- public static final String STRATOS_EULA = "eula.xml";
-
- // EULA default text.
- public static final String STRATOS_EULA_DEFAULT_TEXT =
- "Please refer to: " + StratosConstants.STRATOS_TERMS_OF_USAGE +
- " for terms and usage and " + StratosConstants.STRATOS_PRIVACY_POLICY +
- " for privacy policy of WSO2 Stratos.";
-
- // Web location of Terms of Usage and privacy policy
- public static final String STRATOS_TERMS_OF_USAGE = "http://wso2.com/cloud/services/terms-of-use/";
- public static final String STRATOS_PRIVACY_POLICY = "http://wso2.com/cloud/services/privacy-policy/";
- public static final String MULTITENANCY_FREE_PLAN = "Demo";
- public static final String MULTITENANCY_SMALL_PLAN = "SMB";
- public static final String MULTITENANCY_MEDIUM_PLAN = "Professional";
- public static final String MULTITENANCY_LARGE_PLAN = "Enterprise";
- public static final String EMAIL_CONFIG = "email";
- public static final String MULTITENANCY_CONFIG_FOLDER = "multitenancy";
-
- // Cloud controller - payload
- public static final String MEMBER_ID = "MEMBER_ID";
- public static final String LB_CLUSTER_ID = "LB_CLUSTER_ID";
- public static final String NETWORK_PARTITION_ID = "NETWORK_PARTITION_ID";
-
- // Kubernetes related constants
- public static final String KUBERNETES_CLUSTER_ID = "KUBERNETES_CLUSTER_ID";
- public static final String KUBERNETES_MASTER_PORT = "KUBERNETES_MASTER_PORT";
- public static final String KUBERNETES_MASTER_DEFAULT_PORT = "8080";
-
- //drools related constants
- public static final String DROOLS_DIR_NAME = "drools";
- public static final String SCALE_CHECK_DROOL_FILE = "scaling.drl";
- public static final String DEPENDENT_SCALE_CHECK_DROOL_FILE = "dependent-scaling.drl";
- public static final String MIN_CHECK_DROOL_FILE = "mincheck.drl";
- public static final String MAX_CHECK_DROOL_FILE = "maxcheck.drl";
- public static final String OBSOLETE_CHECK_DROOL_FILE = "obsoletecheck.drl";
- public static final String MIN_COUNT = "MIN_COUNT";
- public static final String SCALING_REASON = "SCALING_REASON";
- public static final String SCALING_TIME = "SCALING_TIME";
-
- // Policy and definition related constants
- public static final int PUBLIC_DEFINITION = 0;
-
- // member expiry timeout constants
- public static final String PENDING_MEMBER_EXPIRY_TIMEOUT = "autoscaler.member.pendingMemberExpiryTimeout";
- public static final String OBSOLETED_MEMBER_EXPIRY_TIMEOUT = "autoscaler.member.obsoletedMemberExpiryTimeout";
- public static final String PENDING_TERMINATION_MEMBER_EXPIRY_TIMEOUT =
- "autoscaler.member.pendingTerminationMemberExpiryTimeout";
-
- public static final String FILTER_VALUE_SEPARATOR = ",";
- public static final String TOPOLOGY_APPLICATION_FILTER = "stratos.topology.application.filter";
- public static final String TOPOLOGY_SERVICE_FILTER = "stratos.topology.service.filter";
- public static final String TOPOLOGY_CLUSTER_FILTER = "stratos.topology.cluster.filter";
- public static final String TOPOLOGY_MEMBER_FILTER = "stratos.topology.member.filter";
- public static final String TOPOLOGY_NETWORK_PARTITION_FILTER = "stratos.topology.network.partition.filter";
-
- // to identify a lb cluster
- public static final String LOAD_BALANCER_REF = "load.balancer.ref";
- public static final String SERVICE_AWARE_LOAD_BALANCER = "service.aware.load.balancer";
- public static final String DEFAULT_LOAD_BALANCER = "default.load.balancer";
- public static final String NO_LOAD_BALANCER = "no.load.balancer";
- public static final String EXISTING_LOAD_BALANCERS = "existing.load.balancers";
-
- public static final long HAZELCAST_INSTANCE_INIT_TIMEOUT = 300000; // 5 min
-
- public static final String AUTOSCALER_SERVICE_URL = "autoscaler.service.url";
- public static final String CLOUD_CONTROLLER_SERVICE_URL = "cloud.controller.service.url";
- public static final String STRATOS_MANAGER_SERVICE_URL = "stratos.manager.service.url";
-
- public static final String CLOUD_CONTROLLER_CLIENT_SOCKET_TIMEOUT = "cc.socket.timeout";
- public static final String CLOUD_CONTROLLER_CLIENT_CONNECTION_TIMEOUT = "cc.connection.timeout";
- public static final String AUTOSCALER_CLIENT_SOCKET_TIMEOUT = "autoscaler.socket.timeout";
- public static final String AUTOSCALER_CLIENT_CONNECTION_TIMEOUT = "autoscaler.connection.timeout";
- public static final String STRATOS_MANAGER_CLIENT_SOCKET_TIMEOUT = "stratos.manager.socket.timeout";
- public static final String STRATOS_MANAGER_CLIENT_CONNECTION_TIMEOUT = "stratos.manager.connection.timeout";
-
- public static final String DEFAULT_CLIENT_SOCKET_TIMEOUT = "300000";
- public static final String DEFAULT_CLIENT_CONNECTION_TIMEOUT = "300000";
-
- // partition algorithm id constants
- public static final String PARTITION_ROUND_ROBIN_ALGORITHM_ID = "round-robin";
- public static final String PARTITION_WEIGHTED_ROUND_ROBIN_ALGORITHM_ID = "weighted-round-robin";
- public static final String PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID = "one-after-another";
- // network partition algorithm id constants
- public static final String NETWORK_PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID = "one-after-another";
- public static final String NETWORK_PARTITION_ALL_AT_ONCE_ALGORITHM_ID = "all-at-once";
- public static final String APPLICATION_POLICY_NETWORK_PARTITION_GROUPS = "networkPartitionGroups";
- public static final String APPLICATION_POLICY_NETWORK_PARTITIONS_SPLITTER = "\\|";
- public static final String APPLICATION_POLICY_NETWORK_PARTITION_GROUPS_SPLITTER = ",";
-
- public static final String NOT_DEFINED = "not-defined";
- public static final String CLUSTER_INSTANCE_ID = "cluster.instance.id";
+ public static final String CLOUD_SERVICE_IS_ACTIVE_PROP_KEY = "active";
+
+ public static final String CLOUD_SERVICE_INFO_STORE_PATH =
+ "/repository/components/org.apache.stratos/cloud-manager/cloud-services";
+
+ public static final String TENANT_USER_VALIDATION_STORE_PATH = "/repository/components/org.wso2.carbon.validations";
+ public static final String ADMIN_EMAIL_VERIFICATION_FLAG_PATH =
+ "/repository/components/org.wso2.carbon.email-confirmation-flag";
+ public static final String TENANT_DOMAIN_VERIFICATION_FLAG_PATH =
+ "/repository/components/org.wso2.carbon.domain-confirmation-flag";
+
+ public static final String DOMAIN_VALIDATOR_INFO_PATH =
+ "/repository/components/org.wso2.carbon.domain-validator-info";
+
+ public static final String TENANT_CREATION_THEME_PAGE_TOKEN =
+ "/repository/components/org.wso2.carbon.theme-page-token";
+
+ public static final String TENANT_PACKAGE_INFO_PATH = "/repository/components/org.wso2.carbon.package-info";
+
+ public static final String ALL_THEMES_PATH = "/repository/components/org.wso2.carbon.all-themes";
+
+ public static final String THROTTLING_RULES_PATH = "/repository/components/org.wso2.carbon.throttling-rules";
+
+ public static final String ORIGINATED_SERVICE_PATH = "/repository/components/org.wso2.carbon.originated-service";
+
+ public static final String PATH_SEPARATOR = "/";
+
+ public static final String CLOUD_SERVICE_ICONS_STORE_PATH =
+ "/repository/components/org.wso2.carbon.cloud-manager/" + "cloud-services-icons";
+
+ public static final String VALIDATION_KEY_RESOURCE_NAME = "validation-key";
+ public static final String INCOMING_PATH_DIR = "incoming";
+ public static final String OUTGOING_PATH_DIR = "outgoing";
+ public static final String MULTITENANCY_SCHEDULED_TASK_ID = "multitenancyScheduledTask";
+ public static final String MULTITENANCY_VIEWING_TASK_ID = "multitenancyViewingTask";
+
+ public static final String INVALID_TENANT = "invalidTenant";
+ public static final String INACTIVE_TENANT = "inactiveTenant";
+ public static final String ACTIVE_TENANT = "activeTenant";
+ public static final String IS_EMAIL_VALIDATED = "isEmailValidated";
+ public static final String IS_CREDENTIALS_ALREADY_RESET = "isCredentialsReset";
+ public static final String TENANT_ADMIN = "tenantAdminUsername";
+
+ public static final String CLOUD_MANAGER_SERVICE = "Apache Stratos Controller";
+ public static final String CLOUD_IDENTITY_SERVICE = "WSO2 Stratos Identity";
+ public static final String CLOUD_GOVERNANCE_SERVICE = "WSO2 Stratos Governance";
+ public static final String CLOUD_ESB_SERVICE = "WSO2 Stratos Enterprise Service Bus";
+
+ // keystore mgt related Constants
+ public static final String TENANT_KS = "/repository/security/key-stores/";
+ public static final String TENANT_PUB_KEY = "/repository/security/pub-key";
+ public static final String PROP_TENANT_KS_TYPE = "key-store-type";
+ public static final String PROP_TENANT_KS_PASSWD = "key-store-password";
+ public static final String PROP_TENANT_KS_PRIV_KEY_PASSWD = "priv-key-password";
+ public static final String PROP_TENANT_KS_ALIAS = "alias";
+
+ // constants related to redirection
+
+ public static final String UNVERIFIED_ACCOUNT_DOMAIN_SUFFIX = "-unverified";
+ public static final String TENANT_SPECIFIC_URL_RESOLVED = "tenant-sepcific-url-resolved";
+ public static final String SUFFIXED_UNVERIFIED_SESSION_FLAG = "temp-suffixed-unverified";
+
+ // metering constants
+ public static final String THROTTLING_ALL_ACTION = "all_actions";
+ public static final String THROTTLING_IN_DATA_ACTION = "in_data_action";
+ //this covers registry capacity + registry bandwidth
+ public static final String THROTTLING_OUT_DATA_ACTION = "out_data_action"; //this covers registry bandwidth
+ public static final String THROTTLING_ADD_USER_ACTION = "add_user_action";
+ public static final String THROTTLING_SERVICE_IN_BANDWIDTH_ACTION = "service_in_bandwith_action";
+ public static final String THROTTLING_SERVICE_OUT_BANDWIDTH_ACTION = "service_out_bandwith_action";
+ public static final String THROTTLING_WEBAPP_IN_BANDWIDTH_ACTION = "webapp_in_bandwith_action";
+ public static final String THROTTLING_WEBAPP_OUT_BANDWIDTH_ACTION = "webapp_out_bandwith_action";
+ public static final String THROTTLING_SERVICE_REQUEST_ACTION = "service_request_action";
+ public static final String THROTTLING_SERVICE_RESPONSE_ACTION = "service_response_action";
+
+ // the session attribute to keep track whether the registry action validated
+ // and the usage persisted
+ public static final String REGISTRY_ACTION_VALIDATED_SESSION_ATTR = "registryActionValidated";
+ public static final String REGISTRY_USAGE_PERSISTED_SESSION_ATTR = "usagePersited";
+
+ // Metering servlet attributes
+ public static final String SERVICE_NAME_SERVLET_ATTR = "meteringServiceName";
+ public static final String TENANT_ID_SERVLET_ATTR = "tenantId";
+ public static final String ADMIN_SERVICE_SERVLET_ATTR = "adminService";
+
+ // * as a Service impl related constants
+ public static final String ORIGINATED_SERVICE = "originatedService";
+
+ // Configuration file name
+ public static final String STRATOS_CONF_FILE = "stratos.xml";
+ //public static final String STRATOS_CONF_LOC = "repository/conf/";
+ //public static final String STRATOS_CONF_FILE_WITH_PATH = STRATOS_CONF_LOC + STRATOS_CONF_FILE;
+
+ // EULA location
+ public static final String STRATOS_EULA = "eula.xml";
+
+ // EULA default text.
+ public static final String STRATOS_EULA_DEFAULT_TEXT =
+ "Please refer to: " + StratosConstants.STRATOS_TERMS_OF_USAGE +
+ " for terms and usage and " + StratosConstants.STRATOS_PRIVACY_POLICY +
+ " for privacy policy of WSO2 Stratos.";
+
+ // Web location of Terms of Usage and privacy policy
+ public static final String STRATOS_TERMS_OF_USAGE = "http://wso2.com/cloud/services/terms-of-use/";
+ public static final String STRATOS_PRIVACY_POLICY = "http://wso2.com/cloud/services/privacy-policy/";
+ public static final String MULTITENANCY_FREE_PLAN = "Demo";
+ public static final String MULTITENANCY_SMALL_PLAN = "SMB";
+ public static final String MULTITENANCY_MEDIUM_PLAN = "Professional";
+ public static final String MULTITENANCY_LARGE_PLAN = "Enterprise";
+ public static final String EMAIL_CONFIG = "email";
+ public static final String MULTITENANCY_CONFIG_FOLDER = "multitenancy";
+
+ // Cloud controller - payload
+ public static final String MEMBER_ID = "MEMBER_ID";
+ public static final String LB_CLUSTER_ID = "LB_CLUSTER_ID";
+ public static final String NETWORK_PARTITION_ID = "NETWORK_PARTITION_ID";
+
+ // Kubernetes related constants
+ public static final String KUBERNETES_CLUSTER_ID = "KUBERNETES_CLUSTER_ID";
+ public static final String KUBERNETES_MASTER_PORT = "KUBERNETES_MASTER_PORT";
+ public static final String KUBERNETES_MASTER_DEFAULT_PORT = "8080";
+
+ //drools related constants
+ public static final String DROOLS_DIR_NAME = "drools";
+ public static final String SCALE_CHECK_DROOL_FILE = "scaling.drl";
+ public static final String DEPENDENT_SCALE_CHECK_DROOL_FILE = "dependent-scaling.drl";
+ public static final String MIN_CHECK_DROOL_FILE = "mincheck.drl";
+ public static final String MAX_CHECK_DROOL_FILE = "maxcheck.drl";
+ public static final String OBSOLETE_CHECK_DROOL_FILE = "obsoletecheck.drl";
+ public static final String MIN_COUNT = "MIN_COUNT";
+ public static final String SCALING_REASON = "SCALING_REASON";
+ public static final String SCALING_TIME = "SCALING_TIME";
+
+ // Policy and definition related constants
+ public static final int PUBLIC_DEFINITION = 0;
+
+ // member expiry timeout constants
+ public static final String PENDING_MEMBER_EXPIRY_TIMEOUT = "autoscaler.member.pendingMemberExpiryTimeout";
+ public static final String OBSOLETED_MEMBER_EXPIRY_TIMEOUT = "autoscaler.member.obsoletedMemberExpiryTimeout";
+ public static final String PENDING_TERMINATION_MEMBER_EXPIRY_TIMEOUT =
+ "autoscaler.member.pendingTerminationMemberExpiryTimeout";
+
+ public static final String FILTER_VALUE_SEPARATOR = ",";
+ public static final String TOPOLOGY_APPLICATION_FILTER = "stratos.topology.application.filter";
+ public static final String TOPOLOGY_SERVICE_FILTER = "stratos.topology.service.filter";
+ public static final String TOPOLOGY_CLUSTER_FILTER = "stratos.topology.cluster.filter";
+ public static final String TOPOLOGY_MEMBER_FILTER = "stratos.topology.member.filter";
+ public static final String TOPOLOGY_NETWORK_PARTITION_FILTER = "stratos.topology.network.partition.filter";
+
+ // to identify a lb cluster
+ public static final String LOAD_BALANCER_REF = "load.balancer.ref";
+ public static final String SERVICE_AWARE_LOAD_BALANCER = "service.aware.load.balancer";
+ public static final String DEFAULT_LOAD_BALANCER = "default.load.balancer";
+ public static final String NO_LOAD_BALANCER = "no.load.balancer";
+ public static final String EXISTING_LOAD_BALANCERS = "existing.load.balancers";
+
+ public static final long HAZELCAST_INSTANCE_INIT_TIMEOUT = 300000; // 5 min
+
+ public static final String AUTOSCALER_SERVICE_URL = "autoscaler.service.url";
+ public static final String CLOUD_CONTROLLER_SERVICE_URL = "cloud.controller.service.url";
+ public static final String STRATOS_MANAGER_SERVICE_URL = "stratos.manager.service.url";
+
+ public static final String CLOUD_CONTROLLER_CLIENT_SOCKET_TIMEOUT = "cc.socket.timeout";
+ public static final String CLOUD_CONTROLLER_CLIENT_CONNECTION_TIMEOUT = "cc.connection.timeout";
+ public static final String AUTOSCALER_CLIENT_SOCKET_TIMEOUT = "autoscaler.socket.timeout";
+ public static final String AUTOSCALER_CLIENT_CONNECTION_TIMEOUT = "autoscaler.connection.timeout";
+ public static final String STRATOS_MANAGER_CLIENT_SOCKET_TIMEOUT = "stratos.manager.socket.timeout";
+ public static final String STRATOS_MANAGER_CLIENT_CONNECTION_TIMEOUT = "stratos.manager.connection.timeout";
+
+ public static final String DEFAULT_CLIENT_SOCKET_TIMEOUT = "300000";
+ public static final String DEFAULT_CLIENT_CONNECTION_TIMEOUT = "300000";
+
+ // partition algorithm id constants
+ public static final String PARTITION_ROUND_ROBIN_ALGORITHM_ID = "round-robin";
+ public static final String PARTITION_WEIGHTED_ROUND_ROBIN_ALGORITHM_ID = "weighted-round-robin";
+ public static final String PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID = "one-after-another";
+ // network partition algorithm id constants
+ public static final String NETWORK_PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID = "one-after-another";
+ public static final String NETWORK_PARTITION_ALL_AT_ONCE_ALGORITHM_ID = "all-at-once";
+ public static final String APPLICATION_POLICY_NETWORK_PARTITION_GROUPS = "networkPartitionGroups";
+ public static final String APPLICATION_POLICY_NETWORK_PARTITIONS_SPLITTER = "\\|";
+ public static final String APPLICATION_POLICY_NETWORK_PARTITION_GROUPS_SPLITTER = ",";
+
+ public static final String NOT_DEFINED = "not-defined";
+ public static final String CLUSTER_INSTANCE_ID = "cluster.instance.id";
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/218b5fdc/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/healthstatspublisher/healthstats.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/healthstatspublisher/healthstats.py b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/healthstatspublisher/healthstats.py
index 711fe43..855f732 100644
--- a/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/healthstatspublisher/healthstats.py
+++ b/components/org.apache.stratos.python.cartridge.agent/src/main/python/cartridge.agent/cartridge.agent/modules/healthstatspublisher/healthstats.py
@@ -162,7 +162,7 @@ class HealthStatisticsPublisher:
"""
event = ThriftEvent()
- #Sevent.payloadData.append(int(round(time.time() * 1000)))
+ #event.payloadData.append(int(round(time.time() * 1000)))
event.payloadData.append(self.cartridge_agent_config.cluster_id)
event.payloadData.append(self.cartridge_agent_config.cluster_instance_id)
event.payloadData.append(self.cartridge_agent_config.network_partition_id)
http://git-wip-us.apache.org/repos/asf/stratos/blob/218b5fdc/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl
----------------------------------------------------------------------
diff --git a/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl b/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl
index ca532de..167711f 100644
--- a/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl
+++ b/products/stratos/modules/distribution/src/main/conf/drools/scaling.drl
@@ -165,9 +165,6 @@ dialect "mvel"
int count = 0;
String autoscalingReason = (numberOfRequiredInstances == numberOfInstancesReuquiredBasedOnRif)?"Scaling up due to RIF":(numberOfRequiredInstances== numberOfInstancesReuquiredBasedOnMemoryConsumption)?"Scaling up due to MC":"Scaling up due to LA";
- String autoscalingReason = (numberOfRequiredInstances == numberOfInstancesReuquiredBasedOnRif)?"Scaling up due to RIF":(numberOfRequiredInstances== numberOfInstancesReuquiredBasedOnMemoryConsumption)?"Scaling up due to MC":"Scaling up due to LA";
-
-
while(count != additionalInstances && partitionsAvailable){
ClusterLevelPartitionContext partitionContext = (ClusterLevelPartitionContext) partitionAlgorithm.getNextScaleUpPartitionContext(clusterInstanceContext.getPartitionCtxtsAsAnArray());
[07/18] stratos git commit: Publishing events for Metering Service
Implementation
Posted by im...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/76c7724b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java
----------------------------------------------------------------------
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 f04a11f..dba9670 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
@@ -31,6 +31,7 @@ import org.apache.stratos.cloud.controller.messaging.publisher.TopologyEventPubl
import org.apache.stratos.cloud.controller.statistics.publisher.BAMUsageDataPublisher;
import org.apache.stratos.cloud.controller.util.CloudControllerUtil;
import org.apache.stratos.common.Property;
+import org.apache.stratos.common.constants.StratosConstants;
import org.apache.stratos.messaging.domain.application.ClusterDataHolder;
import org.apache.stratos.messaging.domain.instance.ClusterInstance;
import org.apache.stratos.messaging.domain.topology.*;
@@ -51,1015 +52,994 @@ import java.util.*;
* and build the complete topology with the events received
*/
public class TopologyBuilder {
- private static final Log log = LogFactory.getLog(TopologyBuilder.class);
-
-
- public static void handleServiceCreated(List<Cartridge> cartridgeList) {
- Service service;
- Topology topology = TopologyManager.getTopology();
- if (cartridgeList == null) {
- log.warn(String.format("Cartridge list is empty"));
- return;
- }
-
- try {
-
- TopologyManager.acquireWriteLock();
- for (Cartridge cartridge : cartridgeList) {
- if (!topology.serviceExists(cartridge.getType())) {
- ServiceType serviceType = cartridge.isMultiTenant() ? ServiceType.MultiTenant : ServiceType.SingleTenant;
- service = new Service(cartridge.getType(), serviceType);
- Properties properties = new Properties();
-
- try {
- Property[] propertyArray = null;
-
- if (cartridge.getProperties() != null) {
- if (cartridge.getProperties().getProperties() != null) {
- propertyArray = cartridge.getProperties().getProperties();
- }
- }
-
- List<Property> propertyList = new ArrayList<Property>();
- if (propertyArray != null) {
- propertyList = Arrays.asList(propertyArray);
- if (propertyList != null) {
- for (Property property : propertyList) {
- properties.setProperty(property.getName(), property.getValue());
- }
- }
- }
- } catch (Exception e) {
- log.error(e);
- }
-
- service.setProperties(properties);
- if (cartridge.getPortMappings() != null) {
- List<PortMapping> portMappings = Arrays.asList(cartridge.getPortMappings());
- Port port;
- //adding ports to the event
- for (PortMapping portMapping : portMappings) {
- port = new Port(portMapping.getProtocol(),
- portMapping.getPort(), portMapping.getProxyPort());
- service.addPort(port);
- }
- }
-
- topology.addService(service);
- TopologyManager.updateTopology(topology);
- }
- }
- } finally {
- TopologyManager.releaseWriteLock();
- }
- TopologyEventPublisher.sendServiceCreateEvent(cartridgeList);
- }
-
- public static void handleServiceRemoved(List<Cartridge> cartridgeList) {
- Topology topology = TopologyManager.getTopology();
-
- for (Cartridge cartridge : cartridgeList) {
- Service service = topology.getService(cartridge.getType());
- if (service == null) {
- log.warn("Cartridge does not exist [cartidge] " + cartridge);
- return;
- }
- if (service.getClusters().size() == 0) {
- if (topology.serviceExists(cartridge.getType())) {
- try {
- TopologyManager.acquireWriteLock();
- topology.removeService(cartridge.getType());
- TopologyManager.updateTopology(topology);
- } finally {
- TopologyManager.releaseWriteLock();
- }
- TopologyEventPublisher.sendServiceRemovedEvent(cartridgeList);
- } else {
- log.warn(String.format("Service %s does not exist..", cartridge.getType()));
- }
- } else {
- log.warn("Subscription already exists. Hence not removing the service:" + cartridge.getType()
- + " from the topology");
- }
- }
- }
-
- public static void handleClusterCreated(ClusterStatusClusterCreatedEvent event) {
- TopologyManager.acquireWriteLock();
- Cluster cluster;
-
- try {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(event.getServiceName());
- if (service == null) {
- log.error("Service " + event.getServiceName() +
- " not found in Topology, unable to update the cluster status to Created");
- return;
- }
-
- if (service.clusterExists(event.getClusterId())) {
- log.warn("Cluster " + event.getClusterId() + " is already in the Topology ");
- return;
- } else {
- cluster = new Cluster(event.getServiceName(),
- event.getClusterId(), event.getDeploymentPolicyName(),
- event.getAutosScalePolicyName(), event.getAppId());
- //cluster.setStatus(Status.Created);
- cluster.setHostNames(event.getHostNames());
- cluster.setTenantRange(event.getTenantRange());
- service.addCluster(cluster);
- TopologyManager.updateTopology(topology);
- }
- } finally {
- TopologyManager.releaseWriteLock();
- }
-
- TopologyEventPublisher.sendClusterCreatedEvent(cluster);
- }
-
- public static void handleApplicationClustersCreated(String appId, List<Cluster> appClusters) {
-
- TopologyManager.acquireWriteLock();
-
- try {
- Topology topology = TopologyManager.getTopology();
- for (Cluster cluster : appClusters) {
- Service service = topology.getService(cluster.getServiceName());
- if (service == null) {
- log.error("Service " + cluster.getServiceName()
- + " not found in Topology, unable to create Application cluster");
- } else {
- service.addCluster(cluster);
- log.info("Application Cluster " + cluster.getClusterId() + " created in CC topology");
- }
- }
- TopologyManager.updateTopology(topology);
- } finally {
- TopologyManager.releaseWriteLock();
- }
-
- log.debug("Creating cluster port mappings: [appication-id] " + appId);
- for(Cluster cluster : appClusters) {
- String cartridgeType = cluster.getServiceName();
- Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType);
- if(cartridge == null) {
- throw new CloudControllerException("Cartridge not found: [cartridge-type] " + cartridgeType);
- }
-
- for(PortMapping portMapping : cartridge.getPortMappings()) {
- ClusterPortMapping clusterPortMapping = new ClusterPortMapping(appId,
- cluster.getClusterId(), portMapping.getName(), portMapping.getProtocol(), portMapping.getPort(),
- portMapping.getProxyPort());
- CloudControllerContext.getInstance().addClusterPortMapping(clusterPortMapping);
- log.debug("Cluster port mapping created: " + clusterPortMapping.toString());
- }
- }
-
- // Persist cluster port mappings
- CloudControllerContext.getInstance().persist();
-
- // Send application clusters created event
- TopologyEventPublisher.sendApplicationClustersCreated(appId, appClusters);
- }
-
- public static void handleApplicationClustersRemoved(String appId,
- Set<ClusterDataHolder> clusterData) {
- TopologyManager.acquireWriteLock();
-
- List<Cluster> removedClusters = new ArrayList<Cluster>();
- CloudControllerContext context = CloudControllerContext.getInstance();
- try {
- Topology topology = TopologyManager.getTopology();
-
- if (clusterData != null) {
- // remove clusters from CC topology model and remove runtime information
- for (ClusterDataHolder aClusterData : clusterData) {
- Service aService = topology.getService(aClusterData.getServiceType());
- if (aService != null) {
- removedClusters.add(aService.removeCluster(aClusterData.getClusterId()));
- } else {
- log.warn("Service " + aClusterData.getServiceType() + " not found, " +
- "unable to remove Cluster " + aClusterData.getClusterId());
- }
- // remove runtime data
- context.removeClusterContext(aClusterData.getClusterId());
-
- log.info("Removed application [ " + appId + " ]'s Cluster " +
- "[ " + aClusterData.getClusterId() + " ] from the topology");
- }
- // persist runtime data changes
- CloudControllerContext.getInstance().persist();
- } else {
- log.info("No cluster data found for application " + appId + " to remove");
- }
-
- TopologyManager.updateTopology(topology);
-
- } finally {
- TopologyManager.releaseWriteLock();
- }
-
- // Remove cluster port mappings of application
- CloudControllerContext.getInstance().removeClusterPortMappings(appId);
- CloudControllerContext.getInstance().persist();
-
- TopologyEventPublisher.sendApplicationClustersRemoved(appId, clusterData);
-
- }
-
- public static void handleClusterReset(ClusterStatusClusterResetEvent event) {
- TopologyManager.acquireWriteLock();
-
- try {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(event.getServiceName());
- if (service == null) {
- log.error("Service " + event.getServiceName() +
- " not found in Topology, unable to update the cluster status to Created");
- return;
- }
-
- Cluster cluster = service.getCluster(event.getClusterId());
- if (cluster == null) {
- log.error("Cluster " + event.getClusterId() + " not found in Topology, unable to update " +
- "status to Created");
- return;
- }
-
- ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
- if (context == null) {
- log.warn("Cluster Instance Context is not found for [cluster] " +
- event.getClusterId() + " [instance-id] " +
- event.getInstanceId());
- return;
- }
- ClusterStatus status = ClusterStatus.Created;
- if (context.isStateTransitionValid(status)) {
- context.setStatus(status);
- log.info("Cluster Created adding status started for" + cluster.getClusterId());
- TopologyManager.updateTopology(topology);
- //publishing data
- TopologyEventPublisher.sendClusterResetEvent(event.getAppId(), event.getServiceName(),
- event.getClusterId(), event.getInstanceId());
- } else {
- log.warn(String.format("Cluster state transition is not valid: [cluster-id] %s " +
- " [instance-id] %s [current-status] %s [status-requested] %s",
- event.getClusterId(), event.getInstanceId(),
- context.getStatus(), status));
- }
-
- } finally {
- TopologyManager.releaseWriteLock();
- }
-
-
- }
-
- public static void handleClusterInstanceCreated(String serviceType, String clusterId,
- String alias, String instanceId, String partitionId,
- String networkPartitionId) {
-
- TopologyManager.acquireWriteLock();
-
- try {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(serviceType);
- if (service == null) {
- log.error("Service " + serviceType +
- " not found in Topology, unable to update the cluster status to Created");
- return;
- }
-
- Cluster cluster = service.getCluster(clusterId);
- if (cluster == null) {
- log.error("Cluster " + clusterId + " not found in Topology, unable to update " +
- "status to Created");
- return;
- }
-
- if (cluster.getInstanceContexts(instanceId) != null) {
- log.warn("The Instance context for the cluster already exists for [cluster] " +
- clusterId + " [instance-id] " + instanceId);
- return;
- }
-
- ClusterInstance clusterInstance = new ClusterInstance(alias, clusterId, instanceId);
- clusterInstance.setNetworkPartitionId(networkPartitionId);
- clusterInstance.setPartitionId(partitionId);
- cluster.addInstanceContext(instanceId, clusterInstance);
- TopologyManager.updateTopology(topology);
-
- ClusterInstanceCreatedEvent clusterInstanceCreatedEvent =
- new ClusterInstanceCreatedEvent(serviceType, clusterId,
- clusterInstance);
- clusterInstanceCreatedEvent.setPartitionId(partitionId);
- TopologyEventPublisher.sendClusterInstanceCreatedEvent(clusterInstanceCreatedEvent);
-
- } finally {
- TopologyManager.releaseWriteLock();
- }
- }
-
-
- public static void handleClusterRemoved(ClusterContext ctxt) {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(ctxt.getCartridgeType());
- String deploymentPolicy;
- if (service == null) {
- log.warn(String.format("Service %s does not exist",
- ctxt.getCartridgeType()));
- return;
- }
-
- if (!service.clusterExists(ctxt.getClusterId())) {
- log.warn(String.format("Cluster %s does not exist for service %s",
- ctxt.getClusterId(),
- ctxt.getCartridgeType()));
- return;
- }
-
- try {
- TopologyManager.acquireWriteLock();
- Cluster cluster = service.removeCluster(ctxt.getClusterId());
- deploymentPolicy = cluster.getDeploymentPolicyName();
- TopologyManager.updateTopology(topology);
- } finally {
- TopologyManager.releaseWriteLock();
- }
- TopologyEventPublisher.sendClusterRemovedEvent(ctxt, deploymentPolicy);
- }
-
- /**
- * Add member object to the topology and publish member created event
- *
- * @param memberContext
- */
- public static void handleMemberCreatedEvent(MemberContext memberContext) {
- Topology topology = TopologyManager.getTopology();
-
- Service service = topology.getService(memberContext.getCartridgeType());
- String clusterId = memberContext.getClusterId();
- Cluster cluster = service.getCluster(clusterId);
- String memberId = memberContext.getMemberId();
- String clusterInstanceId = memberContext.getClusterInstanceId();
- String networkPartitionId = memberContext.getNetworkPartitionId();
- String partitionId = memberContext.getPartition().getId();
- String lbClusterId = memberContext.getLbClusterId();
- long initTime = memberContext.getInitTime();
-
- if (cluster.memberExists(memberId)) {
- log.warn(String.format("Member %s already exists", memberId));
- return;
- }
-
- try {
- TopologyManager.acquireWriteLock();
- Member member = new Member(service.getServiceName(), clusterId, memberId, clusterInstanceId,
- networkPartitionId, partitionId, memberContext.getLoadBalancingIPType(), initTime);
- member.setStatus(MemberStatus.Created);
- member.setLbClusterId(lbClusterId);
- member.setProperties(CloudControllerUtil.toJavaUtilProperties(memberContext.getProperties()));
- cluster.addMember(member);
- TopologyManager.updateTopology(topology);
- } finally {
- TopologyManager.releaseWriteLock();
- }
-
- TopologyEventPublisher.sendMemberCreatedEvent(memberContext);
- }
-
- /**
- * Update member status to initialized and publish member initialized event
- *
- * @param memberContext
- */
- public static void handleMemberInitializedEvent(MemberContext memberContext) {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(memberContext.getCartridgeType());
- if (service == null) {
- log.warn(String.format("Service %s does not exist",
- memberContext.getCartridgeType()));
- return;
- }
- if (!service.clusterExists(memberContext.getClusterId())) {
- log.warn(String.format("Cluster %s does not exist in service %s",
- memberContext.getClusterId(),
- memberContext.getCartridgeType()));
- return;
- }
-
- Member member = service.getCluster(memberContext.getClusterId()).
- getMember(memberContext.getMemberId());
- if (member == null) {
- log.warn(String.format("Member %s does not exist",
- memberContext.getMemberId()));
- return;
- }
-
- try {
- TopologyManager.acquireWriteLock();
-
- // Set ip addresses
- member.setDefaultPrivateIP(memberContext.getDefaultPrivateIP());
- if (memberContext.getPrivateIPs() != null) {
- member.setMemberPrivateIPs(Arrays.asList(memberContext.getPrivateIPs()));
- }
- member.setDefaultPublicIP(memberContext.getDefaultPublicIP());
- if (memberContext.getPublicIPs() != null) {
- member.setMemberPublicIPs(Arrays.asList(memberContext.getPublicIPs()));
- }
-
- // try update lifecycle state
- if (!member.isStateTransitionValid(MemberStatus.Initialized)) {
- log.error("Invalid state transition from " + member.getStatus() + " to " +
- MemberStatus.Initialized);
- return;
- } else {
- member.setStatus(MemberStatus.Initialized);
- log.info("Member status updated to initialized");
-
- TopologyManager.updateTopology(topology);
-
- TopologyEventPublisher.sendMemberInitializedEvent(memberContext);
- //publishing data
- BAMUsageDataPublisher.publish(memberContext.getMemberId(),
- memberContext.getPartition().getId(),
- memberContext.getNetworkPartitionId(),
- memberContext.getClusterId(),
- memberContext.getCartridgeType(),
- MemberStatus.Initialized.toString(),
- null);
- }
- } finally {
- TopologyManager.releaseWriteLock();
- }
- }
-
- private static int findKubernetesServicePort(String clusterId, List<KubernetesService> kubernetesServices,
- PortMapping portMapping) {
- for (KubernetesService kubernetesService : kubernetesServices) {
- if (kubernetesService.getProtocol().equals(portMapping.getProtocol())) {
- return kubernetesService.getPort();
- }
- }
- throw new RuntimeException("Kubernetes service port not found: [cluster-id] " + clusterId + " [port] "
- + portMapping.getPort());
- }
-
- public static void handleMemberStarted(InstanceStartedEvent instanceStartedEvent) {
- try {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(instanceStartedEvent.getServiceName());
- if (service == null) {
- log.warn(String.format("Service %s does not exist",
- instanceStartedEvent.getServiceName()));
- return;
- }
- if (!service.clusterExists(instanceStartedEvent.getClusterId())) {
- log.warn(String.format("Cluster %s does not exist in service %s",
- instanceStartedEvent.getClusterId(),
- instanceStartedEvent.getServiceName()));
- return;
- }
-
- Cluster cluster = service.getCluster(instanceStartedEvent.getClusterId());
- Member member = cluster.getMember(instanceStartedEvent.getMemberId());
- if (member == null) {
- log.warn(String.format("Member %s does not exist",
- instanceStartedEvent.getMemberId()));
- return;
- }
-
- try {
- TopologyManager.acquireWriteLock();
- // try update lifecycle state
- if (!member.isStateTransitionValid(MemberStatus.Starting)) {
- log.error("Invalid State Transition from " + member.getStatus() + " to " +
- MemberStatus.Starting);
- return;
- } else {
- member.setStatus(MemberStatus.Starting);
- log.info("member started event adding status started");
-
- TopologyManager.updateTopology(topology);
- //memberStartedEvent.
- TopologyEventPublisher.sendMemberStartedEvent(instanceStartedEvent);
- //publishing data
- BAMUsageDataPublisher.publish(instanceStartedEvent.getMemberId(),
- instanceStartedEvent.getPartitionId(),
- instanceStartedEvent.getNetworkPartitionId(),
- instanceStartedEvent.getClusterId(),
- instanceStartedEvent.getServiceName(),
- MemberStatus.Starting.toString(),
- null);
- }
- } finally {
- TopologyManager.releaseWriteLock();
- }
- } catch (Exception e) {
- String message = String.format("Could not handle member started event: [application-id] %s " +
- "[service-name] %s [member-id] %s", instanceStartedEvent.getApplicationId(),
- instanceStartedEvent.getServiceName(), instanceStartedEvent.getMemberId());
- log.warn(message, e);
- }
- }
-
- public static void handleMemberActivated(InstanceActivatedEvent instanceActivatedEvent) {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(instanceActivatedEvent.getServiceName());
- if (service == null) {
- log.warn(String.format("Service %s does not exist",
- instanceActivatedEvent.getServiceName()));
- return;
- }
-
- Cluster cluster = service.getCluster(instanceActivatedEvent.getClusterId());
- if (cluster == null) {
- log.warn(String.format("Cluster %s does not exist",
- instanceActivatedEvent.getClusterId()));
- return;
- }
-
- Member member = cluster.getMember(instanceActivatedEvent.getMemberId());
- if (member == null) {
- log.warn(String.format("Member %s does not exist",
- instanceActivatedEvent.getMemberId()));
- return;
- }
-
- MemberActivatedEvent memberActivatedEvent = new MemberActivatedEvent(
- instanceActivatedEvent.getServiceName(),
- instanceActivatedEvent.getClusterId(),
- instanceActivatedEvent.getClusterInstanceId(),
- instanceActivatedEvent.getMemberId(),
- instanceActivatedEvent.getNetworkPartitionId(),
- instanceActivatedEvent.getPartitionId());
-
- // grouping - set grouid
- //TODO
- memberActivatedEvent.setApplicationId(null);
- try {
- TopologyManager.acquireWriteLock();
- // try update lifecycle state
- if (!member.isStateTransitionValid(MemberStatus.Active)) {
- log.error("Invalid state transition from [" + member.getStatus() + "] to [" + MemberStatus.Active + "]");
- return;
- } else {
- member.setStatus(MemberStatus.Active);
-
- // Set member ports
- try {
- Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(service.getServiceName());
- if (cartridge == null) {
- throw new RuntimeException(String.format("Cartridge not found: [cartridge-type] %s",
- service.getServiceName()));
- }
-
- Port port;
- int portValue;
- List<PortMapping> portMappings = Arrays.asList(cartridge.getPortMappings());
- String clusterId = cluster.getClusterId();
- ClusterContext clusterContext = CloudControllerContext.getInstance().getClusterContext(clusterId);
- List<KubernetesService> kubernetesServices = clusterContext.getKubernetesServices();
-
- for (PortMapping portMapping : portMappings) {
- if (kubernetesServices != null) {
- portValue = findKubernetesServicePort(clusterId, kubernetesServices, portMapping);
- } else {
- portValue = portMapping.getPort();
- }
- port = new Port(portMapping.getProtocol(), portValue, portMapping.getProxyPort());
- member.addPort(port);
- memberActivatedEvent.addPort(port);
- }
- } catch (Exception e) {
- String message = String.format("Could not add member ports: [service-name] %s [member-id] %s",
- memberActivatedEvent.getServiceName(), memberActivatedEvent.getMemberId());
- log.error(message, e);
- }
-
- // Set member ip addresses
- memberActivatedEvent.setDefaultPrivateIP(member.getDefaultPrivateIP());
- memberActivatedEvent.setMemberPrivateIPs(member.getMemberPrivateIPs());
- memberActivatedEvent.setDefaultPublicIP(member.getDefaultPublicIP());
- memberActivatedEvent.setMemberPublicIPs(member.getMemberPublicIPs());
- TopologyManager.updateTopology(topology);
-
- // Publish member activated event
- TopologyEventPublisher.sendMemberActivatedEvent(memberActivatedEvent);
-
- // Publish statistics data
- BAMUsageDataPublisher.publish(memberActivatedEvent.getMemberId(),
- memberActivatedEvent.getPartitionId(),
- memberActivatedEvent.getNetworkPartitionId(),
- memberActivatedEvent.getClusterId(),
- memberActivatedEvent.getServiceName(),
- MemberStatus.Active.toString(),
- null);
- }
- } finally {
- TopologyManager.releaseWriteLock();
- }
- }
-
- public static void handleMemberReadyToShutdown(InstanceReadyToShutdownEvent instanceReadyToShutdownEvent)
- throws InvalidMemberException, InvalidCartridgeTypeException {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(instanceReadyToShutdownEvent.getServiceName());
- //update the status of the member
- if (service == null) {
- log.warn(String.format("Service %s does not exist",
- instanceReadyToShutdownEvent.getServiceName()));
- return;
- }
-
- Cluster cluster = service.getCluster(instanceReadyToShutdownEvent.getClusterId());
- if (cluster == null) {
- log.warn(String.format("Cluster %s does not exist",
- instanceReadyToShutdownEvent.getClusterId()));
- return;
- }
-
-
- Member member = cluster.getMember(instanceReadyToShutdownEvent.getMemberId());
- if (member == null) {
- log.warn(String.format("Member %s does not exist",
- instanceReadyToShutdownEvent.getMemberId()));
- return;
- }
- MemberReadyToShutdownEvent memberReadyToShutdownEvent = new MemberReadyToShutdownEvent(
- instanceReadyToShutdownEvent.getServiceName(),
- instanceReadyToShutdownEvent.getClusterId(),
- instanceReadyToShutdownEvent.getClusterInstanceId(),
- instanceReadyToShutdownEvent.getMemberId(),
- instanceReadyToShutdownEvent.getNetworkPartitionId(),
- instanceReadyToShutdownEvent.getPartitionId());
- try {
- TopologyManager.acquireWriteLock();
-
- if (!member.isStateTransitionValid(MemberStatus.ReadyToShutDown)) {
- log.error("Invalid State Transition from " + member.getStatus() + " to " +
- MemberStatus.ReadyToShutDown);
- return;
- }
- member.setStatus(MemberStatus.ReadyToShutDown);
- log.info("Member Ready to shut down event adding status started");
-
- TopologyManager.updateTopology(topology);
- } finally {
- TopologyManager.releaseWriteLock();
- }
- TopologyEventPublisher.sendMemberReadyToShutdownEvent(memberReadyToShutdownEvent);
- //publishing data
- BAMUsageDataPublisher.publish(instanceReadyToShutdownEvent.getMemberId(),
- instanceReadyToShutdownEvent.getPartitionId(),
- instanceReadyToShutdownEvent.getNetworkPartitionId(),
- instanceReadyToShutdownEvent.getClusterId(),
- instanceReadyToShutdownEvent.getServiceName(),
- MemberStatus.ReadyToShutDown.toString(),
- null);
- //termination of particular instance will be handled by autoscaler
- }
-
- public static void handleMemberMaintenance(InstanceMaintenanceModeEvent instanceMaintenanceModeEvent)
- throws InvalidMemberException, InvalidCartridgeTypeException {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(instanceMaintenanceModeEvent.getServiceName());
- //update the status of the member
- if (service == null) {
- log.warn(String.format("Service %s does not exist",
- instanceMaintenanceModeEvent.getServiceName()));
- return;
- }
-
- Cluster cluster = service.getCluster(instanceMaintenanceModeEvent.getClusterId());
- if (cluster == null) {
- log.warn(String.format("Cluster %s does not exist",
- instanceMaintenanceModeEvent.getClusterId()));
- return;
- }
-
- Member member = cluster.getMember(instanceMaintenanceModeEvent.getMemberId());
- if (member == null) {
- log.warn(String.format("Member %s does not exist",
- instanceMaintenanceModeEvent.getMemberId()));
- return;
- }
-
-
- MemberMaintenanceModeEvent memberMaintenanceModeEvent = new MemberMaintenanceModeEvent(
- instanceMaintenanceModeEvent.getServiceName(),
- instanceMaintenanceModeEvent.getClusterId(),
- instanceMaintenanceModeEvent.getClusterInstanceId(),
- instanceMaintenanceModeEvent.getMemberId(),
- instanceMaintenanceModeEvent.getNetworkPartitionId(),
- instanceMaintenanceModeEvent.getPartitionId());
- try {
- TopologyManager.acquireWriteLock();
- // try update lifecycle state
- if (!member.isStateTransitionValid(MemberStatus.In_Maintenance)) {
- log.error("Invalid State Transition from " + member.getStatus() + " to "
- + MemberStatus.In_Maintenance);
- return;
- }
- member.setStatus(MemberStatus.In_Maintenance);
- log.info("member maintenance mode event adding status started");
-
- TopologyManager.updateTopology(topology);
- } finally {
- TopologyManager.releaseWriteLock();
- }
- //publishing data
- TopologyEventPublisher.sendMemberMaintenanceModeEvent(memberMaintenanceModeEvent);
-
- }
-
- /**
- * Remove member from topology and send member terminated event.
- *
- * @param serviceName
- * @param clusterId
- * @param networkPartitionId
- * @param partitionId
- * @param memberId
- */
- public static void handleMemberTerminated(String serviceName, String clusterId,
- String networkPartitionId, String partitionId,
- String memberId) {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(serviceName);
- Properties properties;
- if (service == null) {
- log.warn(String.format("Service %s does not exist",
- serviceName));
- return;
- }
- Cluster cluster = service.getCluster(clusterId);
- if (cluster == null) {
- log.warn(String.format("Cluster %s does not exist",
- clusterId));
- return;
- }
-
- Member member = cluster.getMember(memberId);
- if (member == null) {
- log.warn(String.format("Member %s does not exist",
- memberId));
- return;
- }
-
- String clusterInstanceId = member.getClusterInstanceId();
-
- try {
- TopologyManager.acquireWriteLock();
- properties = member.getProperties();
- cluster.removeMember(member);
- TopologyManager.updateTopology(topology);
- } finally {
- TopologyManager.releaseWriteLock();
- }
- /* @TODO leftover from grouping_poc*/
- String groupAlias = null;
- TopologyEventPublisher.sendMemberTerminatedEvent(serviceName, clusterId, memberId,
- clusterInstanceId, networkPartitionId,
- partitionId, properties, groupAlias);
- }
-
- public static void handleMemberSuspended() {
- //TODO
- try {
- TopologyManager.acquireWriteLock();
- } finally {
- TopologyManager.releaseWriteLock();
- }
- }
-
- public static void handleClusterActivatedEvent(ClusterStatusClusterActivatedEvent clusterStatusClusterActivatedEvent) {
-
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(clusterStatusClusterActivatedEvent.getServiceName());
- //update the status of the cluster
- if (service == null) {
- log.warn(String.format("Service %s does not exist",
- clusterStatusClusterActivatedEvent.getServiceName()));
- return;
- }
-
- Cluster cluster = service.getCluster(clusterStatusClusterActivatedEvent.getClusterId());
- if (cluster == null) {
- log.warn(String.format("Cluster %s does not exist",
- clusterStatusClusterActivatedEvent.getClusterId()));
- return;
- }
-
- String clusterId = cluster.getClusterId();
- ClusterContext clusterContext = CloudControllerContext.getInstance().getClusterContext(clusterId);
- if (clusterContext == null) {
- log.warn("Cluster context not found: [cluster-id] " + clusterId);
- return;
- }
-
- ClusterInstanceActivatedEvent clusterInstanceActivatedEvent =
- new ClusterInstanceActivatedEvent(
- clusterStatusClusterActivatedEvent.getAppId(),
- clusterStatusClusterActivatedEvent.getServiceName(),
- clusterStatusClusterActivatedEvent.getClusterId(),
- clusterStatusClusterActivatedEvent.getInstanceId());
- try {
- TopologyManager.acquireWriteLock();
- List<KubernetesService> kubernetesServices = clusterContext.getKubernetesServices();
- cluster.setKubernetesServices(kubernetesServices);
- clusterInstanceActivatedEvent.setKubernetesServices(kubernetesServices);
-
- ClusterInstance context = cluster.getInstanceContexts(clusterStatusClusterActivatedEvent.getInstanceId());
- if (context == null) {
- log.warn("Cluster instance context is not found for [cluster] " +
- clusterStatusClusterActivatedEvent.getClusterId() + " [instance-id] " +
- clusterStatusClusterActivatedEvent.getInstanceId());
- return;
- }
- ClusterStatus status = ClusterStatus.Active;
- if (context.isStateTransitionValid(status)) {
- context.setStatus(status);
- log.info("Cluster activated adding status started for " + cluster.getClusterId());
- TopologyManager.updateTopology(topology);
- // publish event
- TopologyEventPublisher.sendClusterActivatedEvent(clusterInstanceActivatedEvent);
- } else {
- log.error(String.format("Cluster state transition is not valid: [cluster-id] %s " +
- " [instance-id] %s [current-status] %s [status-requested] %s",
- clusterStatusClusterActivatedEvent.getClusterId(), clusterStatusClusterActivatedEvent.getInstanceId(),
- context.getStatus(), status));
- return;
- }
- } finally {
- TopologyManager.releaseWriteLock();
- }
-
- }
-
- public static void handleClusterInactivateEvent(
- ClusterStatusClusterInactivateEvent clusterInactivateEvent) {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(clusterInactivateEvent.getServiceName());
- //update the status of the cluster
- if (service == null) {
- log.warn(String.format("Service %s does not exist",
- clusterInactivateEvent.getServiceName()));
- return;
- }
-
- Cluster cluster = service.getCluster(clusterInactivateEvent.getClusterId());
- if (cluster == null) {
- log.warn(String.format("Cluster %s does not exist",
- clusterInactivateEvent.getClusterId()));
- return;
- }
-
- ClusterInstanceInactivateEvent clusterInactivatedEvent1 =
- new ClusterInstanceInactivateEvent(
- clusterInactivateEvent.getAppId(),
- clusterInactivateEvent.getServiceName(),
- clusterInactivateEvent.getClusterId(),
- clusterInactivateEvent.getInstanceId());
- try {
- TopologyManager.acquireWriteLock();
- ClusterInstance context = cluster.getInstanceContexts(clusterInactivateEvent.getInstanceId());
- if (context == null) {
- log.warn("Cluster Instance Context is not found for [cluster] " +
- clusterInactivateEvent.getClusterId() + " [instance-id] " +
- clusterInactivateEvent.getInstanceId());
- return;
- }
- ClusterStatus status = ClusterStatus.Inactive;
- if (context.isStateTransitionValid(status)) {
- context.setStatus(status);
- log.info("Cluster Inactive adding status started for" + cluster.getClusterId());
- TopologyManager.updateTopology(topology);
- //publishing data
- TopologyEventPublisher.sendClusterInactivateEvent(clusterInactivatedEvent1);
- } else {
- log.error(String.format("Cluster state transition is not valid: [cluster-id] %s " +
- " [instance-id] %s [current-status] %s [status-requested] %s",
- clusterInactivateEvent.getClusterId(), clusterInactivateEvent.getInstanceId(),
- context.getStatus(), status));
- return;
- }
- } finally {
- TopologyManager.releaseWriteLock();
- }
- }
-
-
- private static void deleteAppResourcesFromMetadataService(ApplicationInstanceTerminatedEvent event) {
- try {
- MetaDataServiceClient metadataClient = new DefaultMetaDataServiceClient();
- metadataClient.deleteApplicationProperties(event.getAppId());
- } catch (Exception e) {
- log.error("Error occurred while deleting the application resources frm metadata service ", e);
- }
- }
-
- public static void handleClusterTerminatedEvent(ClusterStatusClusterTerminatedEvent event) {
-
- TopologyManager.acquireWriteLock();
-
- try {
- Topology topology = TopologyManager.getTopology();
- Service service = topology.getService(event.getServiceName());
-
- //update the status of the cluster
- if (service == null) {
- log.warn(String.format("Service %s does not exist",
- event.getServiceName()));
- return;
- }
-
- Cluster cluster = service.getCluster(event.getClusterId());
- if (cluster == null) {
- log.warn(String.format("Cluster %s does not exist",
- event.getClusterId()));
- return;
- }
-
- ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
- if (context == null) {
- log.warn("Cluster Instance Context is not found for [cluster] " +
- event.getClusterId() + " [instance-id] " +
- event.getInstanceId());
- return;
- }
- ClusterStatus status = ClusterStatus.Terminated;
- if (context.isStateTransitionValid(status)) {
- context.setStatus(status);
- log.info("Cluster Terminated adding status started for and removing the cluster instance"
- + cluster.getClusterId());
- cluster.removeInstanceContext(event.getInstanceId());
- TopologyManager.updateTopology(topology);
- //publishing data
- ClusterInstanceTerminatedEvent clusterTerminatedEvent = new ClusterInstanceTerminatedEvent(event.getAppId(),
- event.getServiceName(), event.getClusterId(), event.getInstanceId());
-
- TopologyEventPublisher.sendClusterTerminatedEvent(clusterTerminatedEvent);
- } else {
- log.error(String.format("Cluster state transition is not valid: [cluster-id] %s " +
- " [instance-id] %s [current-status] %s [status-requested] %s",
- event.getClusterId(), event.getInstanceId(),
- context.getStatus(), status));
- return;
- }
- } finally {
- TopologyManager.releaseWriteLock();
- }
-
-
- }
-
- public static void handleClusterTerminatingEvent(ClusterStatusClusterTerminatingEvent event) {
-
- TopologyManager.acquireWriteLock();
-
- try {
- Topology topology = TopologyManager.getTopology();
- Cluster cluster = topology.getService(event.getServiceName()).
- getCluster(event.getClusterId());
-
- if (!cluster.isStateTransitionValid(ClusterStatus.Terminating, event.getInstanceId())) {
- log.error("Invalid state transfer from " + cluster.getStatus(event.getInstanceId()) + " to " +
- ClusterStatus.Terminating);
- }
- ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
- if (context == null) {
- log.warn("Cluster Instance Context is not found for [cluster] " +
- event.getClusterId() + " [instance-id] " +
- event.getInstanceId());
- return;
- }
- ClusterStatus status = ClusterStatus.Terminating;
- if (context.isStateTransitionValid(status)) {
- context.setStatus(status);
- log.info("Cluster Terminating started for " + cluster.getClusterId());
- TopologyManager.updateTopology(topology);
- //publishing data
- ClusterInstanceTerminatingEvent clusterTerminaingEvent = new ClusterInstanceTerminatingEvent(event.getAppId(),
- event.getServiceName(), event.getClusterId(), event.getInstanceId());
-
- TopologyEventPublisher.sendClusterTerminatingEvent(clusterTerminaingEvent);
-
- // Remove kubernetes services if available
- ClusterContext clusterContext =
- CloudControllerContext.getInstance().getClusterContext(event.getClusterId());
- if(StringUtils.isNotBlank(clusterContext.getKubernetesClusterId())) {
- KubernetesIaas.removeKubernetesServices(event.getAppId(), event.getClusterId());
- }
- } else {
- log.error(String.format("Cluster state transition is not valid: [cluster-id] %s " +
- " [instance-id] %s [current-status] %s [status-requested] %s",
- event.getClusterId(), event.getInstanceId(),
- context.getStatus(), status));
- }
- } finally {
- TopologyManager.releaseWriteLock();
- }
- }
+ private static final Log log = LogFactory.getLog(TopologyBuilder.class);
+
+ public static void handleServiceCreated(List<Cartridge> cartridgeList) {
+ Service service;
+ Topology topology = TopologyManager.getTopology();
+ if (cartridgeList == null) {
+ log.warn(String.format("Cartridge list is empty"));
+ return;
+ }
+
+ try {
+
+ TopologyManager.acquireWriteLock();
+ for (Cartridge cartridge : cartridgeList) {
+ if (!topology.serviceExists(cartridge.getType())) {
+ ServiceType serviceType =
+ cartridge.isMultiTenant() ? ServiceType.MultiTenant : ServiceType.SingleTenant;
+ service = new Service(cartridge.getType(), serviceType);
+ Properties properties = new Properties();
+
+ try {
+ Property[] propertyArray = null;
+
+ if (cartridge.getProperties() != null) {
+ if (cartridge.getProperties().getProperties() != null) {
+ propertyArray = cartridge.getProperties().getProperties();
+ }
+ }
+
+ List<Property> propertyList = new ArrayList<Property>();
+ if (propertyArray != null) {
+ propertyList = Arrays.asList(propertyArray);
+ if (propertyList != null) {
+ for (Property property : propertyList) {
+ properties.setProperty(property.getName(), property.getValue());
+ }
+ }
+ }
+ } catch (Exception e) {
+ log.error(e);
+ }
+
+ service.setProperties(properties);
+ if (cartridge.getPortMappings() != null) {
+ List<PortMapping> portMappings = Arrays.asList(cartridge.getPortMappings());
+ Port port;
+ //adding ports to the event
+ for (PortMapping portMapping : portMappings) {
+ port = new Port(portMapping.getProtocol(), portMapping.getPort(),
+ portMapping.getProxyPort());
+ service.addPort(port);
+ }
+ }
+
+ topology.addService(service);
+ TopologyManager.updateTopology(topology);
+ }
+ }
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ TopologyEventPublisher.sendServiceCreateEvent(cartridgeList);
+ }
+
+ public static void handleServiceRemoved(List<Cartridge> cartridgeList) {
+ Topology topology = TopologyManager.getTopology();
+
+ for (Cartridge cartridge : cartridgeList) {
+ Service service = topology.getService(cartridge.getType());
+ if (service == null) {
+ log.warn("Cartridge does not exist [cartidge] " + cartridge);
+ return;
+ }
+ if (service.getClusters().size() == 0) {
+ if (topology.serviceExists(cartridge.getType())) {
+ try {
+ TopologyManager.acquireWriteLock();
+ topology.removeService(cartridge.getType());
+ TopologyManager.updateTopology(topology);
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ TopologyEventPublisher.sendServiceRemovedEvent(cartridgeList);
+ } else {
+ log.warn(String.format("Service %s does not exist..", cartridge.getType()));
+ }
+ } else {
+ log.warn("Subscription already exists. Hence not removing the service:" + cartridge.getType() +
+ " from the topology");
+ }
+ }
+ }
+
+ public static void handleClusterCreated(ClusterStatusClusterCreatedEvent event) {
+ TopologyManager.acquireWriteLock();
+ Cluster cluster;
+
+ try {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(event.getServiceName());
+ if (service == null) {
+ log.error("Service " + event.getServiceName() +
+ " not found in Topology, unable to update the cluster status to Created");
+ return;
+ }
+
+ if (service.clusterExists(event.getClusterId())) {
+ log.warn("Cluster " + event.getClusterId() + " is already in the Topology ");
+ return;
+ } else {
+ cluster = new Cluster(event.getServiceName(), event.getClusterId(), event.getDeploymentPolicyName(),
+ event.getAutosScalePolicyName(), event.getAppId());
+ //cluster.setStatus(Status.Created);
+ cluster.setHostNames(event.getHostNames());
+ cluster.setTenantRange(event.getTenantRange());
+ service.addCluster(cluster);
+ TopologyManager.updateTopology(topology);
+ }
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+
+ TopologyEventPublisher.sendClusterCreatedEvent(cluster);
+ }
+
+ public static void handleApplicationClustersCreated(String appId, List<Cluster> appClusters) {
+
+ TopologyManager.acquireWriteLock();
+
+ try {
+ Topology topology = TopologyManager.getTopology();
+ for (Cluster cluster : appClusters) {
+ Service service = topology.getService(cluster.getServiceName());
+ if (service == null) {
+ log.error("Service " + cluster.getServiceName() +
+ " not found in Topology, unable to create Application cluster");
+ } else {
+ service.addCluster(cluster);
+ log.info("Application Cluster " + cluster.getClusterId() + " created in CC topology");
+ }
+ }
+ TopologyManager.updateTopology(topology);
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+
+ log.debug("Creating cluster port mappings: [appication-id] " + appId);
+ for (Cluster cluster : appClusters) {
+ String cartridgeType = cluster.getServiceName();
+ Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(cartridgeType);
+ if (cartridge == null) {
+ throw new CloudControllerException("Cartridge not found: [cartridge-type] " + cartridgeType);
+ }
+
+ for (PortMapping portMapping : cartridge.getPortMappings()) {
+ ClusterPortMapping clusterPortMapping =
+ new ClusterPortMapping(appId, cluster.getClusterId(), portMapping.getName(),
+ portMapping.getProtocol(), portMapping.getPort(),
+ portMapping.getProxyPort());
+ CloudControllerContext.getInstance().addClusterPortMapping(clusterPortMapping);
+ log.debug("Cluster port mapping created: " + clusterPortMapping.toString());
+ }
+ }
+
+ // Persist cluster port mappings
+ CloudControllerContext.getInstance().persist();
+
+ // Send application clusters created event
+ TopologyEventPublisher.sendApplicationClustersCreated(appId, appClusters);
+ }
+
+ public static void handleApplicationClustersRemoved(String appId, Set<ClusterDataHolder> clusterData) {
+ TopologyManager.acquireWriteLock();
+
+ List<Cluster> removedClusters = new ArrayList<Cluster>();
+ CloudControllerContext context = CloudControllerContext.getInstance();
+ try {
+ Topology topology = TopologyManager.getTopology();
+
+ if (clusterData != null) {
+ // remove clusters from CC topology model and remove runtime information
+ for (ClusterDataHolder aClusterData : clusterData) {
+ Service aService = topology.getService(aClusterData.getServiceType());
+ if (aService != null) {
+ removedClusters.add(aService.removeCluster(aClusterData.getClusterId()));
+ } else {
+ log.warn("Service " + aClusterData.getServiceType() + " not found, " +
+ "unable to remove Cluster " + aClusterData.getClusterId());
+ }
+ // remove runtime data
+ context.removeClusterContext(aClusterData.getClusterId());
+
+ log.info("Removed application [ " + appId + " ]'s Cluster " +
+ "[ " + aClusterData.getClusterId() + " ] from the topology");
+ }
+ // persist runtime data changes
+ CloudControllerContext.getInstance().persist();
+ } else {
+ log.info("No cluster data found for application " + appId + " to remove");
+ }
+
+ TopologyManager.updateTopology(topology);
+
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+
+ // Remove cluster port mappings of application
+ CloudControllerContext.getInstance().removeClusterPortMappings(appId);
+ CloudControllerContext.getInstance().persist();
+
+ TopologyEventPublisher.sendApplicationClustersRemoved(appId, clusterData);
+
+ }
+
+ public static void handleClusterReset(ClusterStatusClusterResetEvent event) {
+ TopologyManager.acquireWriteLock();
+
+ try {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(event.getServiceName());
+ if (service == null) {
+ log.error("Service " + event.getServiceName() +
+ " not found in Topology, unable to update the cluster status to Created");
+ return;
+ }
+
+ Cluster cluster = service.getCluster(event.getClusterId());
+ if (cluster == null) {
+ log.error("Cluster " + event.getClusterId() + " not found in Topology, unable to update " +
+ "status to Created");
+ return;
+ }
+
+ ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
+ if (context == null) {
+ log.warn("Cluster Instance Context is not found for [cluster] " +
+ event.getClusterId() + " [instance-id] " +
+ event.getInstanceId());
+ return;
+ }
+ ClusterStatus status = ClusterStatus.Created;
+ if (context.isStateTransitionValid(status)) {
+ context.setStatus(status);
+ log.info("Cluster Created adding status started for" + cluster.getClusterId());
+ TopologyManager.updateTopology(topology);
+ //publishing data
+ TopologyEventPublisher
+ .sendClusterResetEvent(event.getAppId(), event.getServiceName(), event.getClusterId(),
+ event.getInstanceId());
+ } else {
+ log.warn(String.format("Cluster state transition is not valid: [cluster-id] %s " +
+ " [instance-id] %s [current-status] %s [status-requested] %s",
+ event.getClusterId(), event.getInstanceId(), context.getStatus(), status));
+ }
+
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+
+ }
+
+ public static void handleClusterInstanceCreated(String serviceType, String clusterId, String alias,
+ String instanceId, String partitionId, String networkPartitionId) {
+
+ TopologyManager.acquireWriteLock();
+
+ try {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(serviceType);
+ if (service == null) {
+ log.error("Service " + serviceType +
+ " not found in Topology, unable to update the cluster status to Created");
+ return;
+ }
+
+ Cluster cluster = service.getCluster(clusterId);
+ if (cluster == null) {
+ log.error("Cluster " + clusterId + " not found in Topology, unable to update " +
+ "status to Created");
+ return;
+ }
+
+ if (cluster.getInstanceContexts(instanceId) != null) {
+ log.warn("The Instance context for the cluster already exists for [cluster] " +
+ clusterId + " [instance-id] " + instanceId);
+ return;
+ }
+
+ ClusterInstance clusterInstance = new ClusterInstance(alias, clusterId, instanceId);
+ clusterInstance.setNetworkPartitionId(networkPartitionId);
+ clusterInstance.setPartitionId(partitionId);
+ cluster.addInstanceContext(instanceId, clusterInstance);
+ TopologyManager.updateTopology(topology);
+
+ ClusterInstanceCreatedEvent clusterInstanceCreatedEvent =
+ new ClusterInstanceCreatedEvent(serviceType, clusterId, clusterInstance);
+ clusterInstanceCreatedEvent.setPartitionId(partitionId);
+ TopologyEventPublisher.sendClusterInstanceCreatedEvent(clusterInstanceCreatedEvent);
+
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ }
+
+ public static void handleClusterRemoved(ClusterContext ctxt) {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(ctxt.getCartridgeType());
+ String deploymentPolicy;
+ if (service == null) {
+ log.warn(String.format("Service %s does not exist", ctxt.getCartridgeType()));
+ return;
+ }
+
+ if (!service.clusterExists(ctxt.getClusterId())) {
+ log.warn(String.format("Cluster %s does not exist for service %s", ctxt.getClusterId(),
+ ctxt.getCartridgeType()));
+ return;
+ }
+
+ try {
+ TopologyManager.acquireWriteLock();
+ Cluster cluster = service.removeCluster(ctxt.getClusterId());
+ deploymentPolicy = cluster.getDeploymentPolicyName();
+ TopologyManager.updateTopology(topology);
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ TopologyEventPublisher.sendClusterRemovedEvent(ctxt, deploymentPolicy);
+ }
+
+ /**
+ * Add member object to the topology and publish member created event
+ *
+ * @param memberContext
+ */
+ public static void handleMemberCreatedEvent(MemberContext memberContext) {
+ Topology topology = TopologyManager.getTopology();
+
+ Service service = topology.getService(memberContext.getCartridgeType());
+ String clusterId = memberContext.getClusterId();
+ Cluster cluster = service.getCluster(clusterId);
+ String memberId = memberContext.getMemberId();
+ String clusterInstanceId = memberContext.getClusterInstanceId();
+ String networkPartitionId = memberContext.getNetworkPartitionId();
+ String partitionId = memberContext.getPartition().getId();
+ String lbClusterId = memberContext.getLbClusterId();
+ long initTime = memberContext.getInitTime();
+ String autoscalingReason =
+ memberContext.getProperties().getProperty(StratosConstants.SCALING_REASON).getValue();
+ long scalingTime =
+ Long.parseLong(memberContext.getProperties().getProperty(StratosConstants.SCALING_TIME).getValue());
+
+ if (cluster.memberExists(memberId)) {
+ log.warn(String.format("Member %s already exists", memberId));
+ return;
+ }
+
+ try {
+ TopologyManager.acquireWriteLock();
+ Member member =
+ new Member(service.getServiceName(), clusterId, memberId, clusterInstanceId, networkPartitionId,
+ partitionId, memberContext.getLoadBalancingIPType(), initTime);
+ member.setStatus(MemberStatus.Created);
+ member.setLbClusterId(lbClusterId);
+ member.setProperties(CloudControllerUtil.toJavaUtilProperties(memberContext.getProperties()));
+ cluster.addMember(member);
+ TopologyManager.updateTopology(topology);
+ //Member created time
+ Long timeStamp = System.currentTimeMillis();
+ //publishing to BAM
+ BAMUsageDataPublisher.publish(memberContext.getMemberId(), memberContext.getPartition().getId(),
+ memberContext.getNetworkPartitionId(), memberContext.getClusterId(),
+ memberContext.getClusterInstanceId(), memberContext.getCartridgeType(),
+ MemberStatus.Created.toString(), timeStamp, autoscalingReason, scalingTime,
+ null);
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+
+ TopologyEventPublisher.sendMemberCreatedEvent(memberContext);
+ }
+
+ /**
+ * Update member status to initialized and publish member initialized event
+ *
+ * @param memberContext
+ */
+ public static void handleMemberInitializedEvent(MemberContext memberContext) {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(memberContext.getCartridgeType());
+ if (service == null) {
+ log.warn(String.format("Service %s does not exist", memberContext.getCartridgeType()));
+ return;
+ }
+ if (!service.clusterExists(memberContext.getClusterId())) {
+ log.warn(String.format("Cluster %s does not exist in service %s", memberContext.getClusterId(),
+ memberContext.getCartridgeType()));
+ return;
+ }
+
+ Member member = service.getCluster(memberContext.getClusterId()).
+ getMember(memberContext.getMemberId());
+ if (member == null) {
+ log.warn(String.format("Member %s does not exist", memberContext.getMemberId()));
+ return;
+ }
+
+ try {
+ TopologyManager.acquireWriteLock();
+
+ // Set ip addresses
+ member.setDefaultPrivateIP(memberContext.getDefaultPrivateIP());
+ if (memberContext.getPrivateIPs() != null) {
+ member.setMemberPrivateIPs(Arrays.asList(memberContext.getPrivateIPs()));
+ }
+ member.setDefaultPublicIP(memberContext.getDefaultPublicIP());
+ if (memberContext.getPublicIPs() != null) {
+ member.setMemberPublicIPs(Arrays.asList(memberContext.getPublicIPs()));
+ }
+
+ // try update lifecycle state
+ if (!member.isStateTransitionValid(MemberStatus.Initialized)) {
+ log.error("Invalid state transition from " + member.getStatus() + " to " +
+ MemberStatus.Initialized);
+ return;
+ } else {
+ member.setStatus(MemberStatus.Initialized);
+ log.info("Member status updated to initialized");
+
+ TopologyManager.updateTopology(topology);
+ //member initialized time
+ Long timeStamp = System.currentTimeMillis();
+
+ TopologyEventPublisher.sendMemberInitializedEvent(memberContext);
+ //publishing data
+ BAMUsageDataPublisher.publish(memberContext.getMemberId(), memberContext.getPartition().getId(),
+ memberContext.getNetworkPartitionId(), memberContext.getClusterId(),
+ memberContext.getCartridgeType(), MemberStatus.Initialized.toString(),
+ timeStamp, null, null, null);
+ }
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ }
+
+ private static int findKubernetesServicePort(String clusterId, List<KubernetesService> kubernetesServices,
+ PortMapping portMapping) {
+ for (KubernetesService kubernetesService : kubernetesServices) {
+ if (kubernetesService.getProtocol().equals(portMapping.getProtocol())) {
+ return kubernetesService.getPort();
+ }
+ }
+ throw new RuntimeException(
+ "Kubernetes service port not found: [cluster-id] " + clusterId + " [port] " + portMapping.getPort());
+ }
+
+ public static void handleMemberStarted(InstanceStartedEvent instanceStartedEvent) {
+ try {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(instanceStartedEvent.getServiceName());
+ if (service == null) {
+ log.warn(String.format("Service %s does not exist", instanceStartedEvent.getServiceName()));
+ return;
+ }
+ if (!service.clusterExists(instanceStartedEvent.getClusterId())) {
+ log.warn(String.format("Cluster %s does not exist in service %s", instanceStartedEvent.getClusterId(),
+ instanceStartedEvent.getServiceName()));
+ return;
+ }
+
+ Cluster cluster = service.getCluster(instanceStartedEvent.getClusterId());
+ Member member = cluster.getMember(instanceStartedEvent.getMemberId());
+ if (member == null) {
+ log.warn(String.format("Member %s does not exist", instanceStartedEvent.getMemberId()));
+ return;
+ }
+
+ try {
+ TopologyManager.acquireWriteLock();
+ // try update lifecycle state
+ if (!member.isStateTransitionValid(MemberStatus.Starting)) {
+ log.error("Invalid State Transition from " + member.getStatus() + " to " +
+ MemberStatus.Starting);
+ return;
+ } else {
+ member.setStatus(MemberStatus.Starting);
+ log.info("member started event adding status started");
+
+ TopologyManager.updateTopology(topology);
+ //member starting time
+ Long timeStamp = System.currentTimeMillis();
+ //memberStartedEvent.
+ TopologyEventPublisher.sendMemberStartedEvent(instanceStartedEvent);
+ //publishing data
+ BAMUsageDataPublisher
+ .publish(instanceStartedEvent.getMemberId(), instanceStartedEvent.getPartitionId(),
+ instanceStartedEvent.getNetworkPartitionId(), instanceStartedEvent.getClusterId(),
+ instanceStartedEvent.getServiceName(), MemberStatus.Starting.toString(), null,
+ null, null);
+ }
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ } catch (Exception e) {
+ String message = String.format(
+ "Could not handle member started event: [application-id] %s " + "[service-name] %s [member-id] %s",
+ instanceStartedEvent.getApplicationId(), instanceStartedEvent.getServiceName(),
+ instanceStartedEvent.getMemberId());
+ log.warn(message, e);
+ }
+ }
+
+ public static void handleMemberActivated(InstanceActivatedEvent instanceActivatedEvent) {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(instanceActivatedEvent.getServiceName());
+ if (service == null) {
+ log.warn(String.format("Service %s does not exist", instanceActivatedEvent.getServiceName()));
+ return;
+ }
+
+ Cluster cluster = service.getCluster(instanceActivatedEvent.getClusterId());
+ if (cluster == null) {
+ log.warn(String.format("Cluster %s does not exist", instanceActivatedEvent.getClusterId()));
+ return;
+ }
+
+ Member member = cluster.getMember(instanceActivatedEvent.getMemberId());
+ if (member == null) {
+ log.warn(String.format("Member %s does not exist", instanceActivatedEvent.getMemberId()));
+ return;
+ }
+
+ MemberActivatedEvent memberActivatedEvent =
+ new MemberActivatedEvent(instanceActivatedEvent.getServiceName(), instanceActivatedEvent.getClusterId(),
+ instanceActivatedEvent.getClusterInstanceId(),
+ instanceActivatedEvent.getMemberId(),
+ instanceActivatedEvent.getNetworkPartitionId(),
+ instanceActivatedEvent.getPartitionId());
+
+ // grouping - set grouid
+ //TODO
+ memberActivatedEvent.setApplicationId(null);
+ try {
+ TopologyManager.acquireWriteLock();
+ // try update lifecycle state
+ if (!member.isStateTransitionValid(MemberStatus.Active)) {
+ log.error(
+ "Invalid state transition from [" + member.getStatus() + "] to [" + MemberStatus.Active + "]");
+ return;
+ } else {
+ member.setStatus(MemberStatus.Active);
+
+ // Set member ports
+ try {
+ Cartridge cartridge = CloudControllerContext.getInstance().getCartridge(service.getServiceName());
+ if (cartridge == null) {
+ throw new RuntimeException(
+ String.format("Cartridge not found: [cartridge-type] %s", service.getServiceName()));
+ }
+
+ Port port;
+ int portValue;
+ List<PortMapping> portMappings = Arrays.asList(cartridge.getPortMappings());
+ String clusterId = cluster.getClusterId();
+ ClusterContext clusterContext = CloudControllerContext.getInstance().getClusterContext(clusterId);
+ List<KubernetesService> kubernetesServices = clusterContext.getKubernetesServices();
+
+ for (PortMapping portMapping : portMappings) {
+ if (kubernetesServices != null) {
+ portValue = findKubernetesServicePort(clusterId, kubernetesServices, portMapping);
+ } else {
+ portValue = portMapping.getPort();
+ }
+ port = new Port(portMapping.getProtocol(), portValue, portMapping.getProxyPort());
+ member.addPort(port);
+ memberActivatedEvent.addPort(port);
+ }
+ } catch (Exception e) {
+ String message = String.format("Could not add member ports: [service-name] %s [member-id] %s",
+ memberActivatedEvent.getServiceName(),
+ memberActivatedEvent.getMemberId());
+ log.error(message, e);
+ }
+
+ // Set member ip addresses
+ memberActivatedEvent.setDefaultPrivateIP(member.getDefaultPrivateIP());
+ memberActivatedEvent.setMemberPrivateIPs(member.getMemberPrivateIPs());
+ memberActivatedEvent.setDefaultPublicIP(member.getDefaultPublicIP());
+ memberActivatedEvent.setMemberPublicIPs(member.getMemberPublicIPs());
+ TopologyManager.updateTopology(topology);
+
+ //member activated time
+ Long timeStamp = System.currentTimeMillis();
+
+ // Publish member activated event
+ TopologyEventPublisher.sendMemberActivatedEvent(memberActivatedEvent);
+
+ // Publish statistics data
+ BAMUsageDataPublisher.publish(memberActivatedEvent.getMemberId(), memberActivatedEvent.getPartitionId(),
+ memberActivatedEvent.getNetworkPartitionId(),
+ memberActivatedEvent.getClusterId(),
+ memberActivatedEvent.getServiceName(), MemberStatus.Active.toString(),
+ null, null, null);
+ }
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ }
+
+ public static void handleMemberReadyToShutdown(InstanceReadyToShutdownEvent instanceReadyToShutdownEvent)
+ throws InvalidMemberException, InvalidCartridgeTypeException {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(instanceReadyToShutdownEvent.getServiceName());
+ //update the status of the member
+ if (service == null) {
+ log.warn(String.format("Service %s does not exist", instanceReadyToShutdownEvent.getServiceName()));
+ return;
+ }
+
+ Cluster cluster = service.getCluster(instanceReadyToShutdownEvent.getClusterId());
+ if (cluster == null) {
+ log.warn(String.format("Cluster %s does not exist", instanceReadyToShutdownEvent.getClusterId()));
+ return;
+ }
+
+ Member member = cluster.getMember(instanceReadyToShutdownEvent.getMemberId());
+ if (member == null) {
+ log.warn(String.format("Member %s does not exist", instanceReadyToShutdownEvent.getMemberId()));
+ return;
+ }
+ MemberReadyToShutdownEvent memberReadyToShutdownEvent =
+ new MemberReadyToShutdownEvent(instanceReadyToShutdownEvent.getServiceName(),
+ instanceReadyToShutdownEvent.getClusterId(),
+ instanceReadyToShutdownEvent.getClusterInstanceId(),
+ instanceReadyToShutdownEvent.getMemberId(),
+ instanceReadyToShutdownEvent.getNetworkPartitionId(),
+ instanceReadyToShutdownEvent.getPartitionId());
+ //get the time of ReadyToShutdown state change
+ Long timeStamp = null;
+ try {
+ TopologyManager.acquireWriteLock();
+
+ if (!member.isStateTransitionValid(MemberStatus.ReadyToShutDown)) {
+ log.error("Invalid State Transition from " + member.getStatus() + " to " +
+ MemberStatus.ReadyToShutDown);
+ return;
+ }
+ member.setStatus(MemberStatus.ReadyToShutDown);
+ log.info("Member Ready to shut down event adding status started");
+
+ TopologyManager.updateTopology(topology);
+
+ timeStamp = System.currentTimeMillis();
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ TopologyEventPublisher.sendMemberReadyToShutdownEvent(memberReadyToShutdownEvent);
+ //publishing data
+ BAMUsageDataPublisher
+ .publish(instanceReadyToShutdownEvent.getMemberId(), instanceReadyToShutdownEvent.getPartitionId(),
+ instanceReadyToShutdownEvent.getNetworkPartitionId(),
+ instanceReadyToShutdownEvent.getClusterId(), instanceReadyToShutdownEvent.getServiceName(),
+ MemberStatus.ReadyToShutDown.toString(), null, null, null);
+ //termination of particular instance will be handled by autoscaler
+ }
+
+ public static void handleMemberMaintenance(InstanceMaintenanceModeEvent instanceMaintenanceModeEvent)
+ throws InvalidMemberException, InvalidCartridgeTypeException {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(instanceMaintenanceModeEvent.getServiceName());
+ //update the status of the member
+ if (service == null) {
+ log.warn(String.format("Service %s does not exist", instanceMaintenanceModeEvent.getServiceName()));
+ return;
+ }
+
+ Cluster cluster = service.getCluster(instanceMaintenanceModeEvent.getClusterId());
+ if (cluster == null) {
+ log.warn(String.format("Cluster %s does not exist", instanceMaintenanceModeEvent.getClusterId()));
+ return;
+ }
+
+ Member member = cluster.getMember(instanceMaintenanceModeEvent.getMemberId());
+ if (member == null) {
+ log.warn(String.format("Member %s does not exist", instanceMaintenanceModeEvent.getMemberId()));
+ return;
+ }
+
+ MemberMaintenanceModeEvent memberMaintenanceModeEvent =
+ new MemberMaintenanceModeEvent(instanceMaintenanceModeEvent.getServiceName(),
+ instanceMaintenanceModeEvent.getClusterId(),
+ instanceMaintenanceModeEvent.getClusterInstanceId(),
+ instanceMaintenanceModeEvent.getMemberId(),
+ instanceMaintenanceModeEvent.getNetworkPartitionId(),
+ instanceMaintenanceModeEvent.getPartitionId());
+ try {
+ TopologyManager.acquireWriteLock();
+ // try update lifecycle state
+ if (!member.isStateTransitionValid(MemberStatus.In_Maintenance)) {
+ log.error("Invalid State Transition from " + member.getStatus() + " to " + MemberStatus.In_Maintenance);
+ return;
+ }
+ member.setStatus(MemberStatus.In_Maintenance);
+ log.info("member maintenance mode event adding status started");
+
+ TopologyManager.updateTopology(topology);
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ //publishing data
+ TopologyEventPublisher.sendMemberMaintenanceModeEvent(memberMaintenanceModeEvent);
+
+ }
+
+ /**
+ * Remove member from topology and send member terminated event.
+ *
+ * @param serviceName
+ * @param clusterId
+ * @param networkPartitionId
+ * @param partitionId
+ * @param memberId
+ */
+ public static void handleMemberTerminated(String serviceName, String clusterId, String networkPartitionId,
+ String partitionId, String memberId) {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(serviceName);
+ Properties properties;
+ if (service == null) {
+ log.warn(String.format("Service %s does not exist", serviceName));
+ return;
+ }
+ Cluster cluster = service.getCluster(clusterId);
+ if (cluster == null) {
+ log.warn(String.format("Cluster %s does not exist", clusterId));
+ return;
+ }
+
+ Member member = cluster.getMember(memberId);
+ if (member == null) {
+ log.warn(String.format("Member %s does not exist", memberId));
+ return;
+ }
+
+ String clusterInstanceId = member.getClusterInstanceId();
+
+ try {
+ TopologyManager.acquireWriteLock();
+ properties = member.getProperties();
+ cluster.removeMember(member);
+ TopologyManager.updateTopology(topology);
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ /* @TODO leftover from grouping_poc*/
+ String groupAlias = null;
+ TopologyEventPublisher
+ .sendMemberTerminatedEvent(serviceName, clusterId, memberId, clusterInstanceId, networkPartitionId,
+ partitionId, properties, groupAlias);
+ }
+
+ public static void handleMemberSuspended() {
+ //TODO
+ try {
+ TopologyManager.acquireWriteLock();
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ }
+
+ public static void handleClusterActivatedEvent(
+ ClusterStatusClusterActivatedEvent clusterStatusClusterActivatedEvent) {
+
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(clusterStatusClusterActivatedEvent.getServiceName());
+ //update the status of the cluster
+ if (service == null) {
+ log.warn(String.format("Service %s does not exist", clusterStatusClusterActivatedEvent.getServiceName()));
+ return;
+ }
+
+ Cluster cluster = service.getCluster(clusterStatusClusterActivatedEvent.getClusterId());
+ if (cluster == null) {
+ log.warn(String.format("Cluster %s does not exist", clusterStatusClusterActivatedEvent.getClusterId()));
+ return;
+ }
+
+ String clusterId = cluster.getClusterId();
+ ClusterContext clusterContext = CloudControllerContext.getInstance().getClusterContext(clusterId);
+ if (clusterContext == null) {
+ log.warn("Cluster context not found: [cluster-id] " + clusterId);
+ return;
+ }
+
+ ClusterInstanceActivatedEvent clusterInstanceActivatedEvent =
+ new ClusterInstanceActivatedEvent(clusterStatusClusterActivatedEvent.getAppId(),
+ clusterStatusClusterActivatedEvent.getServiceName(),
+ clusterStatusClusterActivatedEvent.getClusterId(),
+ clusterStatusClusterActivatedEvent.getInstanceId());
+ try {
+ TopologyManager.acquireWriteLock();
+ List<KubernetesService> kubernetesServices = clusterContext.getKubernetesServices();
+ cluster.setKubernetesServices(kubernetesServices);
+ clusterInstanceActivatedEvent.setKubernetesServices(kubernetesServices);
+
+ ClusterInstance context = cluster.getInstanceContexts(clusterStatusClusterActivatedEvent.getInstanceId());
+ if (context == null) {
+ log.warn("Cluster instance context is not found for [cluster] " +
+ clusterStatusClusterActivatedEvent.getClusterId() + " [instance-id] " +
+ clusterStatusClusterActivatedEvent.getInstanceId());
+ return;
+ }
+ ClusterStatus status = ClusterStatus.Active;
+ if (context.isStateTransitionValid(status)) {
+ context.setStatus(status);
+ log.info("Cluster activated adding status started for " + cluster.getClusterId());
+ TopologyManager.updateTopology(topology);
+ // publish event
+ TopologyEventPublisher.sendClusterActivatedEvent(clusterInstanceActivatedEvent);
+ } else {
+ log.error(String.format("Cluster state transition is not valid: [cluster-id] %s " +
+ " [instance-id] %s [current-status] %s [status-requested] %s",
+ clusterStatusClusterActivatedEvent.getClusterId(),
+ clusterStatusClusterActivatedEvent.getInstanceId(), context.getStatus(),
+ status));
+ return;
+ }
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+
+ }
+
+ public static void handleClusterInactivateEvent(ClusterStatusClusterInactivateEvent clusterInactivateEvent) {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(clusterInactivateEvent.getServiceName());
+ //update the status of the cluster
+ if (service == null) {
+ log.warn(String.format("Service %s does not exist", clusterInactivateEvent.getServiceName()));
+ return;
+ }
+
+ Cluster cluster = service.getCluster(clusterInactivateEvent.getClusterId());
+ if (cluster == null) {
+ log.warn(String.format("Cluster %s does not exist", clusterInactivateEvent.getClusterId()));
+ return;
+ }
+
+ ClusterInstanceInactivateEvent clusterInactivatedEvent1 =
+ new ClusterInstanceInactivateEvent(clusterInactivateEvent.getAppId(),
+ clusterInactivateEvent.getServiceName(),
+ clusterInactivateEvent.getClusterId(),
+ clusterInactivateEvent.getInstanceId());
+ try {
+ TopologyManager.acquireWriteLock();
+ ClusterInstance context = cluster.getInstanceContexts(clusterInactivateEvent.getInstanceId());
+ if (context == null) {
+ log.warn("Cluster Instance Context is not found for [cluster] " +
+ clusterInactivateEvent.getClusterId() + " [instance-id] " +
+ clusterInactivateEvent.getInstanceId());
+ return;
+ }
+ ClusterStatus status = ClusterStatus.Inactive;
+ if (context.isStateTransitionValid(status)) {
+ context.setStatus(status);
+ log.info("Cluster Inactive adding status started for" + cluster.getClusterId());
+ TopologyManager.updateTopology(topology);
+ //publishing data
+ TopologyEventPublisher.sendClusterInactivateEvent(clusterInactivatedEvent1);
+ } else {
+ log.error(String.format("Cluster state transition is not valid: [cluster-id] %s " +
+ " [instance-id] %s [current-status] %s [status-requested] %s",
+ clusterInactivateEvent.getClusterId(), clusterInactivateEvent.getInstanceId(),
+ context.getStatus(), status));
+ return;
+ }
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ }
+
+ private static void deleteAppResourcesFromMetadataService(ApplicationInstanceTerminatedEvent event) {
+ try {
+ MetaDataServiceClient metadataClient = new DefaultMetaDataServiceClient();
+ metadataClient.deleteApplicationProperties(event.getAppId());
+ } catch (Exception e) {
+ log.error("Error occurred while deleting the application resources frm metadata service ", e);
+ }
+ }
+
+ public static void handleClusterTerminatedEvent(ClusterStatusClusterTerminatedEvent event) {
+
+ TopologyManager.acquireWriteLock();
+
+ try {
+ Topology topology = TopologyManager.getTopology();
+ Service service = topology.getService(event.getServiceName());
+
+ //update the status of the cluster
+ if (service == null) {
+ log.warn(String.format("Service %s does not exist", event.getServiceName()));
+ return;
+ }
+
+ Cluster cluster = service.getCluster(event.getClusterId());
+ if (cluster == null) {
+ log.warn(String.format("Cluster %s does not exist", event.getClusterId()));
+ return;
+ }
+
+ ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
+ if (context == null) {
+ log.warn("Cluster Instance Context is not found for [cluster] " +
+ event.getClusterId() + " [instance-id] " +
+ event.getInstanceId());
+ return;
+ }
+ ClusterStatus status = ClusterStatus.Terminated;
+ if (context.isStateTransitionValid(status)) {
+ context.setStatus(status);
+ log.info("Cluster Terminated adding status started for and removing the cluster instance" +
+ cluster.getClusterId());
+ cluster.removeInstanceContext(event.getInstanceId());
+ TopologyManager.updateTopology(topology);
+ //publishing data
+ ClusterInstanceTerminatedEvent clusterTerminatedEvent =
+ new ClusterInstanceTerminatedEvent(event.getAppId(), event.getServiceName(),
+ event.getClusterId(), event.getInstanceId());
+
+ TopologyEventPublisher.sendClusterTerminatedEvent(clusterTerminatedEvent);
+ } else {
+ log.error(String.format("Cluster state transition is not valid: [cluster-id] %s " +
+ " [instance-id] %s [current-status] %s [status-requested] %s",
+ event.getClusterId(), event.getInstanceId(), context.getStatus(), status));
+ return;
+ }
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+
+ }
+
+ public static void handleClusterTerminatingEvent(ClusterStatusClusterTerminatingEvent event) {
+
+ TopologyManager.acquireWriteLock();
+
+ try {
+ Topology topology = TopologyManager.getTopology();
+ Cluster cluster = topology.getService(event.getServiceName()).
+ getCluster(event.getClusterId());
+
+ if (!cluster.isStateTransitionValid(ClusterStatus.Terminating, event.getInstanceId())) {
+ log.error("Invalid state transfer from " + cluster.getStatus(event.getInstanceId()) + " to " +
+ ClusterStatus.Terminating);
+ }
+ ClusterInstance context = cluster.getInstanceContexts(event.getInstanceId());
+ if (context == null) {
+ log.warn("Cluster Instance Context is not found for [cluster] " +
+ event.getClusterId() + " [instance-id] " +
+ event.getInstanceId());
+ return;
+ }
+ ClusterStatus status = ClusterStatus.Terminating;
+ if (context.isStateTransitionValid(status)) {
+ context.setStatus(status);
+ log.info("Cluster Terminating started for " + cluster.getClusterId());
+ TopologyManager.updateTopology(topology);
+ //publishing data
+ ClusterInstanceTerminatingEvent clusterTerminaingEvent =
+ new ClusterInstanceTerminatingEvent(event.getAppId(), event.getServiceName(),
+ event.getClusterId(), event.getInstanceId());
+
+ TopologyEventPublisher.sendClusterTerminatingEvent(clusterTerminaingEvent);
+
+ // Remove kubernetes services if available
+ ClusterContext clusterContext =
+ CloudControllerContext.getInstance().getClusterContext(event.getClusterId());
+ if (StringUtils.isNotBlank(clusterContext.getKubernetesClusterId())) {
+ KubernetesIaas.removeKubernetesServices(event.getAppId(), event.getClusterId());
+ }
+ } else {
+ log.error(String.format("Cluster state transition is not valid: [cluster-id] %s " +
+ " [instance-id] %s [current-status] %s [status-requested] %s",
+ event.getClusterId(), event.getInstanceId(), context.getStatus(), status));
+ }
+ } finally {
+ TopologyManager.releaseWriteLock();
+ }
+ }
}
[18/18] stratos git commit: Adding DAS Artifacts
Posted by im...@apache.org.
Adding DAS Artifacts
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/9ceab963
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/9ceab963
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/9ceab963
Branch: refs/heads/master
Commit: 9ceab963b7c7fb5a5e85fc2f54c4d034348ce6e8
Parents: 218b5fd
Author: Thanuja <th...@wso2.com>
Authored: Thu Jul 23 17:27:35 2015 +0530
Committer: Thanuja <th...@wso2.com>
Committed: Thu Jul 23 17:27:35 2015 +0530
----------------------------------------------------------------------
extensions/das/artifacts/CCEventReceiver.xml | 29 +++++
extensions/das/artifacts/SparkQuery.txt | 19 ++++
...g.apache.stratos.cloud.controller_1.0.0.json | 112 +++++++++++++++++++
.../org_apache_stratos_cloud_controller.xml | 1 +
extensions/das/spark-time-udf/pom.xml | 12 ++
.../stratos/das/spark/udf/time/TimeUDF.java | 49 ++++++++
6 files changed, 222 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/9ceab963/extensions/das/artifacts/CCEventReceiver.xml
----------------------------------------------------------------------
diff --git a/extensions/das/artifacts/CCEventReceiver.xml b/extensions/das/artifacts/CCEventReceiver.xml
new file mode 100644
index 0000000..2d4a3c4
--- /dev/null
+++ b/extensions/das/artifacts/CCEventReceiver.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+<eventReceiver name="CCEventReceiver" statistics="disable"
+ trace="enable" xmlns="http://wso2.org/carbon/eventreceiver">
+ <from eventAdapterType="wso2event">
+ <property name="events.duplicated.in.cluster">false</property>
+ </from>
+ <mapping customMapping="disable" type="wso2event"/>
+ <to streamName="org.apache.stratos.cloud.controller" version="1.0.0"/>
+</eventReceiver>
http://git-wip-us.apache.org/repos/asf/stratos/blob/9ceab963/extensions/das/artifacts/SparkQuery.txt
----------------------------------------------------------------------
diff --git a/extensions/das/artifacts/SparkQuery.txt b/extensions/das/artifacts/SparkQuery.txt
new file mode 100644
index 0000000..39f7d47
--- /dev/null
+++ b/extensions/das/artifacts/SparkQuery.txt
@@ -0,0 +1,19 @@
+CREATE TEMPORARY TABLE memberstatus
+USING CarbonAnalytics
+OPTIONS (tableName "ORG_APACHE_STRATOS_CLOUD_CONTROLLER");
+
+CREATE TEMPORARY TABLE memberstatusnew
+USING CarbonAnalytics
+OPTIONS (tableName "CLUSTER_MEMBER_NEW",
+ schema "startTime String, endTime String, clusterId STRING, activatedInstanceCount INT, terminatedInstanceCount INT, activeInstanceCount INT");
+
+
+;WITH InstanceCount as
+(select clusterId, count(case when status='Active' and timeStamp > current_time(null)-60000 and timeStamp <= current_time(null) then 1 else NULL end) as activatedInstanceCount, count(case when status='Terminated' and timeStamp > current_time(null)-60000 and timeStamp <= current_time(null) then 1 else NULL end) as terminatedInstanceCount, (sum(case when status='Active' then 1 else 0 end) - sum(case when status='Terminated' then 1 else 0 end))as activeInstanceCount from memberstatus group by clusterId)
+INSERT INTO table memberstatusnew select time(current_time(null)-60000),time(current_time(null)),clusterId, activatedInstanceCount, terminatedInstanceCount,activeInstanceCount from InstanceCount;
+
+CREATE TEMPORARY TABLE membersnew
+USING CarbonAnalytics
+OPTIONS (tableName "MEMBER_NEW",schema "clusterId STRING, clusterInstanceId STRING, partitionId STRING, networkId STRING, cartridgeType STRING, instanceType STRING, memberId STRING, scalingTime LONG,scalingReason STRING, timeStamp LONG");
+
+INSERT INTO TABLE membersnew select clusterId, clusterInstanceId,partitionId,networkId,cartridgeType,instanceType, memberId, time(scalingTime),scalingReason,time(timeStamp) FROM memberstatus where status='Created';
http://git-wip-us.apache.org/repos/asf/stratos/blob/9ceab963/extensions/das/artifacts/org.apache.stratos.cloud.controller_1.0.0.json
----------------------------------------------------------------------
diff --git a/extensions/das/artifacts/org.apache.stratos.cloud.controller_1.0.0.json b/extensions/das/artifacts/org.apache.stratos.cloud.controller_1.0.0.json
new file mode 100644
index 0000000..c0bc66b
--- /dev/null
+++ b/extensions/das/artifacts/org.apache.stratos.cloud.controller_1.0.0.json
@@ -0,0 +1,112 @@
+{
+ "name": "org.apache.stratos.cloud.controller",
+ "version": "1.0.0",
+ "nickName": "cloud.controller",
+ "description": "Instances booted up by the Cloud Controller",
+ "payloadData": [
+ {
+ "name": "timeStamp",
+ "type": "LONG"
+ },
+ {
+ "name": "memberId",
+ "type": "STRING"
+ },
+ {
+ "name": "cartridgeType",
+ "type": "STRING"
+ },
+ {
+ "name": "clusterId",
+ "type": "STRING"
+ },
+ {
+ "name": "clusterInstanceId",
+ "type": "STRING"
+ },
+ {
+ "name": "lbclusterId",
+ "type": "STRING"
+ },
+ {
+ "name": "partitionId",
+ "type": "STRING"
+ },
+ {
+ "name": "networkId",
+ "type": "STRING"
+ },
+ {
+ "name": "instanceType",
+ "type": "STRING"
+ },
+ {
+ "name": "scalingReason",
+ "type": "STRING"
+ },
+ {
+ "name": "scalingTime",
+ "type": "LONG"
+ },
+ {
+ "name": "isMultiTenant",
+ "type": "STRING"
+ },
+ {
+ "name": "iaas",
+ "type": "STRING"
+ },
+ {
+ "name": "status",
+ "type": "STRING"
+ },
+ {
+ "name": "hostName",
+ "type": "STRING"
+ },
+ {
+ "name": "hypervisor",
+ "type": "STRING"
+ },
+ {
+ "name": "ram",
+ "type": "STRING"
+ },
+ {
+ "name": "imageId",
+ "type": "STRING"
+ },
+ {
+ "name": "loginPort",
+ "type": "INT"
+ },
+ {
+ "name": "osName",
+ "type": "STRING"
+ },
+ {
+ "name": "osVersion",
+ "type": "STRING"
+ },
+ {
+ "name": "osArch",
+ "type": "STRING"
+ },
+ {
+ "name": "is64bitOS",
+ "type": "STRING"
+ },
+ {
+ "name": "privateIPAddresses",
+ "type": "STRING"
+ },
+ {
+ "name": "publicIPAddresses",
+ "type": "STRING"
+ },
+ {
+ "name": "allocateIPAddresses",
+ "type": "STRING"
+ }
+ ]
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/9ceab963/extensions/das/artifacts/org_apache_stratos_cloud_controller.xml
----------------------------------------------------------------------
diff --git a/extensions/das/artifacts/org_apache_stratos_cloud_controller.xml b/extensions/das/artifacts/org_apache_stratos_cloud_controller.xml
new file mode 100644
index 0000000..ee99acd
--- /dev/null
+++ b/extensions/das/artifacts/org_apache_stratos_cloud_controller.xml
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?><EventStoreConfiguration><TableSchema><ColumnDefinition><Name>timeStamp</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>LONG</Type></ColumnDefinition><ColumnDefinition><Name>memberId</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>cartridgeType</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>clusterId</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>clusterInstanceId</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScorePar
am>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>lbclusterId</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>partitionId</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>networkId</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>instanceType</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>scalingReason</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam
><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>scalingTime</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>LONG</Type></ColumnDefinition><ColumnDefinition><Name>isMultiTenant</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>iaas</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>status</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>hostName</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><Co
lumnDefinition><Name>hypervisor</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>ram</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>imageId</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>loginPort</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>INTEGER</Type></ColumnDefinition><ColumnDefinition><Name>osName</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>osVersion</Name><EnableIn
dexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>osArch</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>is64bitOS</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>privateIPAddresses</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>publicIPAddresses</Name><EnableIndexing>false</EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition><ColumnDefinition><Name>allocateIPAddresses</Name><EnableIndexing>false<
/EnableIndexing><IsPrimaryKey>false</IsPrimaryKey><EnableScoreParam>false</EnableScoreParam><Type>STRING</Type></ColumnDefinition></TableSchema><Source><StreamId>org.apache.stratos.cloud.controller:1.0.0</StreamId></Source><RecordStoreName>EVENT_STORE</RecordStoreName></EventStoreConfiguration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/9ceab963/extensions/das/spark-time-udf/pom.xml
----------------------------------------------------------------------
diff --git a/extensions/das/spark-time-udf/pom.xml b/extensions/das/spark-time-udf/pom.xml
new file mode 100644
index 0000000..fd69c39
--- /dev/null
+++ b/extensions/das/spark-time-udf/pom.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>stratos-extensions</artifactId>
+ <version>4.1.0</version>
+
+
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/9ceab963/extensions/das/spark-time-udf/src/main/java/org/apache/stratos/das/spark/udf/time/TimeUDF.java
----------------------------------------------------------------------
diff --git a/extensions/das/spark-time-udf/src/main/java/org/apache/stratos/das/spark/udf/time/TimeUDF.java b/extensions/das/spark-time-udf/src/main/java/org/apache/stratos/das/spark/udf/time/TimeUDF.java
new file mode 100644
index 0000000..330c5b2
--- /dev/null
+++ b/extensions/das/spark-time-udf/src/main/java/org/apache/stratos/das/spark/udf/time/TimeUDF.java
@@ -0,0 +1,49 @@
+/*
+ * 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.das.spark.udf.time;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Implementing UDF for implementing spark sql query related to time.
+ */
+public class TimeUDF {
+ /**
+ * Convert time(ms) to DateFormat
+ *
+ * @param timeStamp time in ms
+ * @return date as String
+ */
+ public String time(Long timeStamp) {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+ Date date = new Date(timeStamp.longValue());
+ return sdf.format(date);
+ }
+
+ /**
+ * Get the current time in ms
+ *
+ * @param param
+ * @return
+ */
+ public long current_time(int param) {
+ return System.currentTimeMillis();
+ }
+}