http://git-wip-us.apache.org/repos/asf/stratos/blob/c5adb7aa/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/datapublisher/logpublisher.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/datapublisher/logpublisher.py b/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/datapublisher/logpublisher.py deleted file mode 100644 index 050dd9e..0000000 --- a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/datapublisher/logpublisher.py +++ /dev/null @@ -1,273 +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. - -import os -import datetime -from threading import Thread, current_thread - -from ..databridge.agent import * -from ..config.cartridgeagentconfiguration import CartridgeAgentConfiguration -from ..util import cartridgeagentutils, cartridgeagentconstants -from exception.datapublisherexception import DataPublisherException - - -class LogPublisher(Thread): - - def __init__(self, file_path, stream_definition, tenant_id, alias, date_time, member_id): - Thread.__init__(self) - - self.log = LogFactory().get_log(__name__) - - self.file_path = file_path - self.thrift_publisher = ThriftPublisher( - DataPublisherConfiguration.get_instance().monitoring_server_ip, - DataPublisherConfiguration.get_instance().monitoring_server_port, - DataPublisherConfiguration.get_instance().admin_username, - DataPublisherConfiguration.get_instance().admin_password, - stream_definition) - self.tenant_id = tenant_id - self.alias = alias - self.datetime = date_time - self.member_id = member_id - - self.terminated = False - - def run(self): - if os.path.isfile(self.file_path) and os.access(self.file_path, os.R_OK): - self.log.info("Starting log publisher for file: " + self.file_path + ", thread: " + current_thread()) - # open file and keep reading for new entries - read_file = open(self.file_path, "r") - read_file.seek(os.stat(self.file_path)[6]) # go to the end of the file - - while not self.terminated: - where = read_file.tell() # where the seeker is in the file - line = read_file.readline() # read the current line - if not line: - # no new line entered - time.sleep(1) - read_file.seek(where) # set seeker - else: - # new line detected, create event object - event = ThriftEvent() - event.metaData.append(self.member_id) - event.payloadData.append(self.tenant_id) - event.payloadData.append(self.alias) - event.payloadData.append("") - event.payloadData.append(self.datetime) - event.payloadData.append("") - event.payloadData.append(line) - event.payloadData.append("") - event.payloadData.append("") - event.payloadData.append(self.member_id) - event.payloadData.append("") - - self.thrift_publisher.publish(event) - - self.thrift_publisher.disconnect() # dicsonnect the publisher upon being terminated - else: - raise DataPublisherException("Unable to read the file at path %r" % self.file_path) - - def terminate(self): - """ - Allows the LogPublisher thread to be terminated to stop publishing to BAM/CEP. Allow a minimum of 1 second delay - to take effect. - """ - self.terminated = True - - -class LogPublisherManager(Thread): - """ - A log publishing thread management thread which maintains a log publisher for each log file. Also defines a stream - definition and the BAM/CEP server information for a single publishing context. - """ - - @staticmethod - def define_stream(): - """ - Creates a stream definition for Log Publishing - :return: A StreamDefinition object with the required attributes added - :rtype : StreamDefinition - """ - # stream definition - stream_definition = StreamDefinition() - valid_tenant_id = LogPublisherManager.get_valid_tenant_id(CartridgeAgentConfiguration().tenant_id) - alias = LogPublisherManager.get_alias(CartridgeAgentConfiguration().cluster_id) - stream_name = "logs." + valid_tenant_id + "." \ - + alias + "." + LogPublisherManager.get_current_date() - stream_version = "1.0.0" - - stream_definition.name = stream_name - stream_definition.version = stream_version - stream_definition.description = "Apache Stratos Instance Log Publisher" - stream_definition.add_metadata_attribute("memberId", StreamDefinition.STRING) - stream_definition.add_payloaddata_attribute("tenantID", StreamDefinition.STRING) - stream_definition.add_payloaddata_attribute("serverName", StreamDefinition.STRING) - stream_definition.add_payloaddata_attribute("appName", StreamDefinition.STRING) - stream_definition.add_payloaddata_attribute("logTime", StreamDefinition.STRING) - stream_definition.add_payloaddata_attribute("priority", StreamDefinition.STRING) - stream_definition.add_payloaddata_attribute("message", StreamDefinition.STRING) - stream_definition.add_payloaddata_attribute("logger", StreamDefinition.STRING) - stream_definition.add_payloaddata_attribute("ip", StreamDefinition.STRING) - stream_definition.add_payloaddata_attribute("instance", StreamDefinition.STRING) - stream_definition.add_payloaddata_attribute("stacktrace", StreamDefinition.STRING) - - return stream_definition - - def __init__(self, logfile_paths): - Thread.__init__(self) - self.logfile_paths = logfile_paths - self.publishers = {} - self.ports = [] - self.ports.append(DataPublisherConfiguration.get_instance().monitoring_server_port) - self.ports.append(DataPublisherConfiguration.get_instance().monitoring_server_secure_port) - - self.cartridge_agent_config = CartridgeAgentConfiguration() - - cartridgeagentutils.wait_until_ports_active( - DataPublisherConfiguration.get_instance().monitoring_server_ip, - self.ports, - int(self.cartridge_agent_config.read_property("port.check.timeout", critical=False))) - - ports_active = cartridgeagentutils.check_ports_active( - DataPublisherConfiguration.get_instance().monitoring_server_ip, - self.ports) - - if not ports_active: - raise DataPublisherException("Monitoring server not active, data publishing is aborted") - - self.stream_definition = self.define_stream() - - def run(self): - if self.logfile_paths is not None and len(self.logfile_paths): - for log_path in self.logfile_paths: - # thread for each log file - publisher = self.get_publisher(log_path) - publisher.start() - - def get_publisher(self, log_path): - """ - Retrieve the publisher for the specified log file path. Creates a new LogPublisher if one is not available - :return: The LogPublisher object - :rtype : LogPublisher - """ - if log_path not in self.publishers: - self.publishers[log_path] = LogPublisher(log_path, self.stream_definition) - - return self.publishers[log_path] - - def terminate_publisher(self, log_path): - """ - Terminates the LogPublisher thread associated with the specified log file - """ - if log_path in self.publishers: - self.publishers[log_path].terminate() - - def terminate_all_publishers(self): - """ - Terminates all LogPublisher threads - """ - for publisher in self.publishers: - publisher.terminate() - - @staticmethod - def get_valid_tenant_id(tenant_id): - if tenant_id == cartridgeagentconstants.INVALID_TENANT_ID \ - or tenant_id == cartridgeagentconstants.SUPER_TENANT_ID: - return "0" - - return tenant_id - - @staticmethod - def get_alias(cluster_id): - try: - alias = cluster_id.split("\\.")[0] - except: - alias = cluster_id - - return alias - - @staticmethod - def get_current_date(): - """ - Returns the current date formatted as yyyy-MM-dd - :return: Formatted date string - :rtype : str - """ - return datetime.date.today().strftime(cartridgeagentconstants.DATE_FORMAT) - - -class DataPublisherConfiguration: - """ - A singleton implementation to access configuration information for data publishing to BAM/CEP - TODO: perfect singleton impl ex: Borg - """ - - __instance = None - log = LogFactory().get_log(__name__) - - @staticmethod - def get_instance(): - """ - Singleton instance retriever - :return: Instance - :rtype : DataPublisherConfiguration - """ - if DataPublisherConfiguration.__instance is None: - DataPublisherConfiguration.__instance = DataPublisherConfiguration() - - return DataPublisherConfiguration.__instance - - def __init__(self): - self.enabled = False - self.monitoring_server_ip = None - self.monitoring_server_port = None - self.monitoring_server_secure_port = None - self.admin_username = None - self.admin_password = None - self.cartridge_agent_config = CartridgeAgentConfiguration() - - self.read_config() - - def read_config(self): - self.enabled = True if self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_PUBLISHER_ENABLED, False).strip().lower() == "true" else False - if not self.enabled: - DataPublisherConfiguration.log.info("Data Publisher disabled") - return - - DataPublisherConfiguration.log.info("Data Publisher enabled") - - self.monitoring_server_ip = self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_RECEIVER_IP, False) - if self.monitoring_server_ip is None or self.monitoring_server_ip.strip() == "": - raise RuntimeError("System property not found: " + cartridgeagentconstants.MONITORING_RECEIVER_IP) - - self.monitoring_server_port = self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_RECEIVER_PORT, False) - if self.monitoring_server_port is None or self.monitoring_server_port.strip() == "": - raise RuntimeError("System property not found: " + cartridgeagentconstants.MONITORING_RECEIVER_PORT) - - self.monitoring_server_secure_port = self.cartridge_agent_config.read_property("monitoring.server.secure.port", False) - if self.monitoring_server_secure_port is None or self.monitoring_server_secure_port.strip() == "": - raise RuntimeError("System property not found: monitoring.server.secure.port") - - self.admin_username = self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_SERVER_ADMIN_USERNAME, False) - if self.admin_username is None or self.admin_username.strip() == "": - raise RuntimeError("System property not found: " + cartridgeagentconstants.MONITORING_SERVER_ADMIN_USERNAME) - - self.admin_password = self.cartridge_agent_config.read_property(cartridgeagentconstants.MONITORING_SERVER_ADMIN_PASSWORD, False) - if self.admin_password is None or self.admin_password.strip() == "": - raise RuntimeError("System property not found: " + cartridgeagentconstants.MONITORING_SERVER_ADMIN_PASSWORD) - - DataPublisherConfiguration.log.info("Data Publisher configuration initialized")
http://git-wip-us.apache.org/repos/asf/stratos/blob/c5adb7aa/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/__init__.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/__init__.py b/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/__init__.py deleted file mode 100644 index e69de29..0000000 http://git-wip-us.apache.org/repos/asf/stratos/blob/c5adb7aa/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/instance/__init__.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/instance/__init__.py b/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/instance/__init__.py deleted file mode 100644 index 13a8339..0000000 --- a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/instance/__init__.py +++ /dev/null @@ -1,16 +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. http://git-wip-us.apache.org/repos/asf/stratos/blob/c5adb7aa/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/instance/notifier/__init__.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/instance/notifier/__init__.py b/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/instance/notifier/__init__.py deleted file mode 100644 index 2456923..0000000 --- a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/instance/notifier/__init__.py +++ /dev/null @@ -1,17 +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. - http://git-wip-us.apache.org/repos/asf/stratos/blob/c5adb7aa/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/instance/notifier/events.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/instance/notifier/events.py b/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/instance/notifier/events.py deleted file mode 100644 index eb7be55..0000000 --- a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/instance/notifier/events.py +++ /dev/null @@ -1,77 +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. - -import json - - -class ArtifactUpdatedEvent: - def __init__(self): - self.cluster_id = None - """ :type : str """ - self.status = None - """ :type : str """ - self.repo_username = None - """ :type : str """ - self.repo_password = None - """ :type : str """ - self.repo_url = None - """ :type : str """ - self.tenant_id = None - """ :type : int """ - self.commit_enabled = None - """ :type : bool """ - - @staticmethod - def create_from_json(json_str): - json_obj = json.loads(json_str) - instance = ArtifactUpdatedEvent() - - instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None - instance.status = json_obj["status"] if "status" in json_obj else None - instance.repo_username = json_obj["repoUserName"] if "repoUserName" in json_obj else None - instance.repo_password = json_obj["repoPassword"] if "repoPassword" in json_obj else None - instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None - instance.repo_url = json_obj["repoURL"] if "repoURL" in json_obj else "" - instance.commit_enabled = json_obj["commitEnabled"] if "commitEnabled" in json_obj else None - - return instance - - -class InstanceCleanupClusterEvent: - def __init__(self, cluster_id): - self.cluster_id = cluster_id - """ :type : str """ - - @staticmethod - def create_from_json(json_str): - json_obj = json.loads(json_str) - c_id = json_obj["clusterId"] if "clusterId" in json_obj else None - - return InstanceCleanupClusterEvent(c_id) - - -class InstanceCleanupMemberEvent: - def __init__(self, member_id): - self.member_id = member_id - """ :type : str """ - - @staticmethod - def create_from_json(json_str): - json_obj = json.loads(json_str) - m_id = json_obj["memberId"] if "memberId" in json_obj else None - - return InstanceCleanupMemberEvent(m_id) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/c5adb7aa/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/instance/status/__init__.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/instance/status/__init__.py b/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/instance/status/__init__.py deleted file mode 100644 index 2456923..0000000 --- a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/instance/status/__init__.py +++ /dev/null @@ -1,17 +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. - http://git-wip-us.apache.org/repos/asf/stratos/blob/c5adb7aa/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/instance/status/events.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/instance/status/events.py b/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/instance/status/events.py deleted file mode 100644 index c000c55..0000000 --- a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/instance/status/events.py +++ /dev/null @@ -1,98 +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. - -import json - - -class InstanceActivatedEvent: - def __init__(self, service_name, cluster_id, network_partition_id, parition_id, member_id): - self.serviceName = service_name - """ :type : str """ - self.clusterId = cluster_id - """ :type : str """ - self.networkPartitionId = network_partition_id - """ :type : str """ - self.partitionId = parition_id - """ :type : str """ - self.memberId = member_id - """ :type : str """ - - def to_json(self): - return to_json(self) - - -class InstanceStartedEvent: - def __init__(self, service_name, cluster_id, network_partition_id, parition_id, member_id): - self.serviceName = service_name - """ :type : str """ - self.clusterId = cluster_id - """ :type : str """ - self.networkPartitionId = network_partition_id - """ :type : str """ - self.partitionId = parition_id - """ :type : str """ - self.memberId = member_id - """ :type : str """ - - def to_json(self): - return to_json(self) - - -class InstanceMaintenanceModeEvent: - - def __init__(self, service_name, cluster_id, network_partition_id, partition_id, member_id): - self.serviceName = service_name - """ :type : str """ - self.clusterId = cluster_id - """ :type : str """ - self.networkPartitionId = network_partition_id - """ :type : str """ - self.partitionId = partition_id - """ :type : str """ - self.memberId = member_id - """ :type : str """ - - def to_json(self): - return to_json(self) - - -class InstanceReadyToShutdownEvent: - - def __init__(self, service_name, cluster_id, network_partition_id, partition_id, member_id): - self.serviceName = service_name - """ :type : str """ - self.clusterId = cluster_id - """ :type : str """ - self.networkPartitionId = network_partition_id - """ :type : str """ - self.partitionId = partition_id - """ :type : str """ - self.memberId = member_id - """ :type : str """ - - def to_json(self): - return to_json(self) - - -def to_json(instance): - """ - common function to serialize status event object - :param obj instance: - :return: serialized json string - :rtype str - """ - return json.dumps(instance, default=lambda o: o.__dict__, sort_keys=True, indent=4) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/c5adb7aa/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/tenant/__init__.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/tenant/__init__.py b/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/tenant/__init__.py deleted file mode 100644 index 13a8339..0000000 --- a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/tenant/__init__.py +++ /dev/null @@ -1,16 +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. http://git-wip-us.apache.org/repos/asf/stratos/blob/c5adb7aa/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/tenant/events.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/tenant/events.py b/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/tenant/events.py deleted file mode 100644 index def2b64..0000000 --- a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/tenant/events.py +++ /dev/null @@ -1,147 +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. - -import json -from ... tenant.tenantcontext import * - - -class SubscriptionDomainAddedEvent(): - - def __init__(self): - self.tenant_id = None - """ :type : int """ - self.service_name = None - """ :type : str """ - self.cluster_ids = None - """ :type : list[str] """ - self.domain_name = None - """ :type : str """ - self.application_context = None - """ :type : str """ - - @staticmethod - def create_from_json(json_str): - json_obj = json.loads(json_str) - instance = SubscriptionDomainAddedEvent() - - instance.cluster_ids = json_obj["clusterIds"] if "clusterIds" in json_obj else None - instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None - instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None - instance.domain_name = json_obj["domainName"] if "domainName" in json_obj else None - instance.application_context = json_obj["applicationContext"] if "applicationContext" in json_obj else None - - return instance - - -class SubscriptionDomainRemovedEvent: - - def __init__(self, tenant_id, service_name, cluster_ids, domain_name): - self.tenant_id = tenant_id - """ :type : int """ - self.service_name = service_name - """ :type : str """ - self.cluster_ids = cluster_ids - """ :type : list[str] """ - self.domain_name = domain_name - """ :type : str """ - - @staticmethod - def create_from_json(json_str): - json_obj = json.loads(json_str) - instance = SubscriptionDomainRemovedEvent() - - instance.cluster_ids = json_obj["clusterIds"] if "clusterIds" in json_obj else None - instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None - instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None - instance.domain_name = json_obj["domainName"] if "domainName" in json_obj else None - - return instance - - -class CompleteTenantEvent: - - def __init__(self): - self.tenants = [] - """ :type : list[Tenant] """ - self.tenant_list_json = None - """ :type : str """ - - @staticmethod - def create_from_json(json_str): - json_obj = json.loads(json_str) - instance = CompleteTenantEvent() - instance.tenants = [] - - tenants_str = json_obj["tenants"] if "tenants" in json_obj else None - instance.tenant_list_json = tenants_str - if tenants_str is not None: - for tenant_str in tenants_str: - tenant_obj = Tenant(int(tenant_str["tenantId"]), tenant_str["tenantDomain"]) - for service_name in tenant_str["serviceNameSubscriptionMap"]: - sub_str = tenant_str["serviceNameSubscriptionMap"][service_name] - sub = Subscription(sub_str["serviceName"], sub_str["clusterIds"]) - for domain_name in sub_str["subscriptionDomainMap"]: - subdomain_str = sub_str["subscriptionDomainMap"][domain_name] - sub.add_subscription_domain(domain_name, subdomain_str["applicationContext"]) - tenant_obj.add_subscription(sub) - instance.tenants.append(tenant_obj) - - return instance - - -class TenantSubscribedEvent: - - def __init__(self): - self.tenant_id = None - """ :type : int """ - self.service_name = None - """ :type : str """ - self.cluster_ids = None - """ :type : list[str] """ - - @staticmethod - def create_from_json(json_str): - json_obj = json.loads(json_str) - instance = TenantSubscribedEvent() - - instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None - instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None - instance.cluster_ids = json_obj["clusterIds"] if "clusterIds" in json_obj else None - - return instance - - -class TenantUnsubscribedEvent: - - def __init__(self): - self.tenant_id = None - """ :type : int """ - self.service_name = None - """ :type : str """ - self.cluster_ids = None - """ :type : list[str] """ - - @staticmethod - def create_from_json(json_str): - json_obj = json.loads(json_str) - instance = TenantUnsubscribedEvent() - - instance.tenant_id = json_obj["tenantId"] if "tenantId" in json_obj else None - instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None - instance.cluster_ids = json_obj["clusterIds"] if "clusterIds" in json_obj else None - - return instance \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/c5adb7aa/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/topology/__init__.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/topology/__init__.py b/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/topology/__init__.py deleted file mode 100644 index 2456923..0000000 --- a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/topology/__init__.py +++ /dev/null @@ -1,17 +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. - http://git-wip-us.apache.org/repos/asf/stratos/blob/c5adb7aa/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/topology/events.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/topology/events.py b/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/topology/events.py deleted file mode 100644 index 52c7c19..0000000 --- a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/event/topology/events.py +++ /dev/null @@ -1,280 +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. - -import json - -from ... topology.topologycontext import * - - -class MemberActivatedEvent: - - def __init__(self): - self.service_name = None - """ :type : str """ - self.cluster_id = None - """ :type : str """ - self.network_partition_id = None - """ :type : str """ - self.partition_id = None - """ :type : str """ - self.member_id = None - """ :type : str """ - self.port_map = {} - """ :type : dict[str, Port] """ - self.member_ip = None - """ :type : str """ - - def get_port(self, proxy_port): - """ - Returns the port object of the provided port id - :param str proxy_port: - :return: Port object, None if the port id is invalid - :rtype: topology.topologycontext.Port - """ - if proxy_port in self.port_map: - return self.port_map[proxy_port] - - return None - - @staticmethod - def create_from_json(json_str): - json_obj = json.loads(json_str) - instance = MemberActivatedEvent() - - instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None - instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None - instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None - instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None - instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None - #instance.port_map = json_obj["portMap"] if "portMap" in json_obj else {} - instance.member_ip = json_obj["memberIp"] if "memberIp" in json_obj else None - - for port_proxy in json_obj["portMap"]: - port_str = json_obj["portMap"][port_proxy] - port_obj = Port(port_str["protocol"], port_str["value"], port_proxy) - instance.port_map[port_proxy] = port_obj - - return instance - - -class MemberTerminatedEvent: - - def __init__(self): - self.service_name = None - """ :type : str """ - self.cluster_id = None - """ :type : str """ - self.network_partition_id = None - """ :type : str """ - self.partition_id = None - """ :type : str """ - self.member_id = None - """ :type : str """ - self.properties = {} - """ :type : dict[str, str] """ - - @staticmethod - def create_from_json(json_str): - json_obj = json.loads(json_str) - instance = MemberTerminatedEvent() - - instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None - instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None - instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None - instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None - instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None - instance.properties = json_obj["properties"] if "properties" in json_obj else None - - return instance - - -class MemberSuspendedEvent: - - def __init__(self): - self.service_name = None - """ :type : str """ - self.cluster_id = None - """ :type : str """ - self.network_partition_id = None - """ :type : str """ - self.partition_id = None - """ :type : str """ - self.member_id = None - """ :type : str """ - - @staticmethod - def create_from_json(json_str): - json_obj = json.loads(json_str) - instance = MemberSuspendedEvent() - - instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None - instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None - instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None - instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None - instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None - - return instance - - -class CompleteTopologyEvent: - - def __init__(self): - self.topology = None - """ :type : Topology """ - - @staticmethod - def create_from_json(json_str): - json_obj = json.loads(json_str) - instance = CompleteTopologyEvent() - - topology_str = json_obj["topology"] if "topology" in json_obj else None - if topology_str is not None: - topology_obj = Topology() - topology_obj.json_str = topology_str - - #add service map - for service_name in topology_str["serviceMap"]: - service_str = topology_str["serviceMap"][service_name] - - service_obj = Service(service_name, service_str["serviceType"]) - service_obj.properties = service_str["properties"] - # add ports to port map - for port_proxy in service_str["portMap"]: - port_str = service_str["portMap"][port_proxy] - port_obj = Port(port_str["protocol"], port_str["value"], port_proxy) - service_obj.add_port(port_obj) - - #add cluster map - for cluster_id in service_str["clusterIdClusterMap"]: - cluster_str = service_str["clusterIdClusterMap"][cluster_id] - cl_service_name = cluster_str["serviceName"] - cl_autoscale_policy_name = cluster_str["autoscalePolicyName"] - cl_deployment_policy_name = cluster_str["deploymentPolicyName"] if "deploymentPolicyName" in cluster_str else None - - cluster_obj = Cluster(cl_service_name, cluster_id, cl_deployment_policy_name, cl_autoscale_policy_name) - cluster_obj.hostnames = cluster_str["hostNames"] - cluster_obj.tenant_range = cluster_str["tenantRange"] if "tenantRange" in cluster_str else None - cluster_obj.is_lb_cluster = cluster_str["isLbCluster"] - cluster_obj.is_kubernetes_cluster = cluster_str["isKubernetesCluster"] - cluster_obj.status = cluster_str["status"] - cluster_obj.load_balancer_algorithm_name = cluster_str["loadBalanceAlgorithmName"] if "loadBalanceAlgorithmName" in cluster_str else None - cluster_obj.properties = cluster_str["properties"] - cluster_obj.member_list_json = cluster_str["memberMap"] - - #add member map - for member_id in cluster_str["memberMap"]: - member_str = cluster_str["memberMap"][member_id] - mm_service_name = member_str["serviceName"] - mm_cluster_id = member_str["clusterId"] - mm_network_partition_id = member_str["networkPartitionId"] if "networkPartitionId" in member_str else None - mm_partition_id = member_str["partitionId"] if "partitionId" in member_str else None - - member_obj = Member(mm_service_name, mm_cluster_id, mm_network_partition_id, mm_partition_id, member_id) - member_obj.member_public_ip = member_str["memberPublicIp"] - member_obj.status = member_str["status"] - member_obj.member_ip = member_str["memberIp"] - member_obj.properties = member_str["properties"] - member_obj.lb_cluster_id = member_str["lbClusterId"] if "lbClusterId" in member_str else None - member_obj.json_str = member_str - - #add port map - for mm_port_proxy in member_str["portMap"]: - mm_port_str = member_str["portMap"][mm_port_proxy] - mm_port_obj = Port(mm_port_str["protocol"], mm_port_str["value"], mm_port_proxy) - member_obj.add_port(mm_port_obj) - cluster_obj.add_member(member_obj) - service_obj.add_cluster(cluster_obj) - topology_obj.add_service(service_obj) - instance.topology = topology_obj - - return instance - - def get_topology(self): - return self.topology - - -class MemberStartedEvent: - - def __init__(self): - self.service_name = None - """ :type : str """ - self.cluster_id = None - """ :type : str """ - self.network_partition_id = None - """ :type : str """ - self.partition_id = None - """ :type : str """ - self.member_id = None - """ :type : str """ - self.status = None - """ :type : str """ - self.properties = {} - """ :type : dict[str, str] """ - - @staticmethod - def create_from_json(json_str): - json_obj = json.loads(json_str) - instance = MemberStartedEvent() - - instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None - instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None - instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None - instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None - instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None - instance.properties = json_obj["properties"] if "properties" in json_obj else None - - return instance - - -class InstanceSpawnedEvent: - - def __init__(self): - self.service_name = None - """ :type : str """ - self.cluster_id = None - """ :type : str """ - self.network_partition_id = None - """ :type : str """ - self.partition_id = None - """ :type : str """ - self.member_id = None - """ :type : str """ - self.lb_cluster_id = None - """ :type : str """ - self.member_public_ip = None - """ :type : str """ - self.member_ip = None - """ :type : str """ - self.properties = {} - """ :type : dict[str, str] """ - - @staticmethod - def create_from_json(json_str): - json_obj = json.loads(json_str) - instance = InstanceSpawnedEvent() - - instance.service_name = json_obj["serviceName"] if "serviceName" in json_obj else None - instance.cluster_id = json_obj["clusterId"] if "clusterId" in json_obj else None - instance.network_partition_id = json_obj["networkPartitionId"] if "networkPartitionId" in json_obj else None - instance.partition_id = json_obj["partitionId"] if "partitionId" in json_obj else None - instance.member_id = json_obj["memberId"] if "memberId" in json_obj else None - instance.lb_cluster_id = json_obj["lbClusterId"] if "lbClusterId" in json_obj else None - instance.member_public_ip = json_obj["memberPublicIp"] if "memberPublicIp" in json_obj else None - instance.member_ip = json_obj["memberIp"] if "memberIp" in json_obj else None - instance.properties = json_obj["properties"] - - return instance \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/c5adb7aa/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/exception/__init__.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/exception/__init__.py b/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/exception/__init__.py deleted file mode 100644 index 13a8339..0000000 --- a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/exception/__init__.py +++ /dev/null @@ -1,16 +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. http://git-wip-us.apache.org/repos/asf/stratos/blob/c5adb7aa/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/exception/parameternotfoundexception.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/exception/parameternotfoundexception.py b/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/exception/parameternotfoundexception.py deleted file mode 100644 index 88deafd..0000000 --- a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/exception/parameternotfoundexception.py +++ /dev/null @@ -1,35 +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. - -class ParameterNotFoundException(Exception): - """ - Exception raised when a property is not present in the configuration or the payload - of the cartridge agent - """ - __message = None - - def __init__(self, message): - Exception.__init__(self, message) - self.__message = message - - def get_message(self): - """ - The message provided when the exception is raised - :return: message - :rtype: str - """ - return self.__message http://git-wip-us.apache.org/repos/asf/stratos/blob/c5adb7aa/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/extensions/__init__.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/extensions/__init__.py b/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/extensions/__init__.py deleted file mode 100644 index 13a8339..0000000 --- a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/extensions/__init__.py +++ /dev/null @@ -1,16 +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. http://git-wip-us.apache.org/repos/asf/stratos/blob/c5adb7aa/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/extensions/abstractextensionhandler.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/extensions/abstractextensionhandler.py b/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/extensions/abstractextensionhandler.py deleted file mode 100644 index 1f2df10..0000000 --- a/components/org.apache.stratos.python.cartridge.agent/python_cartridgeagent/cartridgeagent/modules/extensions/abstractextensionhandler.py +++ /dev/null @@ -1,78 +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. - -class AbstractExtensionHandler: - - def on_instance_started_event(self): - raise NotImplementedError - - def on_instance_activated_event(self): - raise NotImplementedError - - def on_artifact_updated_event(self, artifacts_updated_event): - raise NotImplementedError - - def on_artifact_update_scheduler_event(self, tenant_id): - raise NotImplementedError - - def on_instance_cleanup_cluster_event(self, instance_cleanup_cluster_event): - raise NotImplementedError - - def on_instance_cleanup_member_event(self, instance_cleanup_member_event): - raise NotImplementedError - - def on_member_activated_event(self, member_activated_event): - raise NotImplementedError - - def on_complete_topology_event(self, complete_topology_event): - raise NotImplementedError - - def on_instance_spawned_event(self, instance_spawned_event): - raise NotImplementedError - - def on_complete_tenant_event(self, complete_tenant_event): - raise NotImplementedError - - def on_member_terminated_event(self, member_terminated_event): - raise NotImplementedError - - def on_member_suspended_event(self, member_suspended_event): - raise NotImplementedError - - def on_member_started_event(self, member_started_event): - raise NotImplementedError - - def start_server_extension(self): - raise NotImplementedError - - def volume_mount_extension(self, persistence_mappings_payload): - raise NotImplementedError - - def on_subscription_domain_added_event(self, subscription_domain_added_event): - raise NotImplementedError - - def on_subscription_domain_removed_event(self, subscription_domain_removed_event): - raise NotImplementedError - - def on_copy_artifacts_extension(self, src, des): - raise NotImplementedError - - def on_tenant_subscribed_event(self, tenant_subscribed_event): - raise NotImplementedError - - def on_tenant_unsubscribed_event(self, tenant_unsubscribed_event): - raise NotImplementedError
