Fixed Thrift session expiration after client time out to reconnect and continue publishing Fixed issues in git clone auth
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/e7a3c278 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/e7a3c278 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/e7a3c278 Branch: refs/heads/master Commit: e7a3c27867cfeec988b5673e3d4c3c989a0b8dee Parents: 9a4e3a8 Author: Chamila de Alwis <[email protected]> Authored: Sun Oct 26 16:54:05 2014 +0530 Committer: Chamila de Alwis <[email protected]> Committed: Sun Oct 26 16:54:05 2014 +0530 ---------------------------------------------------------------------- .../modules/artifactmgt/git/agentgithandler.py | 7 +++-- .../cartridgeagent/modules/databridge/agent.py | 17 +++++++++--- .../modules/databridge/thrift/publisher.py | 1 - .../cartridgeagent/testgit.py | 27 -------------------- tools/python_cartridgeagent/test/asynctest.txt | 2 +- tools/python_cartridgeagent/test/test_util.py | 5 +++- 6 files changed, 23 insertions(+), 36 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/e7a3c278/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py ---------------------------------------------------------------------- diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py b/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py index d5d085c..7b5bbaf 100644 --- a/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py +++ b/tools/python_cartridgeagent/cartridgeagent/modules/artifactmgt/git/agentgithandler.py @@ -208,7 +208,8 @@ class AgentGitHandler: cartridgeagentutils.create_dir(repo_context.local_repo_path) #TODO: remove gittle stuff - auth = AgentGitHandler.create_auth_configuration(repo_context) + #auth = AgentGitHandler.create_auth_configuration(repo_context) + auth = None if auth is not None: # authentication is required, use Gittle @@ -404,6 +405,7 @@ class AgentGitHandler: AgentGitHandler.log.debug("Modified: %r" % str(modified)) + # TODO: check for unpushed commits and push them too if not modified: AgentGitHandler.log.debug("No changes detected in the local repository for tenant " + tenant_id) return @@ -440,7 +442,8 @@ class AgentGitHandler: # if result != 0: # raise Exception #TODO: handle push failure scenarios - push_op.interact() + #push_op.interact() + push_op.expect(pexpect.EOF) AgentGitHandler.log.debug("Pushed artifacts for tenant : " + tenant_id) except: http://git-wip-us.apache.org/repos/asf/stratos/blob/e7a3c278/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py ---------------------------------------------------------------------- diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py index d67be89..5d341dd 100644 --- a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py +++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/agent.py @@ -16,7 +16,9 @@ # under the License. from thrift.publisher import * +from thrift.gen.Exception.ttypes import ThriftSessionExpiredException from ..util.log import * +import time class StreamDefinition: @@ -161,7 +163,16 @@ class ThriftPublisher: ThriftPublisher.assign_attributes(event.correlationData, event_bundler) ThriftPublisher.assign_attributes(event.payloadData, event_bundler) - self.__publisher.publish(event_bundler) + try: + self.__publisher.publish(event_bundler) + except ThriftSessionExpiredException as ex: + self.log.debug("ThriftSession expired. Reconnecting") + self.__publisher.connect(self.username, self.password) + self.__publisher.defineStream(str(self.stream_definition)) + self.stream_id = self.__publisher.streamId + self.log.debug("connected! stream ID: %r" % self.stream_id) + self.__publisher.publish(event_bundler) + self.log.debug("Published event to thrift stream [%r]" % self.stream_id) def disconnect(self): @@ -199,6 +210,4 @@ class ThriftPublisher: elif isinstance(attrib, str): event_bundler.addStringAttribute(attrib) else: - ThriftPublisher.log.error("Undefined attribute type: %r" % attrib) - else: - ThriftPublisher.log.debug("Empty attribute list") + ThriftPublisher.log.error("Undefined attribute type: %r" % attrib) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/e7a3c278/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/publisher.py ---------------------------------------------------------------------- diff --git a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/publisher.py b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/publisher.py index dfe4aa2..3317404 100644 --- a/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/publisher.py +++ b/tools/python_cartridgeagent/cartridgeagent/modules/databridge/thrift/publisher.py @@ -15,7 +15,6 @@ # specific language governing permissions and limitations # under the License. -import time import sys sys.path.append("gen") http://git-wip-us.apache.org/repos/asf/stratos/blob/e7a3c278/tools/python_cartridgeagent/cartridgeagent/testgit.py ---------------------------------------------------------------------- diff --git a/tools/python_cartridgeagent/cartridgeagent/testgit.py b/tools/python_cartridgeagent/cartridgeagent/testgit.py deleted file mode 100644 index 0b38f83..0000000 --- a/tools/python_cartridgeagent/cartridgeagent/testgit.py +++ /dev/null @@ -1,27 +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. - - -from modules.extensions.defaultextensionhandler import * -from modules.event.instance.notifier.events import ArtifactUpdatedEvent - -event_msg = '{"clusterId":"newoice.php.domain","repoUserName":"chamilad","repoPassword":"eng3lhimm3lsonn3","repoURL":"https://github.com/chamilad/NeWoice","tenantId":"-1234","commitEnabled":false}' -event = ArtifactUpdatedEvent.create_from_json(event_msg) - -extension_handler = DefaultExtensionHandler() -extension_handler.on_artifact_updated_event(event) - http://git-wip-us.apache.org/repos/asf/stratos/blob/e7a3c278/tools/python_cartridgeagent/test/asynctest.txt ---------------------------------------------------------------------- diff --git a/tools/python_cartridgeagent/test/asynctest.txt b/tools/python_cartridgeagent/test/asynctest.txt index 75eddf2..b676e7d 100644 --- a/tools/python_cartridgeagent/test/asynctest.txt +++ b/tools/python_cartridgeagent/test/asynctest.txt @@ -1 +1 @@ -1413885854235.2659 \ No newline at end of file +1414239655582.5959 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/e7a3c278/tools/python_cartridgeagent/test/test_util.py ---------------------------------------------------------------------- diff --git a/tools/python_cartridgeagent/test/test_util.py b/tools/python_cartridgeagent/test/test_util.py index e7c42ac..63c0cc7 100644 --- a/tools/python_cartridgeagent/test/test_util.py +++ b/tools/python_cartridgeagent/test/test_util.py @@ -70,7 +70,10 @@ def test_decrypt_password_success(): secret_key = "tvnw63ufg9gh5111" encrypted_password= "jP1lZ5xMlpLzu8MbY2Porg==" - assert cartridgeagentutils.decrypt_password(encrypted_password, secret_key) == plain_password, "Password decryption failed" + decrypted_password = cartridgeagentutils.decrypt_password(encrypted_password, secret_key) + #print decrypted_password + + assert decrypted_password == plain_password, "Password decryption failed" def test_decrypt_password_failure():
