http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/MemberContext.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/MemberContext.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/MemberContext.java new file mode 100644 index 0000000..a5ab367 --- /dev/null +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/MemberContext.java @@ -0,0 +1,242 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.stratos.cloud.controller.domain; + +import org.apache.stratos.common.Properties; +import org.apache.stratos.common.Property; + +import java.io.Serializable; + +/** + * Holds information about a Member. + * + */ +public class MemberContext implements Serializable { + + private static final long serialVersionUID = -388327475844701869L; + // id of the member + private String memberId; + // corresponding jclouds node id + private String nodeId; + // instance id - derived from nodeId + private String instanceId; + // cluster id of this member + private String clusterId; + // partition this member is in. + private Partition partition; + // cartridge type this member belongs to. + private String cartridgeType; + // private ip + private String privateIpAddress; + // public ip + private String publicIpAddress; + // manually allocated ip + private String allocatedIpAddress; + // member initiated time + private long initTime; + // lb cluster id of this member + private String lbClusterId; + //network partition id + private String networkPartitionId; + //member expiry period on the topology + private long obsoleteExpiryTime; + //member obsolete init time + private long obsoleteInitTime; + + private Properties properties; + + public MemberContext(String id, String clusterId, Partition partition) { + this.memberId = id; + this.clusterId = clusterId; + this.setPartition(partition); + init(); + } + + public MemberContext() { + init(); + } + + private void init() { + this.properties = new Properties(); + this.properties.setProperties(new Property[0]); + } + + public String getMemberId() { + return memberId; + } + public void setMemberId(String memberId) { + this.memberId = memberId; + } + public String getNodeId() { + return nodeId; + } + public void setNodeId(String nodeId) { + this.nodeId = nodeId; + } + public String getClusterId() { + return clusterId; + } + public void setClusterId(String clusterId) { + this.clusterId = clusterId; + } + public String getCartridgeType() { + return cartridgeType; + } + public void setCartridgeType(String cartridgeType) { + this.cartridgeType = cartridgeType; + } + public Partition getPartition() { + return partition; + } + + public void setPartition(Partition partition) { + this.partition = partition; + } + + public String getPublicIpAddress() { + return publicIpAddress; + } + + public void setPublicIpAddress(String publicIpAddress) { + this.publicIpAddress = publicIpAddress; + } + + public String getPrivateIpAddress() { + return privateIpAddress; + } + + public void setPrivateIpAddress(String privateIpAddress) { + this.privateIpAddress = privateIpAddress; + } + + public String getAllocatedIpAddress() { + return allocatedIpAddress; + } + + public void setAllocatedIpAddress(String allocatedIpAddress) { + this.allocatedIpAddress = allocatedIpAddress; + } + + public long getInitTime() { + return initTime; + } + + public void setInitTime(long initTime) { + this.initTime = initTime; + } + + public String getLbClusterId() { + return lbClusterId; + } + + public void setLbClusterId(String lbClusterId) { + this.lbClusterId = lbClusterId; + } + + + public String getNetworkPartitionId() { + return networkPartitionId; + } + + public void setNetworkPartitionId(String networkPartitionId) { + this.networkPartitionId = networkPartitionId; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((clusterId == null) ? 0 : clusterId.hashCode()); + result = prime * result + + ((memberId == null) ? 0 : memberId.hashCode()); + result = prime * result + ((nodeId == null) ? 0 : nodeId.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + MemberContext other = (MemberContext) obj; + if (clusterId == null) { + if (other.clusterId != null) + return false; + } else if (!clusterId.equals(other.clusterId)) + return false; + if (memberId == null) { + if (other.memberId != null) + return false; + } else if (!memberId.equals(other.memberId)) + return false; + if (nodeId == null) { + if (other.nodeId != null) + return false; + } else if (!nodeId.equals(other.nodeId)) + return false; + return true; + } + + public String getInstanceId() { + return instanceId; + } + + public void setInstanceId(String instanceId) { + this.instanceId = instanceId; + } + + public long getObsoleteExpiryTime() { + return obsoleteExpiryTime; + } + + public void setObsoleteExpiryTime(long obsoleteExpiryTime) { + this.obsoleteExpiryTime = obsoleteExpiryTime; + } + + public long getObsoleteInitTime() { + return obsoleteInitTime; + } + + public void setObsoleteInitTime(long obsoleteInitTime) { + this.obsoleteInitTime = obsoleteInitTime; + } + + public Properties getProperties() { + return properties; + } + + public void setProperties(Properties properties) { + this.properties = properties; + } + + @Override + public String toString() { + return "MemberContext [memberId=" + memberId + ", nodeId=" + nodeId + ", instanceId=" + + instanceId + ", clusterId=" + clusterId + ", partition=" + partition + + ", cartridgeType=" + cartridgeType + ", privateIpAddress=" + privateIpAddress + + ", publicIpAddress=" + publicIpAddress + ", allocatedIpAddress=" + + allocatedIpAddress + ", initTime=" + initTime + ", lbClusterId=" + lbClusterId + + ", networkPartitionId=" + networkPartitionId + ", properties=" + properties + "]"; + } + +}
http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/NetworkInterface.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/NetworkInterface.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/NetworkInterface.java new file mode 100644 index 0000000..4e939b4 --- /dev/null +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/NetworkInterface.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.stratos.cloud.controller.domain; + +import java.io.Serializable; + +public class NetworkInterface implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 3979879787250775211L; + private String networkUuid; + private String fixedIp; + private String portUuid; + + public NetworkInterface() { + } + + public NetworkInterface(String networkUuid, String fixedIp, String portUuid) { + this.networkUuid = networkUuid; + this.fixedIp = fixedIp; + this.portUuid = portUuid; + } + + /** + * @return the networkUuid + */ + public String getNetworkUuid() { + return networkUuid; + } + /** + * @param networkUuid the networkUuid to set + */ + public void setNetworkUuid(String networkUuid) { + this.networkUuid = networkUuid; + } + /** + * @return the fixedIp + */ + public String getFixedIp() { + return fixedIp; + } + /** + * @param fixedIp the fixedIp to set + */ + public void setFixedIp(String fixedIp) { + this.fixedIp = fixedIp; + } + /** + * @return the portUuid + */ + public String getPortUuid() { + return portUuid; + } + /** + * @param portUuid the portUuid to set + */ + public void setPortUuid(String portUuid) { + this.portUuid = portUuid; + } + + public String toString() { + StringBuilder sb = new StringBuilder('{'); + String delimeter = ""; + if (networkUuid != null) { + sb.append(delimeter).append("networkUuid : ").append(networkUuid); + delimeter = ", "; + } + if (fixedIp != null) { + sb.append(delimeter).append("fixedIp : ").append(fixedIp); + delimeter = ", "; + } + if (portUuid != null) { + sb.append(delimeter).append("portUuid : ").append(portUuid); + delimeter = ", "; + } + sb.append('}'); + return sb.toString(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/NetworkInterfaces.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/NetworkInterfaces.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/NetworkInterfaces.java new file mode 100644 index 0000000..1c0b447 --- /dev/null +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/NetworkInterfaces.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.stratos.cloud.controller.domain; + +import java.io.Serializable; +import java.util.Arrays; +/** + * Had to wrap {@link NetworkInterface} array using a class, since there's a bug in current + * stub generation. + * + */ +public class NetworkInterfaces implements Serializable { + + private static final long serialVersionUID = -8435710709813227055L; + private NetworkInterface[] networkInterfaces; + + /** + * @return the networkInterfaces + */ + public NetworkInterface[] getNetworkInterfaces() { + return networkInterfaces; + } + + /** + * @param networkInterfaces the networkInterfaces to set + */ + public void setNetworkInterfaces(NetworkInterface[] networkInterfaces) { + if(networkInterfaces == null) { + this.networkInterfaces = new NetworkInterface[0]; + } else { + this.networkInterfaces = Arrays.copyOf(networkInterfaces, networkInterfaces.length); + } + } + + @Override + public String toString() { + return "NetworkInterfaces [network interfaces=" + Arrays.toString(networkInterfaces) + "]"; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/Partition.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/Partition.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/Partition.java new file mode 100644 index 0000000..c75c05f --- /dev/null +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/Partition.java @@ -0,0 +1,179 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.stratos.cloud.controller.domain; + +import org.apache.stratos.common.Properties; + +import java.io.Serializable; + +/** + * The model class for Partition definition. + */ +public class Partition implements Serializable{ + + private static final long serialVersionUID = 3725971214092010720L; + private int partitionMax; + private int partitionMin; + /** + * provider should match with an IaasProvider type. + */ + private String provider; + private Properties properties = new Properties(); + private String id; + private String description; + private boolean isPublic; + + + /** + * Gets the value of the partitionMax property. + * + */ + public int getPartitionMax() { + return partitionMax; + } + + /** + * Sets the value of the partitionMax property. + * + */ + public void setPartitionMax(int value) { + this.partitionMax = value; + } + + /** + * Gets the value of the partitionMin property. + * + */ + public int getPartitionMin() { + return partitionMin; + } + + /** + * Sets the value of the partitionMin property. + * + */ + public void setPartitionMin(int value) { + this.partitionMin = value; + } + + /** + * Gets the value of the id property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getId() { + return id; + } + + /** + * Sets the value of the id property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setId(String id) { + this.id = id; + } + + /** + * Gets the value of the description property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getDescription() { + return description; + } + + /** + * Sets the value of the description property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * Sets the value of the isPublic property. + * + * @param value + * allowed object is boolean + * + */ + public void setIsPublic(boolean isPublic) { + this.isPublic = isPublic; + } + + /** + * Gets the value of the isPublic property. + * + */ + public boolean getIsPublic() { + return isPublic; + } + + public Properties getProperties() { + return properties; + } + + public void setProperties(Properties properties) { + this.properties = properties; + } + + public String getProvider() { + return provider; + } + + public void setProvider(String provider) { + this.provider = provider; + } + + @Override + public String toString() { + return "Partition [id=" + id + ", description=" + description + ", isPublic=" + isPublic + + ", provider=" + provider + ", partitionMin=" + partitionMin + ", partitionMax=" + + partitionMax + ", properties=" + properties + "]"; + } + + public boolean equals(Object obj) { + if(obj != null && obj instanceof Partition) { + return this.id.equals(((Partition) obj).getId()); + } + return false; + + } + + @Override + public int hashCode() { + return this.id.hashCode(); + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/Persistence.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/Persistence.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/Persistence.java new file mode 100644 index 0000000..ba25de9 --- /dev/null +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/Persistence.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.stratos.cloud.controller.domain; + +import java.io.Serializable; +import java.util.Arrays; + +public class Persistence implements Serializable{ + + private static final long serialVersionUID = 3455721979991902731L; + private boolean persistanceRequired; + private Volume[] volumes; + + public String toString () { + return "Persistence Required: " + isPersistanceRequired(); + } + + public boolean isPersistanceRequired() { + return persistanceRequired; + } + + public void setPersistanceRequired(boolean persistanceRequired) { + this.persistanceRequired = persistanceRequired; + } + + public Volume[] getVolumes() { + return volumes; + } + + public void setVolumes(Volume[] volumes) { + if(volumes == null) { + this.volumes = new Volume[0]; + } else { + this.volumes = Arrays.copyOf(volumes, volumes.length); + } + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/PortMapping.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/PortMapping.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/PortMapping.java new file mode 100644 index 0000000..cedbb49 --- /dev/null +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/PortMapping.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.stratos.cloud.controller.domain; + +import java.io.Serializable; + +public class PortMapping implements Serializable{ + + private static final long serialVersionUID = -5387564414633460306L; + private String protocol; + private String port; + private String proxyPort; + + public PortMapping(){ + + } + + public PortMapping(String protocol, String port, String proxyPort){ + this.protocol = protocol; + this.port = port; + this.proxyPort = proxyPort; + } + + public String getProtocol() { + return protocol; + } + + public void setProtocol(String protocol) { + this.protocol = protocol; + } + + public String getPort() { + return port; + } + + public void setPort(String port) { + this.port = port; + } + + public String getProxyPort() { + return proxyPort; + } + + public void setProxyPort(String proxyPort) { + this.proxyPort = proxyPort; + } + + public String toString () { + + return "Protocol: " + protocol + ", Port: " + port + ", Proxy Port: " + proxyPort; + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/Registrant.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/Registrant.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/Registrant.java new file mode 100644 index 0000000..a751a1f --- /dev/null +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/Registrant.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.stratos.cloud.controller.domain; + +import org.apache.stratos.common.Properties; + +/** + * Upon a new subscription, Stratos Manager would send this POJO. + * + * + */ +public class Registrant { + + private String clusterId; + private String tenantRange; + private String hostName; + private String cartridgeType; + private String payload; + private Properties properties; + private String autoScalerPolicyName; + private String deploymentPolicyName; + private Persistence persistence; + + public String getTenantRange() { + return tenantRange; + } + public void setTenantRange(String tenantRange) { + this.tenantRange = tenantRange; + } + public String getHostName() { + return hostName; + } + public void setHostName(String hostName) { + this.hostName = hostName; + } + public Properties getProperties() { + return properties; + } + public void setProperties(Properties properties) { + this.properties = properties; + } + public String getAutoScalerPolicyName() { + return autoScalerPolicyName; + } + public void setAutoScalerPolicyName(String autoScalerPolicyName) { + this.autoScalerPolicyName = autoScalerPolicyName; + } + public String getClusterId() { + return clusterId; + } + public void setClusterId(String clusterId) { + this.clusterId = clusterId; + } + public String getCartridgeType() { + return cartridgeType; + } + public void setCartridgeType(String cartridgeType) { + this.cartridgeType = cartridgeType; + } + public String getPayload() { + return payload; + } + public void setPayload(String payload) { + this.payload = payload; + } + + public String getDeploymentPolicyName() { + return deploymentPolicyName; + } + + public void setDeploymentPolicyName(String deploymentPolicyName) { + this.deploymentPolicyName = deploymentPolicyName; + } + @Override + public String toString() { + return "Registrant [clusterId=" + clusterId + ", tenantRange=" + tenantRange + + ", hostName=" + hostName + ", cartridgeType=" + cartridgeType + ", properties=" + + properties + ", autoScalerPolicyName=" + autoScalerPolicyName + + ", deploymentPolicyName=" + deploymentPolicyName + "]"; + } + + public Persistence getPersistence() { + return persistence; + } + + public void setPersistence(Persistence persistence) { + this.persistence = persistence; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/ServiceGroup.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/ServiceGroup.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/ServiceGroup.java new file mode 100644 index 0000000..7d9d986 --- /dev/null +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/ServiceGroup.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.stratos.cloud.controller.domain; + +import java.io.Serializable; + +public class ServiceGroup implements Serializable { + + + private static final long serialVersionUID = -7413745300105885793L; + + private String name; + + private String [] subGroups; + + private String [] cartridges; + + private Dependencies dependencies; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String [] getSubGroups() { + return subGroups; + } + + public void setSubGroups(String [] subGroups) { + this.subGroups = subGroups; + } + + public String [] getCartridges() { + return cartridges; + } + + public void setCartridges(String [] cartridges) { + this.cartridges = cartridges; + } + + public Dependencies getDependencies() { + return dependencies; + } + + public void setDependencies(Dependencies dependencies) { + this.dependencies = dependencies; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/TopologyConfig.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/TopologyConfig.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/TopologyConfig.java new file mode 100644 index 0000000..4d88de6 --- /dev/null +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/TopologyConfig.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.stratos.cloud.controller.domain; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +/** + * Configuration related to Topology synchronization + * + */ +public class TopologyConfig implements Serializable{ + + private static final long serialVersionUID = 4435173744617096911L; + + /** + * Key - Value pair. + */ + private Map<String, String> properties = new HashMap<String, String>(); + + public void setProperty(String key, String value) { + properties.put(key, value); + } + + public String getProperty(String key) { + + if(properties.containsKey(key)){ + return properties.get(key); + } + + return null; + } + + public Map<String, String> getProperties() { + return properties; + } + + public void setProperties(Map<String, String> properties) { + this.properties = properties; + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/Volume.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/Volume.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/Volume.java new file mode 100644 index 0000000..8173583 --- /dev/null +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/Volume.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.stratos.cloud.controller.domain; + +import java.io.Serializable; + +public class Volume implements Serializable { + private static final long serialVersionUID = 3455729879991902731L; + + private String id; + private int size; + private String device; + private boolean removeOntermination; + private String mappingPath; + private String iaasType; + private String snapshotId; + private String volumeId; + + public String toString () { + return "Persistence Required: " + ", Size: " + getSize() + ", device: " + getDevice() + + " mapping path : " + mappingPath + " remove on termination " + isRemoveOntermination() + " SnaphotId " + snapshotId; + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + public String getDevice() { + return device; + } + + public void setDevice(String device) { + this.device = device; + } + + public boolean isRemoveOntermination() {return removeOntermination;} + + public void setRemoveOntermination(boolean removeOntermination) { + this.removeOntermination = removeOntermination; + } + + public String getMappingPath() { + return mappingPath; + } + + public void setMappingPath(String mappingPath) { + this.mappingPath = mappingPath; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Volume other = (Volume) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } + + public String getIaasType() { + return iaasType; + } + + public void setIaasType(String iaasType) { + this.iaasType = iaasType; + } + + public String getSnapshotId() { + return snapshotId; + } + + public void setSnapshotId(String snapshotId) { + this.snapshotId = snapshotId; + } + + public String getVolumeId() { + return volumeId; + } + + public void setVolumeId(String volumeId) { + this.volumeId = volumeId; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/payload/MetaDataHolder.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/payload/MetaDataHolder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/payload/MetaDataHolder.java new file mode 100644 index 0000000..a505479 --- /dev/null +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/payload/MetaDataHolder.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.stratos.cloud.controller.domain.payload; + +import java.util.Properties; + +/** + * Holds payload/meta data related to a cluster + */ + +public class MetaDataHolder { + + private String appId; + + private String groupName; + + private String clusterId; + + private Properties properties; + + public MetaDataHolder (String appId, String clusterId) { + + this.appId = appId; + this.clusterId = clusterId; + } + + public MetaDataHolder(String appId, String groupName, String clusterId) { + + this.appId = appId; + this.groupName = groupName; + this.clusterId = clusterId; + } + + public String getAppId() { + return appId; + } + + public String getGroupName() { + return groupName; + } + + public String getClusterId() { + return clusterId; + } + + public boolean equals(Object other) { + + if(other == null || !(other instanceof MetaDataHolder)) { + return false; + } + + if(this == other) { + return true; + } + + MetaDataHolder that = (MetaDataHolder)other; + + if (this.groupName == null || that.groupName == null) { + return this.appId.equals(that.appId) && this.clusterId.equals(that.clusterId); + } else { + return this.appId.equals(that.appId) && this.groupName.equals(that.groupName) && + this.clusterId.equals(that.clusterId); + } + } + + public int hashCode () { + + if (this.getGroupName() == null) { + return this.appId.hashCode() + this.clusterId.hashCode(); + } else { + return this.appId.hashCode() + this.groupName.hashCode() + this.clusterId.hashCode(); + } + } + + public Properties getProperties() { + return properties; + } + + public void setProperties(Properties properties) { + this.properties = properties; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/ContainerClusterContextToKubernetesContainer.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/ContainerClusterContextToKubernetesContainer.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/ContainerClusterContextToKubernetesContainer.java index cda9a89..ab6c06f 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/ContainerClusterContextToKubernetesContainer.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/ContainerClusterContextToKubernetesContainer.java @@ -23,11 +23,11 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.pojo.Cartridge; -import org.apache.stratos.cloud.controller.pojo.ClusterContext; -import org.apache.stratos.cloud.controller.pojo.ContainerClusterContext; -import org.apache.stratos.cloud.controller.pojo.PortMapping; -import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder; +import org.apache.stratos.cloud.controller.domain.Cartridge; +import org.apache.stratos.cloud.controller.domain.ClusterContext; +import org.apache.stratos.cloud.controller.domain.ContainerClusterContext; +import org.apache.stratos.cloud.controller.domain.PortMapping; +import org.apache.stratos.cloud.controller.context.FasterLookUpDataHolder; import org.apache.stratos.cloud.controller.util.CloudControllerUtil; import org.apache.stratos.common.Properties; import org.apache.stratos.common.Property; http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/ContainerClusterContextToKubernetesService.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/ContainerClusterContextToKubernetesService.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/ContainerClusterContextToKubernetesService.java index 61fe0ee..f1c7c02 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/ContainerClusterContextToKubernetesService.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/ContainerClusterContextToKubernetesService.java @@ -18,10 +18,10 @@ */ package org.apache.stratos.cloud.controller.functions; -import org.apache.stratos.cloud.controller.pojo.ClusterContext; -import org.apache.stratos.cloud.controller.pojo.ContainerClusterContext; -import org.apache.stratos.cloud.controller.pojo.KubernetesClusterContext; -import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder; +import org.apache.stratos.cloud.controller.domain.ClusterContext; +import org.apache.stratos.cloud.controller.domain.ContainerClusterContext; +import org.apache.stratos.cloud.controller.domain.KubernetesClusterContext; +import org.apache.stratos.cloud.controller.context.FasterLookUpDataHolder; import org.apache.stratos.cloud.controller.util.CloudControllerUtil; import org.apache.stratos.common.constants.StratosConstants; import org.apache.stratos.kubernetes.client.model.Selector; http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/ContainerClusterContextToReplicationController.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/ContainerClusterContextToReplicationController.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/ContainerClusterContextToReplicationController.java index a60fd5c..e1a5df7 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/ContainerClusterContextToReplicationController.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/ContainerClusterContextToReplicationController.java @@ -18,9 +18,9 @@ */ package org.apache.stratos.cloud.controller.functions; -import org.apache.stratos.cloud.controller.pojo.ClusterContext; -import org.apache.stratos.cloud.controller.pojo.ContainerClusterContext; -import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder; +import org.apache.stratos.cloud.controller.domain.ClusterContext; +import org.apache.stratos.cloud.controller.domain.ContainerClusterContext; +import org.apache.stratos.cloud.controller.context.FasterLookUpDataHolder; import org.apache.stratos.cloud.controller.util.CloudControllerUtil; import org.apache.stratos.common.constants.StratosConstants; import org.apache.stratos.kubernetes.client.model.Container; http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/PodToMemberContext.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/PodToMemberContext.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/PodToMemberContext.java index 29987cc..c6e920d 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/PodToMemberContext.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/PodToMemberContext.java @@ -18,7 +18,7 @@ */ package org.apache.stratos.cloud.controller.functions; -import org.apache.stratos.cloud.controller.pojo.MemberContext; +import org.apache.stratos.cloud.controller.domain.MemberContext; import org.apache.stratos.kubernetes.client.model.Pod; import com.google.common.base.Function; http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/hector/CassandraDataRetriever.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/hector/CassandraDataRetriever.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/hector/CassandraDataRetriever.java deleted file mode 100644 index a754e2f..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/hector/CassandraDataRetriever.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.stratos.cloud.controller.hector; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.apache.stratos.cloud.controller.exception.CloudControllerException; -import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.util.CloudControllerConstants; - -import me.prettyprint.cassandra.model.BasicColumnDefinition; -import me.prettyprint.cassandra.model.BasicColumnFamilyDefinition; -import me.prettyprint.cassandra.model.CqlQuery; -import me.prettyprint.cassandra.model.CqlRows; -import me.prettyprint.cassandra.serializers.StringSerializer; -import me.prettyprint.cassandra.service.CassandraHostConfigurator; -import me.prettyprint.cassandra.service.ThriftCfDef; -import me.prettyprint.hector.api.Cluster; -import me.prettyprint.hector.api.Keyspace; -import me.prettyprint.hector.api.beans.HColumn; -import me.prettyprint.hector.api.beans.Row; -import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition; -import me.prettyprint.hector.api.ddl.ColumnIndexType; -import me.prettyprint.hector.api.ddl.ComparatorType; -import me.prettyprint.hector.api.ddl.KeyspaceDefinition; -import me.prettyprint.hector.api.factory.HFactory; -import me.prettyprint.hector.api.query.QueryResult; - -public class CassandraDataRetriever { - - private static final Log log = LogFactory.getLog(CassandraDataRetriever.class); - private static FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance(); - private final static StringSerializer se = StringSerializer.get(); - private static Cluster cluster; - private static Keyspace keyspace; - private static boolean isInit; - - public static void init() { - - if(isInit){ - return; - } - getCassandraKeyspace(); - indexCounterColumn("payload_status"); - isInit = true; - } - - public static void connect() { - - if(keyspace == null){ - handleException("Cannot find the key space."); - } - - String colFamily = CloudControllerConstants.CLOUD_CONTROLLER_COL_FAMILY; - - CqlQuery<String,String,String> cqlQuery = new CqlQuery<String,String,String>(keyspace, se, se, se); - cqlQuery.setQuery("select payload_nodeId from "+colFamily+" where payload_status='RUNNING'"); -// cqlQuery.setQuery("select * from "+colFamily+" where payload_domain='nirmal'"); - QueryResult<CqlRows<String,String,String>> result = cqlQuery.execute(); - - if (result != null && result.get() != null) { - List<Row<String, String, String>> list = result.get().getList(); - for (Row<?, ?, ?> row : list) { - System.out.println("."); - List<?> columns = row.getColumnSlice().getColumns(); - for (Iterator<?> iterator = columns.iterator(); iterator.hasNext();) { - HColumn<?, ?> column = (HColumn<?, ?>) iterator.next(); - System.out.print(column.getName() + ":" + column.getValue() - + "\t"); - } - System.out.println(""); - } - } - -// ColumnQuery<String, String, String> columnQuery = -// HFactory.createStringColumnQuery(keyspace); -// KeyIterator<String> keyIterator = new KeyIterator<String>(keyspace, colFamily, StringSerializer.get()); -// for ( String key : keyIterator ) { -// -// columnQuery.setColumnFamily(colFamily).setKey(key).setName("payload_nodeId"); -// QueryResult<HColumn<String, String>> result = columnQuery.execute(); -// HColumn<String, String> hColumn = result.get(); -// System.out.println("Column: " + hColumn.getName() + " Value : " + hColumn.getValue() + "\n"); -// } - -// //Read Data -// for (String key : keyList) { -// System.out.println("\nretrieving Key " + rowKey + "From Column Family " + columnFamily + "\n"); -// for (String columnName : columnList.split(":")) { -// //sout data -// } -// } - - - } - - private static void indexCounterColumn(String idxColumnName) { - - KeyspaceDefinition keyspaceDefinition = cluster.describeKeyspace(CloudControllerConstants.DEFAULT_CASSANDRA_KEY_SPACE); - - List<ColumnFamilyDefinition> cdfs = keyspaceDefinition.getCfDefs(); - ColumnFamilyDefinition cfd = null; - for (ColumnFamilyDefinition c : cdfs) { - if (c.getName().equals(CloudControllerConstants.CLOUD_CONTROLLER_COL_FAMILY)) { - System.out.println(c.getName()); - cfd = c; - break; - } - } - - BasicColumnFamilyDefinition columnFamilyDefinition = new BasicColumnFamilyDefinition(cfd); - - BasicColumnDefinition bcdf = new BasicColumnDefinition(); - bcdf.setName(StringSerializer.get().toByteBuffer(idxColumnName)); - bcdf.setIndexName(idxColumnName + "index"); - bcdf.setIndexType(ColumnIndexType.KEYS); - bcdf.setValidationClass(ComparatorType.UTF8TYPE.getClassName()); - - columnFamilyDefinition.addColumnDefinition(bcdf); - cluster.updateColumnFamily(new ThriftCfDef(columnFamilyDefinition)); - - } - - private static void getCassandraKeyspace() { - if (cluster == null) { - Map<String, String> credentials = new HashMap<String, String>(); - credentials.put("username", dataHolder.getDataPubConfig().getCassandraUser()); - credentials.put("password", dataHolder.getDataPubConfig().getCassandraPassword()); - - cluster = - retrieveCassandraCluster(CloudControllerConstants.DEFAULT_CASSANDRA_CLUSTER_NAME, - dataHolder.getDataPubConfig().getCassandraConnUrl(), credentials); - - keyspace = - HFactory.createKeyspace(CloudControllerConstants.DEFAULT_CASSANDRA_KEY_SPACE, - cluster); - } - - } - - private static Cluster retrieveCassandraCluster(String clusterName, String connectionUrl, - Map<String, String> credentials) { - - CassandraHostConfigurator hostConfigurator = new CassandraHostConfigurator(connectionUrl); - hostConfigurator.setRetryDownedHosts(false); - Cluster cluster = HFactory.createCluster(clusterName, hostConfigurator, credentials); - return cluster; - } - - private static void handleException(String msg) { - - log.error(msg); - throw new CloudControllerException(msg); - } - -// private void handleException(String msg, Exception e) { -// -// log.error(msg, e); -// throw new AutoscalerServiceException(msg, e); -// } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/hive/HiveQueryExecutor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/hive/HiveQueryExecutor.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/hive/HiveQueryExecutor.java deleted file mode 100644 index e3bce02..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/hive/HiveQueryExecutor.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.stratos.cloud.controller.hive; - -import org.apache.axis2.AxisFault; -import org.apache.axis2.client.Options; -import org.apache.axis2.client.ServiceClient; -import org.apache.axis2.transport.http.HttpTransportProperties; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.exception.CloudControllerException; -import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder; -import org.apache.stratos.cloud.controller.util.CloudControllerConstants; -import org.wso2.carbon.analytics.hive.stub.HiveExecutionServiceHiveExecutionException; -import org.wso2.carbon.analytics.hive.stub.HiveExecutionServiceStub; -import org.wso2.carbon.analytics.hive.stub.HiveExecutionServiceStub.QueryResult; -import org.wso2.carbon.analytics.hive.stub.HiveExecutionServiceStub.QueryResultRow; -import org.wso2.carbon.base.ServerConfiguration; -import org.wso2.carbon.utils.CarbonUtils; - -import java.rmi.RemoteException; -import java.util.ArrayList; -import java.util.List; - -public class HiveQueryExecutor { - private static final Log log = LogFactory.getLog(HiveQueryExecutor.class); - private HiveExecutionServiceStub hiveService; - private String payloadPrefix = CloudControllerConstants.PAYLOAD_PREFIX; - private String hiveTable = "cloudController"; - private FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance(); - - public HiveQueryExecutor() { - - ServerConfiguration serverConfig = CarbonUtils.getServerConfiguration(); - String bamServerUrl = serverConfig.getFirstProperty("BamServerURL"); - String serviceName = "HiveExecutionService"; - HttpTransportProperties.Authenticator authenticator; - - try { - hiveService = new HiveExecutionServiceStub(bamServerUrl+"/services/"+serviceName); - - // admin service authentication - authenticator = new HttpTransportProperties.Authenticator(); - authenticator.setUsername(dataHolder.getDataPubConfig().getBamUsername()); - authenticator.setPassword(dataHolder.getDataPubConfig().getBamPassword()); - authenticator.setPreemptiveAuthentication(true); - - ServiceClient client = hiveService._getServiceClient(); - Options option = client.getOptions(); - option.setManageSession(true); - option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, authenticator); - option.setTimeOutInMilliSeconds(120000); - - } catch (AxisFault e) { - String msg = "Cannot get a connection to "+serviceName; - handleException(msg, e); - } - } - - public QueryResult[] execute(String query){ - try { - return hiveService.executeHiveScript(query); - } catch (RemoteException e) { - handleException("Query : '"+query+"' - "+e.getMessage(), e); - } catch (HiveExecutionServiceHiveExecutionException e) { - handleException("Query : '"+query+"' - "+e.getMessage(), e); - } - - return new QueryResult[0]; - } - - public void createHiveTable(){ - String query = - "CREATE EXTERNAL TABLE IF NOT EXISTS "+hiveTable+" (id STRING, " + - payloadPrefix+CloudControllerConstants.MEMBER_ID_COL +" STRING," + - payloadPrefix+CloudControllerConstants.CARTRIDGE_TYPE_COL+" STRING," + - payloadPrefix+CloudControllerConstants.CLUSTER_ID_COL +" STRING," + - payloadPrefix+CloudControllerConstants.LB_CLUSTER_ID_COL +" STRING," + - payloadPrefix+CloudControllerConstants.PARTITION_ID_COL +" STRING," + - payloadPrefix+CloudControllerConstants.NETWORK_ID_COL +" STRING," + - payloadPrefix+CloudControllerConstants.HOST_NAME_COL+" STRING," + - payloadPrefix+CloudControllerConstants.HYPERVISOR_COL+" STRING," + - payloadPrefix+CloudControllerConstants.IAAS_COL+" STRING," + - payloadPrefix+CloudControllerConstants.IMAGE_ID_COL+" STRING," + - payloadPrefix+CloudControllerConstants.LOGIN_PORT_COL+" STRING," + - payloadPrefix+CloudControllerConstants.PRIV_IP_COL+" STRING," + - payloadPrefix+CloudControllerConstants.PUB_IP_COL+" STRING," + - payloadPrefix+CloudControllerConstants.STATUS_COL+" STRING," + - ") STORED BY 'org.apache.hadoop.hive.cassandra.CassandraStorageHandler' " + - "WITH SERDEPROPERTIES ( \"cassandra.host\" = \""+dataHolder.getDataPubConfig().getCassandraConnUrl().split(":")[0]+"\"," + - "\"cassandra.port\" = \""+dataHolder.getDataPubConfig().getCassandraConnUrl().split(":")[1]+ - "\",\"cassandra.ks.name\" = \""+CloudControllerConstants.DEFAULT_CASSANDRA_KEY_SPACE+"\"," + - "\"cassandra.ks.username\" = \""+dataHolder.getDataPubConfig().getCassandraUser()+ - "\", \"cassandra.ks.password\" = \""+dataHolder.getDataPubConfig().getCassandraPassword()+"\"," + - "\"cassandra.cf.name\" = \""+CloudControllerConstants.CLOUD_CONTROLLER_COL_FAMILY+"\"," + - "\"cassandra.columns.mapping\" = \"" + - payloadPrefix+CloudControllerConstants.MEMBER_ID_COL +"," + - payloadPrefix+CloudControllerConstants.CARTRIDGE_TYPE_COL+"," + - payloadPrefix+CloudControllerConstants.CLUSTER_ID_COL +"," + - payloadPrefix+CloudControllerConstants.LB_CLUSTER_ID_COL +" STRING," + - payloadPrefix+CloudControllerConstants.PARTITION_ID_COL +" STRING," + - payloadPrefix+CloudControllerConstants.NETWORK_ID_COL +" STRING," + - payloadPrefix+CloudControllerConstants.HOST_NAME_COL+"," + - payloadPrefix+CloudControllerConstants.HYPERVISOR_COL+"," + - payloadPrefix+CloudControllerConstants.IAAS_COL+"," + - payloadPrefix+CloudControllerConstants.IMAGE_ID_COL+"," + - payloadPrefix+CloudControllerConstants.LOGIN_PORT_COL+"," + - payloadPrefix+CloudControllerConstants.PRIV_IP_COL+"," + - payloadPrefix+CloudControllerConstants.PUB_IP_COL+"," + - payloadPrefix+CloudControllerConstants.STATUS_COL+"," + - "\");"; - - execute(query); - } - - public List<String> getRunningNodeIds() { - List<String> nodeIds = new ArrayList<String>(); - String query = -// "select " + payloadPrefix + AutoscalerConstant.MEMBER_ID_COL + " from " + -// hiveTable + " where payload_status='RUNNING' OR payload_status='PENDING' ;"; - -// "select id1 from (select distinct payload_nodeId from cloud1 where payload_status='RUNNING' OR payload_status='PENDING') table1 -//LEFT OUTER JOIN -//(select distinct payload_nodeId as nodeId from cloud1 where payload_status='TERMINATED') table2 -//ON(table2.nodeId = table1.payload_nodeId) -//where table2.nodeId is null;"; - "select table1.id1 from (select distinct "+payloadPrefix+CloudControllerConstants.MEMBER_ID_COL + - " as id1 from "+ hiveTable +" where "+payloadPrefix+CloudControllerConstants.STATUS_COL+ - "='RUNNING' OR "+payloadPrefix+CloudControllerConstants.STATUS_COL+"='PENDING') table1 " + - "LEFT OUTER JOIN " +"(select distinct "+payloadPrefix+CloudControllerConstants.MEMBER_ID_COL + - " as id2 from "+hiveTable+" where "+payloadPrefix+CloudControllerConstants.STATUS_COL+"='TERMINATED') table2 " + - "ON(table1.id1 = table2.id2) where table2.id2 is null;"; - - QueryResult[] result = execute(query); - - for (QueryResult queryResult : result) { - if(queryResult == null || queryResult.getResultRows() == null){ - continue; - } - for (QueryResultRow row : queryResult.getResultRows()) { - if (row != null && row.getColumnValues() != null && row.getColumnValues().length != 0) { - nodeIds.add(row.getColumnValues()[0]); - } - } - } - - return nodeIds; - - } - - private void handleException(String msg, Exception e){ - log.error(msg, e); - throw new CloudControllerException(msg, e); - } - -}
