You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by la...@apache.org on 2016/09/16 16:12:23 UTC
[48/48] airavata git commit: Add mdc to orchestrator
Add mdc to orchestrator
Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/6786f8ee
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/6786f8ee
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/6786f8ee
Branch: refs/heads/lahiru/AIRAVATA-2065
Commit: 6786f8ee0eb48ecd3b6e0984b6ff1ddab4f2404d
Parents: 091546f
Author: Lahiru Ginnaliya Gamathige <la...@apache.org>
Authored: Fri Sep 16 09:11:04 2016 -0700
Committer: Lahiru Ginnaliya Gamathige <la...@apache.org>
Committed: Fri Sep 16 09:11:04 2016 -0700
----------------------------------------------------------------------
.../airavata/common/logging/MDCConstants.java | 28 ++++++++++++++++++++
.../server/OrchestratorServerHandler.java | 28 +++++++++++++++-----
2 files changed, 49 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/airavata/blob/6786f8ee/modules/commons/src/main/java/org/apache/airavata/common/logging/MDCConstants.java
----------------------------------------------------------------------
diff --git a/modules/commons/src/main/java/org/apache/airavata/common/logging/MDCConstants.java b/modules/commons/src/main/java/org/apache/airavata/common/logging/MDCConstants.java
new file mode 100644
index 0000000..34e1911
--- /dev/null
+++ b/modules/commons/src/main/java/org/apache/airavata/common/logging/MDCConstants.java
@@ -0,0 +1,28 @@
+/*
+ *
+ * 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.airavata.common.logging;
+
+
+public class MDCConstants {
+ public static final String EXPERIMENT_ID = "experiment_id";
+ public static final String GATEWAY_ID = "gateway_id";
+ public static final String EXPERIMENT_NAME = "experiment_name";
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/6786f8ee/modules/orchestrator/orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java
----------------------------------------------------------------------
diff --git a/modules/orchestrator/orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java b/modules/orchestrator/orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java
index 725a0b1..2ac0fd1 100644
--- a/modules/orchestrator/orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java
+++ b/modules/orchestrator/orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java
@@ -23,6 +23,7 @@ package org.apache.airavata.orchestrator.server;
import org.apache.airavata.common.exception.AiravataException;
import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.logging.MDCConstants;
import org.apache.airavata.common.utils.AiravataUtils;
import org.apache.airavata.common.utils.ServerSettings;
import org.apache.airavata.common.utils.ThriftUtils;
@@ -62,6 +63,7 @@ import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.utils.ZKPaths;
+import org.apache.log4j.MDC;
import org.apache.thrift.TBase;
import org.apache.thrift.TException;
import org.apache.zookeeper.data.Stat;
@@ -591,7 +593,7 @@ public class OrchestratorServerHandler implements OrchestratorService.Iface {
@Override
public void onMessage(MessageContext messageContext) {
-
+ MDC.put(MDCConstants.GATEWAY_ID, messageContext.getGatewayId());
switch (messageContext.getType()) {
case EXPERIMENT:
launchExperiment(messageContext);
@@ -604,6 +606,7 @@ public class OrchestratorServerHandler implements OrchestratorService.Iface {
log.error("Orchestrator got un-support message type : " + messageContext.getType());
break;
}
+ MDC.clear();
}
private void cancelExperiment(MessageContext messageContext) {
@@ -611,6 +614,7 @@ public class OrchestratorServerHandler implements OrchestratorService.Iface {
byte[] bytes = ThriftUtils.serializeThriftObject(messageContext.getEvent());
ExperimentSubmitEvent expEvent = new ExperimentSubmitEvent();
ThriftUtils.createThriftFromBytes(bytes, expEvent);
+ log.info("Cancelling experiment with experimentId: %s gateway Id: %s", expEvent.getExperimentId(), expEvent.getGatewayId());
terminateExperiment(expEvent.getExperimentId(), expEvent.getGatewayId());
} catch (TException e) {
log.error("Experiment cancellation failed due to Thrift conversion error", e);
@@ -622,13 +626,16 @@ public class OrchestratorServerHandler implements OrchestratorService.Iface {
}
private void launchExperiment(MessageContext messageContext) {
+ ExperimentSubmitEvent expEvent = new ExperimentSubmitEvent();
try {
- byte[] bytes = ThriftUtils.serializeThriftObject(messageContext.getEvent());
- ExperimentSubmitEvent expEvent = new ExperimentSubmitEvent();
- ThriftUtils.createThriftFromBytes(bytes, expEvent);
- if (messageContext.isRedeliver()) {
+ byte[] bytes = ThriftUtils.serializeThriftObject(messageContext.getEvent());
+ ThriftUtils.createThriftFromBytes(bytes, expEvent);
+ MDC.put(MDCConstants.EXPERIMENT_ID, expEvent.getExperimentId());
+ log.info("Launching experiment with experimentId: %s gateway Id: %s", expEvent.getExperimentId(), expEvent.getGatewayId());
+ if (messageContext.isRedeliver()) {
ExperimentModel experimentModel = (ExperimentModel) experimentCatalog.
get(ExperimentCatalogModelType.EXPERIMENT, expEvent.getExperimentId());
+ MDC.put(MDCConstants.EXPERIMENT_NAME, experimentModel.getExperimentName());
if (experimentModel.getExperimentStatus().get(0).getState() == ExperimentState.CREATED) {
launchExperiment(expEvent.getExperimentId(), expEvent.getGatewayId());
}
@@ -636,11 +643,18 @@ public class OrchestratorServerHandler implements OrchestratorService.Iface {
launchExperiment(expEvent.getExperimentId(), expEvent.getGatewayId());
}
} catch (TException e) {
- log.error("Experiment launch failed due to Thrift conversion error", e);
+ String logMessage = expEvent.getExperimentId() != null && expEvent.getGatewayId() != null ?
+ String.format("Experiment launch failed due to Thrift conversion error, experimentId: %s, gatewayId: %s",
+ expEvent.getExperimentId(), expEvent.getGatewayId()): "Experiment launch failed due to Thrift conversion error";
+ log.error(logMessage, e);
} catch (RegistryException e) {
- log.error("Experiment launch failed due to registry access issue", e);
+ String logMessage = expEvent.getExperimentId() != null && expEvent.getGatewayId() != null ?
+ String.format("Experiment launch failed due to registry access issue, experimentId: %s, gatewayId: %s",
+ expEvent.getExperimentId(), expEvent.getGatewayId()): "Experiment launch failed due to registry access issue";
+ log.error(logMessage, e);
}finally {
experimentSubscriber.sendAck(messageContext.getDeliveryTag());
+ MDC.clear();
}
}