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/pojo/NetworkInterfaces.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/NetworkInterfaces.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/NetworkInterfaces.java deleted file mode 100644 index 1b7908c..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/NetworkInterfaces.java +++ /dev/null @@ -1,55 +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.pojo; - -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/pojo/Persistence.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/Persistence.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/Persistence.java deleted file mode 100644 index 128efbf..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/Persistence.java +++ /dev/null @@ -1,53 +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.pojo; - -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/pojo/PortMapping.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/PortMapping.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/PortMapping.java deleted file mode 100644 index 63e222b..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/PortMapping.java +++ /dev/null @@ -1,69 +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.pojo; - -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/pojo/Registrant.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/Registrant.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/Registrant.java deleted file mode 100644 index e53e95f..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/Registrant.java +++ /dev/null @@ -1,105 +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.pojo; - -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/pojo/ServiceGroup.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ServiceGroup.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ServiceGroup.java deleted file mode 100644 index 45957f5..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ServiceGroup.java +++ /dev/null @@ -1,69 +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.pojo; - -import java.io.Serializable; -import java.util.List; - -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/pojo/TopologyConfig.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/TopologyConfig.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/TopologyConfig.java deleted file mode 100644 index 2d309a1..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/TopologyConfig.java +++ /dev/null @@ -1,59 +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.pojo; - -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/pojo/Volume.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/Volume.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/Volume.java deleted file mode 100644 index b5e3b29..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/Volume.java +++ /dev/null @@ -1,126 +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.pojo; - -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/pojo/payload/MetaDataHolder.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/payload/MetaDataHolder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/payload/MetaDataHolder.java deleted file mode 100644 index 3db9f71..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/payload/MetaDataHolder.java +++ /dev/null @@ -1,99 +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.pojo.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/publisher/CartridgeInstanceDataPublisher.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/publisher/CartridgeInstanceDataPublisher.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/publisher/CartridgeInstanceDataPublisher.java deleted file mode 100644 index ad3c26f..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/publisher/CartridgeInstanceDataPublisher.java +++ /dev/null @@ -1,213 +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.publisher; - -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.pojo.Cartridge; -import org.apache.stratos.cloud.controller.pojo.MemberContext; -import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder; -import org.apache.stratos.cloud.controller.util.CloudControllerConstants; -import org.jclouds.compute.domain.NodeMetadata; -import org.wso2.carbon.base.ServerConfiguration; -import org.wso2.carbon.databridge.agent.thrift.AsyncDataPublisher; -import org.wso2.carbon.databridge.agent.thrift.exception.AgentException; -import org.wso2.carbon.databridge.commons.Attribute; -import org.wso2.carbon.databridge.commons.AttributeType; -import org.wso2.carbon.databridge.commons.Event; -import org.wso2.carbon.databridge.commons.StreamDefinition; -import org.wso2.carbon.utils.CarbonUtils; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -/** - * This will publish the state changes of a node in the topology to a data receiver - */ -public class CartridgeInstanceDataPublisher { - - private static final Log log = LogFactory.getLog(CartridgeInstanceDataPublisher.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, - NodeMetadata metadata) { - if(!FasterLookUpDataHolder.getInstance().getEnableBAMDataPublisher()){ - 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 = FasterLookUpDataHolder.getInstance().getMemberContextOfMemberId(memberId); - String cartridgeType = memberContext.getCartridgeType(); - Cartridge cartridge = FasterLookUpDataHolder.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.getHardware().getHypervisor()); - payload.add(String.valueOf(metadata.getHardware().getRam())); - payload.add(metadata.getImageId()); - payload.add(metadata.getLoginPort()); - payload.add(metadata.getOperatingSystem().getName()); - payload.add(metadata.getOperatingSystem().getVersion()); - payload.add(metadata.getOperatingSystem().getArch()); - payload.add(String.valueOf(metadata.getOperatingSystem().is64Bit())); - } else { - payload.add(""); - payload.add(""); - payload.add(""); - payload.add(""); - payload.add(0); - payload.add(""); - payload.add(""); - payload.add(""); - payload.add(""); - } - - payload.add(handleNull(memberContext.getPrivateIpAddress())); - payload.add(handleNull(memberContext.getPublicIpAddress())); - payload.add(handleNull(memberContext.getAllocatedIpAddress())); - - 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(){ - FasterLookUpDataHolder.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 = FasterLookUpDataHolder.getInstance().getDataPubConfig().getBamUsername(); - String adminPassword = FasterLookUpDataHolder.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); - FasterLookUpDataHolder.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; - } - - -} 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/publisher/TopologySynchronizerTaskScheduler.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/publisher/TopologySynchronizerTaskScheduler.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/publisher/TopologySynchronizerTaskScheduler.java deleted file mode 100644 index 398dc1f..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/publisher/TopologySynchronizerTaskScheduler.java +++ /dev/null @@ -1,82 +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.publisher; - -import java.util.HashMap; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder; -import org.apache.stratos.cloud.controller.topology.TopologySynchronizerTask; -import org.apache.stratos.cloud.controller.util.CloudControllerConstants; -import org.wso2.carbon.ntask.common.TaskException; -import org.wso2.carbon.ntask.core.TaskInfo; -import org.wso2.carbon.ntask.core.TaskManager; -import org.wso2.carbon.ntask.core.service.TaskService; - -/** - * Topology synchronizer task scheduler for scheduling the topology synchronizer task - * using carbon task service. - */ -public class TopologySynchronizerTaskScheduler { - - private static final Log log = LogFactory.getLog(TopologySynchronizerTaskScheduler.class); - - private static final FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance(); - - public static void schedule(TaskService taskService) { - TaskManager taskManager = null; - try { - - if (!taskService.getRegisteredTaskTypes().contains(CloudControllerConstants.TOPOLOGY_SYNC_TASK_TYPE)) { - // Register task type - taskService.registerTaskType(CloudControllerConstants.TOPOLOGY_SYNC_TASK_TYPE); - - // Register task - taskManager = taskService.getTaskManager(CloudControllerConstants.TOPOLOGY_SYNC_TASK_TYPE); - String cronProp = dataHolder.getTopologyConfig().getProperty(CloudControllerConstants.CRON_PROPERTY); - String cron = cronProp != null ? cronProp :CloudControllerConstants.TOPOLOGY_SYNC_CRON ; - TaskInfo.TriggerInfo triggerInfo = new TaskInfo.TriggerInfo(cron); - TaskInfo taskInfo = new TaskInfo(CloudControllerConstants.TOPOLOGY_SYNC_TASK_NAME, - TopologySynchronizerTask.class.getName(), - new HashMap<String, String>(), triggerInfo); - taskManager.registerTask(taskInfo); - if(log.isDebugEnabled()) { - log.debug(String.format("Topology synchronization task scheduled: %s", CloudControllerConstants.TOPOLOGY_SYNC_TASK_NAME)); - } - } - - } catch (Exception e) { - if (taskManager != null) { - try { - taskManager.deleteTask(CloudControllerConstants.TOPOLOGY_SYNC_TASK_NAME); - } catch (TaskException te) { - if (log.isErrorEnabled()) { - log.error(te); - } - } - } - - String msg = String.format("Could not schedule topology synchronization task: %s", CloudControllerConstants.TOPOLOGY_SYNC_TASK_NAME); - log.error(msg, e); - throw new RuntimeException(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/receiver/application/ApplicationTopicReceiver.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/receiver/application/ApplicationTopicReceiver.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/receiver/application/ApplicationTopicReceiver.java deleted file mode 100644 index 4ad51cc..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/receiver/application/ApplicationTopicReceiver.java +++ /dev/null @@ -1,81 +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.receiver.application; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.topology.TopologyBuilder; -import org.apache.stratos.messaging.event.Event; -import org.apache.stratos.messaging.event.applications.ApplicationTerminatedEvent; -import org.apache.stratos.messaging.listener.applications.ApplicationTerminatedEventListener; -import org.apache.stratos.messaging.message.receiver.applications.ApplicationsEventReceiver; - -/** - * This is to receive the application topic messages. - */ -public class ApplicationTopicReceiver implements Runnable{ - private static final Log log = LogFactory.getLog(ApplicationTopicReceiver.class); - private ApplicationsEventReceiver applicationsEventReceiver; - private boolean terminated; - - public ApplicationTopicReceiver() { - this.applicationsEventReceiver = new ApplicationsEventReceiver(); - addEventListeners(); - - } - - - @Override - public void run() { - - if (log.isInfoEnabled()) { - log.info("Cloud controller application status thread started"); - } - Thread thread = new Thread(applicationsEventReceiver); - thread.start(); - - // Keep the thread live until terminated - while (!terminated) { - try { - Thread.sleep(1000); - } catch (InterruptedException ignore) { - } - } - if (log.isInfoEnabled()) { - log.info("Cloud controller application status thread terminated"); - } - - } - private void addEventListeners() { - applicationsEventReceiver.addEventListener(new ApplicationTerminatedEventListener() { - @Override - protected void onEvent(Event event) { - //Remove the application related data - ApplicationTerminatedEvent terminatedEvent = (ApplicationTerminatedEvent)event; - log.info("ApplicationTerminatedEvent received for [application] " + terminatedEvent.getAppId()); - String appId = terminatedEvent.getAppId(); - TopologyBuilder.handleApplicationClustersRemoved(appId, terminatedEvent.getClusterData()); - } - }); - } - - public void setTerminated(boolean terminated) { - this.terminated = terminated; - } -} 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/receiver/cluster/status/ClusterStatusTopicReceiver.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/receiver/cluster/status/ClusterStatusTopicReceiver.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/receiver/cluster/status/ClusterStatusTopicReceiver.java deleted file mode 100644 index f89434b..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/receiver/cluster/status/ClusterStatusTopicReceiver.java +++ /dev/null @@ -1,114 +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.receiver.cluster.status; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.topology.TopologyBuilder; -import org.apache.stratos.messaging.event.Event; -import org.apache.stratos.messaging.event.cluster.status.*; -import org.apache.stratos.messaging.listener.cluster.status.*; -import org.apache.stratos.messaging.message.receiver.cluster.status.ClusterStatusEventReceiver; - -public class ClusterStatusTopicReceiver implements Runnable{ - private static final Log log = LogFactory.getLog(ClusterStatusTopicReceiver.class); - - private ClusterStatusEventReceiver statusEventReceiver; - private boolean terminated; - - public ClusterStatusTopicReceiver() { - this.statusEventReceiver = new ClusterStatusEventReceiver(); - addEventListeners(); - } - - public void run() { - Thread thread = new Thread(statusEventReceiver); - thread.start(); - if (log.isInfoEnabled()) { - log.info("Cloud controller Cluster status thread started"); - } - - // Keep the thread live until terminated - while (!terminated) { - try { - Thread.sleep(1000); - } catch (InterruptedException ignore) { - } - } - if (log.isInfoEnabled()) { - log.info("Cloud controller application status thread terminated"); - } - - } - private void addEventListeners() { - // Listen to topology events that affect clusters - statusEventReceiver.addEventListener(new ClusterStatusClusterResetEventListener() { - @Override - protected void onEvent(Event event) { - TopologyBuilder.handleClusterReset((ClusterStatusClusterResetEvent) event); - } - }); - - statusEventReceiver.addEventListener(new ClusterStatusClusterInstanceCreatedEventListener() { - @Override - protected void onEvent(Event event) { - //TopologyBuilder.handleClusterInstanceCreated((ClusterStatusClusterInstanceCreatedEvent) event); - } - }); - - statusEventReceiver.addEventListener(new ClusterStatusClusterCreatedEventListener() { - @Override - protected void onEvent(Event event) { - TopologyBuilder.handleClusterCreated((ClusterStatusClusterCreatedEvent) event); - } - }); - - statusEventReceiver.addEventListener(new ClusterStatusClusterActivatedEventListener() { - @Override - protected void onEvent(Event event) { - TopologyBuilder.handleClusterActivatedEvent((ClusterStatusClusterActivatedEvent) event); - } - }); - - statusEventReceiver.addEventListener(new ClusterStatusClusterTerminatedEventListener() { - @Override - protected void onEvent(Event event) { - TopologyBuilder.handleClusterTerminatedEvent((ClusterStatusClusterTerminatedEvent) event); - } - }); - - statusEventReceiver.addEventListener(new ClusterStatusClusterTerminatingEventListener() { - @Override - protected void onEvent(Event event) { - TopologyBuilder.handleClusterTerminatingEvent((ClusterStatusClusterTerminatingEvent) event); - } - }); - - statusEventReceiver.addEventListener(new ClusterStatusClusterInactivateEventListener() { - @Override - protected void onEvent(Event event) { - TopologyBuilder.handleClusterInActivateEvent((ClusterStatusClusterInactivateEvent) event); - } - }); - } - - public void setTerminated(boolean terminated) { - this.terminated = terminated; - } -} 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/receiver/instance/status/InstanceStatusTopicReceiver.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/receiver/instance/status/InstanceStatusTopicReceiver.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/receiver/instance/status/InstanceStatusTopicReceiver.java deleted file mode 100644 index c659fdb..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/receiver/instance/status/InstanceStatusTopicReceiver.java +++ /dev/null @@ -1,113 +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.receiver.instance.status; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.exception.InvalidCartridgeTypeException; -import org.apache.stratos.cloud.controller.exception.InvalidMemberException; -import org.apache.stratos.cloud.controller.topology.TopologyBuilder; -import org.apache.stratos.messaging.event.Event; -import org.apache.stratos.messaging.event.instance.status.InstanceActivatedEvent; -import org.apache.stratos.messaging.event.instance.status.InstanceMaintenanceModeEvent; -import org.apache.stratos.messaging.event.instance.status.InstanceReadyToShutdownEvent; -import org.apache.stratos.messaging.event.instance.status.InstanceStartedEvent; -import org.apache.stratos.messaging.listener.instance.status.InstanceActivatedEventListener; -import org.apache.stratos.messaging.listener.instance.status.InstanceMaintenanceListener; -import org.apache.stratos.messaging.listener.instance.status.InstanceReadyToShutdownEventListener; -import org.apache.stratos.messaging.listener.instance.status.InstanceStartedEventListener; -import org.apache.stratos.messaging.message.receiver.instance.status.InstanceStatusEventReceiver; - -/** - * This will handle the instance status events - */ -public class InstanceStatusTopicReceiver implements Runnable { - private static final Log log = LogFactory.getLog(InstanceStatusTopicReceiver.class); - - private InstanceStatusEventReceiver statusEventReceiver; - private boolean terminated; - - public InstanceStatusTopicReceiver() { - this.statusEventReceiver = new InstanceStatusEventReceiver(); - addEventListeners(); - } - - - @Override - public void run() { - Thread thread = new Thread(statusEventReceiver); - thread.start(); - if (log.isInfoEnabled()) { - log.info("Cloud controller application status thread started"); - } - ///* Keep the thread live until terminated - while (!terminated) { - try { - Thread.sleep(1000); - } catch (InterruptedException ignore) { - } - } - if (log.isInfoEnabled()) { - log.info("Cloud controller application status thread terminated"); - } - } - - private void addEventListeners() { - statusEventReceiver.addEventListener(new InstanceActivatedEventListener() { - @Override - protected void onEvent(Event event) { - TopologyBuilder.handleMemberActivated((InstanceActivatedEvent) event); - } - }); - - statusEventReceiver.addEventListener(new InstanceStartedEventListener() { - @Override - protected void onEvent(Event event) { - TopologyBuilder.handleMemberStarted((InstanceStartedEvent) event); - } - }); - - statusEventReceiver.addEventListener(new InstanceReadyToShutdownEventListener() { - @Override - protected void onEvent(Event event) { - try { - TopologyBuilder.handleMemberReadyToShutdown((InstanceReadyToShutdownEvent) event); - } catch (Exception e) { - String error = "Failed to retrieve the instance status event message"; - log.error(error, e); - } - } - }); - - statusEventReceiver.addEventListener(new InstanceMaintenanceListener() { - @Override - protected void onEvent(Event event) { - try { - TopologyBuilder.handleMemberMaintenance((InstanceMaintenanceModeEvent) event); - } catch (Exception e) { - String error = "Failed to retrieve the instance status event message"; - log.error(error, 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/registry/Deserializer.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/registry/Deserializer.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/registry/Deserializer.java new file mode 100644 index 0000000..bd386e9 --- /dev/null +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/registry/Deserializer.java @@ -0,0 +1,96 @@ +/* + * 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.registry; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectInputStream; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class Deserializer { + + private static final Log log = LogFactory.getLog(Deserializer.class); + + /** + * We deserialize only if the path to the serialized object file is exists. + * @param filePath path to the serialized object file + * @return the object obtained after deserialization or null if file isn't valid. + * @throws Exception + */ + public static Object deserialize(String filePath) throws Exception { + + ObjectInputStream objIn = null; + Object obj = null; + + if(!new File(filePath).isFile()){ + return obj; + } + + try { + + objIn = new ObjectInputStream(new FileInputStream(filePath)); + obj = objIn.readObject(); + + } catch (IOException e) { + log.error("Failed to deserialize the file at "+filePath , e); + throw e; + + } catch (ClassNotFoundException e) { + log.error("Failed to deserialize the file at "+filePath , e); + throw e; + + } finally { + if (objIn != null) { + objIn.close(); + } + } + + return obj; + + } + + /** + * Deserialize a byte array and retrieve the object. + * @param bytes bytes to be deserialized + * @return the deserialized {@link Object} + * @throws Exception if the deserialization is failed. + */ + public static Object deserializeFromByteArray(byte[] bytes) throws Exception { + + ByteArrayInputStream bis = new ByteArrayInputStream(bytes); + ObjectInput in = null; + try { + in = new ObjectInputStream(bis); + Object o = in.readObject(); + + return o; + + } finally { + bis.close(); + if (in != null) { + in.close(); + } + } + } + +} 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/registry/RegistryManager.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/registry/RegistryManager.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/registry/RegistryManager.java index 3162fca..9e30daf 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/registry/RegistryManager.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/registry/RegistryManager.java @@ -24,10 +24,9 @@ package org.apache.stratos.cloud.controller.registry; 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.persist.Serializer; -import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder; +import org.apache.stratos.cloud.controller.context.FasterLookUpDataHolder; import org.apache.stratos.cloud.controller.util.CloudControllerConstants; -import org.apache.stratos.cloud.controller.util.ServiceReferenceHolder; +import org.apache.stratos.cloud.controller.internal.ServiceReferenceHolder; import org.apache.stratos.messaging.domain.topology.Topology; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.registry.core.Registry; 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/registry/Serializer.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/registry/Serializer.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/registry/Serializer.java new file mode 100644 index 0000000..f0f00d5 --- /dev/null +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/registry/Serializer.java @@ -0,0 +1,115 @@ +/* + * 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.registry; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.stratos.cloud.controller.context.FasterLookUpDataHolder; +import org.apache.stratos.messaging.domain.topology.Topology; + +import java.io.*; + +public class Serializer { + + private static final Log log = LogFactory.getLog(Serializer.class); + + public static void serializeToFile(Object serializableObj, String filePath) throws IOException { + + File outFile = new File(filePath); + ObjectOutput objOut = null; + FileOutputStream fileOutputStream = null; + + try { + + if(outFile.createNewFile()){ + log.debug("Serialization file is created at "+filePath); + } else{ + log.debug("Serialization file is already existing at "+filePath); + } + fileOutputStream = new FileOutputStream(outFile); + objOut = new ObjectOutputStream(fileOutputStream); + objOut.writeObject(serializableObj); + + } catch (IOException e) { + log.error("Failed to serialize the object "+serializableObj.toString() + + " to file "+filePath , e); + throw e; + + } finally{ + if(objOut != null) { + objOut.close(); + } + if(fileOutputStream != null) { + fileOutputStream.close(); + } + } + + } + + /** + * Serialize a {@link org.apache.stratos.cloud.controller.context.FasterLookUpDataHolder} to a byte array. + * @param serializableObj + * @return byte[] + * @throws IOException + */ + public static byte[] serializeToByteArray(FasterLookUpDataHolder serializableObj) throws IOException { + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutput out = null; + try { + out = new ObjectOutputStream(bos); + out.writeObject(serializableObj); + + return bos.toByteArray(); + + } finally { + if (out != null) { + out.close(); + } + bos.close(); + } + + } + + /** + * Serialize a {@link org.apache.stratos.cloud.controller.context.FasterLookUpDataHolder} to a byte array. + * @param topology + * @return byte[] + * @throws IOException + */ + public static byte[] serializeToByteArray(Topology topology) throws IOException { + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutput out = null; + try { + out = new ObjectOutputStream(bos); + out.writeObject(topology); + + return bos.toByteArray(); + + } finally { + if (out != null) { + out.close(); + } + bos.close(); + } + + } + +} 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/runtime/FasterLookUpDataHolder.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/runtime/FasterLookUpDataHolder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/runtime/FasterLookUpDataHolder.java deleted file mode 100644 index ffdde8b..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/runtime/FasterLookUpDataHolder.java +++ /dev/null @@ -1,479 +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.runtime; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.pojo.*; -import org.apache.stratos.cloud.controller.registry.RegistryManager; -import org.wso2.carbon.databridge.agent.thrift.AsyncDataPublisher; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledFuture; - -/** - * This object holds all runtime data and provides faster access. This is a Singleton class. - */ -public class FasterLookUpDataHolder implements Serializable{ - - private static final long serialVersionUID = -2662307358852779897L; - - private static final Log log = LogFactory.getLog(FasterLookUpDataHolder.class); - - private static volatile FasterLookUpDataHolder ctxt; - - /* We keep following maps in order to make the look up time, small. */ - - /** - * Key - cluster id - * Value - list of {@link MemberContext} - */ - private Map<String, List<MemberContext>> clusterIdToMemberContext = new ConcurrentHashMap<String, List<MemberContext>>(); - - - /** - * Key - member id - * Value - {@link MemberContext} - */ - private Map<String, MemberContext> memberIdToContext = new ConcurrentHashMap<String, MemberContext>(); - - /** - * Key - member id - * Value - ScheduledFuture task - */ - private transient Map<String, ScheduledFuture<?>> memberIdToScheduledTask = new ConcurrentHashMap<String, ScheduledFuture<?>>(); - - /** - * Key - Kubernetes cluster id - * Value - {@link KubernetesClusterContext} - */ - private Map<String, KubernetesClusterContext> kubClusterIdToKubClusterContext = - new ConcurrentHashMap<String, KubernetesClusterContext>(); - - /** - * Key - cluster id - * Value - {@link ClusterContext} - */ - private Map<String, ClusterContext> clusterIdToContext = new ConcurrentHashMap<String, ClusterContext>(); - - /** - * This works as a cache to hold already validated partitions against a cartridge type. - * Key - cartridge type - * Value - list of partition ids - */ - private Map<String, List<String>> cartridgeTypeToPartitionIds = new ConcurrentHashMap<String, List<String>>(); - - /** - * Thread pool used in this task to execute parallel tasks. - */ - private transient ExecutorService executor = Executors.newFixedThreadPool(20); - - /** - * List of registered {@link Cartridge}s - */ - private List<Cartridge> cartridges; - - /** - * List of deployed service groups - */ - private List<ServiceGroup> serviceGroups; - - /** - * List of IaaS Providers. - */ - private List<IaasProvider> iaasProviders; - - - private String serializationDir; - private boolean enableBAMDataPublisher; - private transient DataPublisherConfig dataPubConfig; - private boolean enableTopologySync; - private transient TopologyConfig topologyConfig; - - private transient AsyncDataPublisher dataPublisher; - private String streamId; - private boolean isPublisherRunning; - private boolean isTopologySyncRunning; - - - public static FasterLookUpDataHolder getInstance() { - - if (ctxt == null) { - synchronized (FasterLookUpDataHolder.class) { - if (ctxt == null && RegistryManager.getInstance() != null) { - - Object obj = RegistryManager.getInstance().retrieve(); - if (obj != null) { - if (obj instanceof FasterLookUpDataHolder) { - ctxt = (FasterLookUpDataHolder) obj; - } - } - } - if(ctxt == null) { - ctxt = new FasterLookUpDataHolder(); - } - } - } - - return ctxt; - } - - private FasterLookUpDataHolder() { - - cartridges = new ArrayList<Cartridge>(); - serviceGroups = new ArrayList<ServiceGroup>(); - } - - public List<Cartridge> getCartridges() { - return cartridges; - } - - public void setCartridges(List<Cartridge> cartridges) { - this.cartridges = cartridges; - } - - public void setServiceGroups(List<ServiceGroup> serviceGroups) { - this.serviceGroups = serviceGroups; - } - - public List<ServiceGroup> getServiceGroups() { - return this.serviceGroups; - } - - - public Cartridge getCartridge(String cartridgeType) { - for (Cartridge cartridge : cartridges) { - if (cartridge.getType().equals(cartridgeType)) { - return cartridge; - } - } - - return null; - } - - public void addCartridge(Cartridge newCartridges) { - - cartridges.add(newCartridges); - } - - public void removeCartridges(List<Cartridge> cartridges) { - if (this.cartridges != null) { - this.cartridges.removeAll(cartridges); - } - - } - - public ServiceGroup getServiceGroup(String name) { - for (ServiceGroup serviceGroup : serviceGroups) { - if (serviceGroup.getName().equals(name)) { - return serviceGroup; - } - } - - return null; - } - - public void addServiceGroup(ServiceGroup newServiceGroup) { - this.serviceGroups.add(newServiceGroup); - } - - public void removeServiceGroup(List<ServiceGroup> serviceGroup) { - if (this.serviceGroups != null) { - this.serviceGroups.removeAll(serviceGroup); - } - } - - public IaasProvider getIaasProvider(String type) { - if(type == null) { - return null; - } - - for (IaasProvider iaasProvider : iaasProviders) { - if(type.equals(iaasProvider.getType())) { - return iaasProvider; - } - } - return null; - } - - public List<IaasProvider> getIaasProviders() { - return iaasProviders; - } - - public void setIaasProviders(List<IaasProvider> iaasProviders) { - this.iaasProviders = iaasProviders; - } - - public String getSerializationDir() { - return serializationDir; - } - - public void setSerializationDir(String serializationDir) { - this.serializationDir = serializationDir; - } - - public AsyncDataPublisher getDataPublisher() { - return dataPublisher; - } - - public void setDataPublisher(AsyncDataPublisher dataPublisher) { - this.dataPublisher = dataPublisher; - } - - public String getStreamId() { - return streamId; - } - - public void setStreamId(String streamId) { - this.streamId = streamId; - } - - public boolean getEnableBAMDataPublisher() { - return enableBAMDataPublisher; - } - - public void setEnableBAMDataPublisher(boolean enableBAMDataPublisher) { - this.enableBAMDataPublisher = enableBAMDataPublisher; - } - - public boolean isPublisherRunning() { - return isPublisherRunning; - } - - public void setPublisherRunning(boolean isPublisherRunning) { - this.isPublisherRunning = isPublisherRunning; - } - - public boolean getEnableTopologySync() { - return enableTopologySync; - } - - public void setEnableTopologySync(boolean enableTopologySync) { - this.enableTopologySync = enableTopologySync; - } - - public boolean isTopologySyncRunning() { - return isTopologySyncRunning; - } - - public void setTopologySyncRunning(boolean isTopologySyncRunning) { - this.isTopologySyncRunning = isTopologySyncRunning; - } - - public TopologyConfig getTopologyConfig() { - return topologyConfig; - } - - public void setTopologyConfig(TopologyConfig topologyConfig) { - this.topologyConfig = topologyConfig; - } - - public DataPublisherConfig getDataPubConfig() { - return dataPubConfig; - } - - public void setDataPubConfig(DataPublisherConfig dataPubConfig) { - this.dataPubConfig = dataPubConfig; - } - - public void addMemberContext(MemberContext ctxt) { - memberIdToContext.put(ctxt.getMemberId(), ctxt); - - List<MemberContext> ctxts; - - if((ctxts = clusterIdToMemberContext.get(ctxt.getClusterId())) == null) { - ctxts = new ArrayList<MemberContext>(); - } - if(ctxts.contains(ctxt)) { - ctxts.remove(ctxt); - } - ctxts.add(ctxt); - clusterIdToMemberContext.put(ctxt.getClusterId(), ctxts); - if(log.isDebugEnabled()) { - - log.debug("Added Member Context to the information model. "+ctxt); - } - } - - public void addScheduledFutureJob(String memberId, ScheduledFuture<?> job) { - memberIdToScheduledTask.put(memberId, job); - } - - public List<MemberContext> removeMemberContextsOfCluster(String clusterId) { - List<MemberContext> ctxts = clusterIdToMemberContext.remove(clusterId); - if(ctxts == null) { - return new ArrayList<MemberContext>(); - } - for (MemberContext memberContext : ctxts) { - String memberId = memberContext.getMemberId(); - memberIdToContext.remove(memberId); - stopTask(memberIdToScheduledTask.remove(memberId)); - } - if(log.isDebugEnabled()) { - - log.debug("Removed Member Context from the information model. "+ctxt); - } - return ctxts; - } - - public MemberContext removeMemberContext(String memberId, String clusterId) { - MemberContext returnedCtxt = memberIdToContext.remove(memberId); - List<MemberContext> ctxts = clusterIdToMemberContext.get(clusterId); - - if (ctxts != null) { - - List<MemberContext> newCtxts = new ArrayList<MemberContext>(ctxts); - - for (Iterator<MemberContext> iterator = newCtxts.iterator(); iterator.hasNext();) { - MemberContext memberContext = (MemberContext) iterator.next(); - if(memberId.equals(memberContext.getMemberId())) { - if(log.isDebugEnabled()) { - - log.debug("MemberContext [id]: "+memberId+" removed from information model."); - } - iterator.remove(); - } - } - - clusterIdToMemberContext.put(clusterId, newCtxts); - } - - stopTask(memberIdToScheduledTask.remove(memberId)); - - return returnedCtxt; - - } - - private void stopTask(ScheduledFuture<?> task) { - if (task != null) { - - task.cancel(true); - log.info("Scheduled Pod Activation Watcher task canceled."); - } - } - - public MemberContext getMemberContextOfMemberId(String memberId) { - return memberIdToContext.get(memberId); - } - - public List<MemberContext> getMemberContextsOfClusterId(String clusterId) { - return clusterIdToMemberContext.get(clusterId); - } - - public Map<String, List<MemberContext>> getClusterIdToMemberContext() { - return clusterIdToMemberContext; - } - - public void setClusterIdToMemberContext(Map<String, List<MemberContext>> clusterIdToMemberContext) { - this.clusterIdToMemberContext = clusterIdToMemberContext; - } - - public Map<String, MemberContext> getMemberIdToContext() { - return memberIdToContext; - } - - public void setMemberIdToContext(Map<String, MemberContext> memberIdToContext) { - this.memberIdToContext = memberIdToContext; - } - - public void addClusterContext(ClusterContext ctxt) { - clusterIdToContext.put(ctxt.getClusterId(), ctxt); - } - - public ClusterContext getClusterContext(String clusterId) { - return clusterIdToContext.get(clusterId); - } - - public ClusterContext removeClusterContext(String clusterId) { - return clusterIdToContext.remove(clusterId); - } - - public Map<String, ClusterContext> getClusterIdToContext() { - return clusterIdToContext; - } - - public void setClusterIdToContext(Map<String, ClusterContext> clusterIdToContext) { - this.clusterIdToContext = clusterIdToContext; - } - - public ExecutorService getExecutor() { - return executor; - } - - public void setExecutor(ExecutorService executor) { - this.executor = executor; - } - - public Map<String, List<String>> getCartridgeTypeToPartitionIds() { - return cartridgeTypeToPartitionIds; - } - - public void setCartridgeTypeToPartitionIds( - Map<String, List<String>> cartridgeTypeToPartitionIds) { - this.cartridgeTypeToPartitionIds = cartridgeTypeToPartitionIds; - } - - public void addToCartridgeTypeToPartitionIdMap(String cartridgeType, String partitionId) { - List<String> list = this.cartridgeTypeToPartitionIds.get(cartridgeType); - - if(list == null) { - list = new ArrayList<String>(); - } - - list.add(partitionId); - this.cartridgeTypeToPartitionIds.put(cartridgeType, list); - } - - public void removeFromCartridgeTypeToPartitionIds(String cartridgeType) { - this.cartridgeTypeToPartitionIds.remove(cartridgeType); - } - - public Map<String, KubernetesClusterContext> getKubClusterIdToKubClusterContext() { - return kubClusterIdToKubClusterContext; - } - - public KubernetesClusterContext getKubernetesClusterContext(String kubClusterId) { - return kubClusterIdToKubClusterContext.get(kubClusterId); - } - - public void addKubernetesClusterContext(KubernetesClusterContext ctxt) { - this.kubClusterIdToKubClusterContext.put(ctxt.getKubernetesClusterId(), ctxt); - } - - public void setKubClusterIdToKubClusterContext( - Map<String, KubernetesClusterContext> kubClusterIdToKubClusterContext) { - this.kubClusterIdToKubClusterContext = kubClusterIdToKubClusterContext; - } - - public Map<String, ScheduledFuture<?>> getMemberIdToScheduledTask() { - return memberIdToScheduledTask; - } - - public void setMemberIdToScheduledTask(Map<String, ScheduledFuture<?>> memberIdToScheduledTask) { - this.memberIdToScheduledTask = memberIdToScheduledTask; - } - -} \ No newline at end of file
