You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by mx...@apache.org on 2017/05/11 11:44:46 UTC

[05/12] incubator-ariatosca git commit: instumented logging and node states

instumented logging and node states


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/c8896ab5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/c8896ab5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/c8896ab5

Branch: refs/heads/ARIA-213-Sporadic-tests-failures-over-locked-database-issue
Commit: c8896ab5a2f127e929f28782bd80224638fb2c71
Parents: a44d9e5
Author: max-orlov <ma...@gigaspaces.com>
Authored: Wed May 10 02:01:47 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Thu May 11 14:28:49 2017 +0300

----------------------------------------------------------------------
 .../workflows/core/events_handler.py            |  4 ++--
 aria/storage/instrumentation.py                 | 24 ++++++++++++--------
 examples/hello-world/scripts/configure.sh       |  4 ++--
 examples/hello-world/scripts/start.sh           | 14 ++++++------
 examples/hello-world/scripts/stop.sh            |  4 ++--
 5 files changed, 28 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c8896ab5/aria/orchestrator/workflows/core/events_handler.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/core/events_handler.py b/aria/orchestrator/workflows/core/events_handler.py
index f3e4e7e..669fb43 100644
--- a/aria/orchestrator/workflows/core/events_handler.py
+++ b/aria/orchestrator/workflows/core/events_handler.py
@@ -40,7 +40,7 @@ def _task_started(task, *args, **kwargs):
     with task._update():
         task.started_at = datetime.utcnow()
         task.status = task.STARTED
-        _update_node_state_if_necessary(task, is_transitional=True)
+    _update_node_state_if_necessary(task, is_transitional=True)
 
 
 @events.on_failure_task_signal.connect
@@ -74,7 +74,7 @@ def _task_succeeded(task, *args, **kwargs):
         task.ended_at = datetime.utcnow()
         task.status = task.SUCCESS
 
-        _update_node_state_if_necessary(task)
+    _update_node_state_if_necessary(task)
 
 
 @events.start_workflow_signal.connect

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c8896ab5/aria/storage/instrumentation.py
----------------------------------------------------------------------
diff --git a/aria/storage/instrumentation.py b/aria/storage/instrumentation.py
index 14d4423..79f821a 100644
--- a/aria/storage/instrumentation.py
+++ b/aria/storage/instrumentation.py
@@ -13,9 +13,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import os
 import copy
-import json
 
 import sqlalchemy.event
 
@@ -26,9 +24,14 @@ from ..storage.exceptions import StorageError
 _VERSION_ID_COL = 'version'
 _STUB = object()
 _INSTRUMENTED = {
+    # Node related stuff
     _models.Node.runtime_properties: dict,
+    _models.Node.state: str,
 
-    # Log related stuff
+    # # Task related stuff
+    _models.Task.status: str,
+
+    # # Log related stuff
     _models.Log.level: str,
     _models.Log.msg: str,
     _models.Log.traceback: str,
@@ -189,12 +192,14 @@ def apply_tracked_changes(tracked_changes, model):
                             # The object can be entirely new (Log is an example of this use case,
                             # its id is None (or 'null'), thus we need to create it from scratch,
                             # and not just update it.
-                            instance = mapi.model_cls() if 'null' else mapi.get(instance_id)
+                            instance = \
+                                mapi.model_cls() if instance_id == 'null' else mapi.get(instance_id)
+
                         setattr(instance, attribute_name, value.current)
                 if instance:
                     _validate_version_id(instance, mapi)
                     # This follows the same logic as the same comment regarding 'null'
-                    if instance_id == 'null':
+                    if instance_id in ('null', None):
                         mapi.put(instance)
                     else:
                         mapi.update(instance)
@@ -204,10 +209,11 @@ def apply_tracked_changes(tracked_changes, model):
         for key, value in successfully_updated_changes.items():
             if not value:
                 del successfully_updated_changes[key]
-        model.logger.error(
-            'Registering all the changes to the storage has failed. {0}'
-            'The successful updates were: {0} '
-            '{1}'.format(os.linesep, json.dumps(successfully_updated_changes, indent=4)))
+        # TODO: if the successful has _STUB, the logging fails because it can't serialize the object
+        # model.logger.error(
+        #     'Registering all the changes to the storage has failed. {0}'
+        #     'The successful updates were: {0} '
+        #     '{1}'.format(os.linesep, json.dumps(successfully_updated_changes, indent=4)))
 
         raise
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c8896ab5/examples/hello-world/scripts/configure.sh
----------------------------------------------------------------------
diff --git a/examples/hello-world/scripts/configure.sh b/examples/hello-world/scripts/configure.sh
index b55ec17..6e93053 100755
--- a/examples/hello-world/scripts/configure.sh
+++ b/examples/hello-world/scripts/configure.sh
@@ -8,7 +8,7 @@ if [ -d ${PYTHON_FILE_SERVER_ROOT} ]; then
 	echo "Removing file server root folder ${PYTHON_FILE_SERVER_ROOT}"
 	rm -rf ${PYTHON_FILE_SERVER_ROOT}
 fi
-ctx logger info "Creating HTTP server root directory at ${PYTHON_FILE_SERVER_ROOT}"
+#ctx logger info "Creating HTTP server root directory at ${PYTHON_FILE_SERVER_ROOT}"
 
 mkdir -p ${PYTHON_FILE_SERVER_ROOT}
 
@@ -17,7 +17,7 @@ cd ${PYTHON_FILE_SERVER_ROOT}
 index_path="index.html"
 image_path="images/aria-logo.png"
 
-ctx logger info "Downloading blueprint resources..."
+#ctx logger info "Downloading blueprint resources..."
 ctx download-resource-and-render ${PYTHON_FILE_SERVER_ROOT}/index.html ${index_path}
 ctx download-resource ${PYTHON_FILE_SERVER_ROOT}/aria-logo.png ${image_path}
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c8896ab5/examples/hello-world/scripts/start.sh
----------------------------------------------------------------------
diff --git a/examples/hello-world/scripts/start.sh b/examples/hello-world/scripts/start.sh
index 96298c5..03c59d4 100755
--- a/examples/hello-world/scripts/start.sh
+++ b/examples/hello-world/scripts/start.sh
@@ -6,16 +6,16 @@ TEMP_DIR="/tmp"
 PYTHON_FILE_SERVER_ROOT=${TEMP_DIR}/python-simple-http-webserver
 PID_FILE="server.pid"
 
-ctx logger info "Starting HTTP server from ${PYTHON_FILE_SERVER_ROOT}"
+#ctx logger info "Starting HTTP server from ${PYTHON_FILE_SERVER_ROOT}"
 
 port=$(ctx node properties port)
 
 cd ${PYTHON_FILE_SERVER_ROOT}
-ctx logger info "Starting SimpleHTTPServer"
+#ctx logger info "Starting SimpleHTTPServer"
 nohup python -m SimpleHTTPServer ${port} > /dev/null 2>&1 &
 echo $! > ${PID_FILE}
 
-ctx logger info "Waiting for server to launch on port ${port}"
+#ctx logger info "Waiting for server to launch on port ${port}"
 url="http://localhost:${port}"
 
 server_is_up() {
@@ -28,7 +28,7 @@ server_is_up() {
 			return 0
 		fi
 	else
-		ctx logger error "Both curl, wget were not found in path"
+#		ctx logger error "Both curl, wget were not found in path"
 		exit 1
 	fi
 	return 1
@@ -38,15 +38,15 @@ STARTED=false
 for i in $(seq 1 15)
 do
 	if server_is_up; then
-		ctx logger info "Server is up."
+#		ctx logger info "Server is up."
 		STARTED=true
     	break
 	else
-		ctx logger info "Server not up. waiting 1 second."
+#		ctx logger info "Server not up. waiting 1 second."
 		sleep 1
 	fi
 done
 if [ ${STARTED} = false ]; then
-	ctx logger error "Failed starting web server in 15 seconds."
+#	ctx logger error "Failed starting web server in 15 seconds."
 	exit 1
 fi

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c8896ab5/examples/hello-world/scripts/stop.sh
----------------------------------------------------------------------
diff --git a/examples/hello-world/scripts/stop.sh b/examples/hello-world/scripts/stop.sh
index 5461caf..63e1971 100755
--- a/examples/hello-world/scripts/stop.sh
+++ b/examples/hello-world/scripts/stop.sh
@@ -8,8 +8,8 @@ PID_FILE="server.pid"
 
 PID=`cat ${PYTHON_FILE_SERVER_ROOT}/${PID_FILE}`
 
-ctx logger info "Shutting down file server. pid = ${PID}"
+#ctx logger info "Shutting down file server. pid = ${PID}"
 kill -9 ${PID} || exit $?
 
-ctx logger info "Deleting file server root directory (${PYTHON_FILE_SERVER_ROOT})"
+#ctx logger info "Deleting file server root directory (${PYTHON_FILE_SERVER_ROOT})"
 rm -rf ${PYTHON_FILE_SERVER_ROOT}