You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by am...@apache.org on 2017/10/03 16:47:32 UTC
incubator-unomi git commit: UNOMI-128 : Deleting an import/export
config does not stop running one
Repository: incubator-unomi
Updated Branches:
refs/heads/master cc8c14d10 -> 8baf62691
UNOMI-128 : Deleting an import/export config does not stop running one
Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/8baf6269
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/8baf6269
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/8baf6269
Branch: refs/heads/master
Commit: 8baf6269140f1b4e4176148ddd8f083f256d4601
Parents: cc8c14d
Author: Abdelkader Midani <am...@apache.org>
Authored: Tue Oct 3 18:46:59 2017 +0200
Committer: Abdelkader Midani <am...@apache.org>
Committed: Tue Oct 3 18:47:17 2017 +0200
----------------------------------------------------------------------
.../router/core/context/RouterCamelContext.java | 2 +-
.../core/processor/ConfigDeleteProcessor.java | 43 ++++++++++++++++++++
.../core/route/ConfigUpdateRouteBuilder.java | 24 +++++++----
.../AbstractConfigurationServiceEndpoint.java | 5 +--
.../ExportConfigurationServiceEndPoint.java | 25 ++++++++++++
.../ImportConfigurationServiceEndPoint.java | 27 +++++++++++-
6 files changed, 112 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8baf6269/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/context/RouterCamelContext.java
----------------------------------------------------------------------
diff --git a/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/context/RouterCamelContext.java b/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/context/RouterCamelContext.java
index 302b77d..a8e0b81 100644
--- a/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/context/RouterCamelContext.java
+++ b/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/context/RouterCamelContext.java
@@ -163,7 +163,7 @@ public class RouterCamelContext implements SynchronousBundleListener {
return camelContext.stopRoute(routeId, 10L, TimeUnit.SECONDS, true);
}
- private void killExistingRoute(String routeId) throws Exception {
+ public void killExistingRoute(String routeId) throws Exception {
//Active routes
Route route = camelContext.getRoute(routeId);
if (route != null && stopRoute(routeId)) {
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8baf6269/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/processor/ConfigDeleteProcessor.java
----------------------------------------------------------------------
diff --git a/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/processor/ConfigDeleteProcessor.java b/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/processor/ConfigDeleteProcessor.java
new file mode 100644
index 0000000..1022113
--- /dev/null
+++ b/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/processor/ConfigDeleteProcessor.java
@@ -0,0 +1,43 @@
+/*
+ * 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.unomi.router.core.processor;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.unomi.router.core.context.RouterCamelContext;
+
+/**
+ * Created by amidani on 03/10/2017.
+ */
+public class ConfigDeleteProcessor implements Processor {
+
+ private RouterCamelContext routerCamelContext;
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ if (exchange.getIn() != null) {
+ Message message = exchange.getIn();
+ String routeId = message.getHeader("id", String.class);
+ routerCamelContext.killExistingRoute(routeId);
+ }
+ }
+
+ public void setRouterCamelContext(RouterCamelContext routerCamelContext) {
+ this.routerCamelContext = routerCamelContext;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8baf6269/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/route/ConfigUpdateRouteBuilder.java
----------------------------------------------------------------------
diff --git a/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/route/ConfigUpdateRouteBuilder.java b/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/route/ConfigUpdateRouteBuilder.java
index 885713a..eff48c2 100644
--- a/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/route/ConfigUpdateRouteBuilder.java
+++ b/extensions/router/router-core/src/main/java/org/apache/unomi/router/core/route/ConfigUpdateRouteBuilder.java
@@ -21,6 +21,7 @@ import org.apache.camel.model.rest.RestBindingMode;
import org.apache.unomi.router.api.ExportConfiguration;
import org.apache.unomi.router.api.ImportConfiguration;
import org.apache.unomi.router.core.context.RouterCamelContext;
+import org.apache.unomi.router.core.processor.ConfigDeleteProcessor;
import org.apache.unomi.router.core.processor.ConfigUpdateProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,27 +43,34 @@ public class ConfigUpdateRouteBuilder extends RouteBuilder {
.bindingMode(RestBindingMode.json)
.dataFormatProperty("prettyPrint", "true");
- rest().put("/importConfigAdmin").consumes("application/json").type(ImportConfiguration.class)
- .to("direct:importConfigRestDeposit");
+ rest("/importConfigAdmin")
+ .put().consumes("application/json").type(ImportConfiguration.class)
+ .to("direct:configUpdateRestDeposit")
+ .delete("/{id}").to("direct:configDeleteRestDeposit");
+
+ rest("/exportConfigAdmin")
+ .put().consumes("application/json").type(ExportConfiguration.class)
+ .to("direct:configUpdateRestDeposit")
+ .delete("/{id}").to("direct:configDeleteRestDeposit");
+
ConfigUpdateProcessor profileConfigUpdateProcessor = new ConfigUpdateProcessor();
profileConfigUpdateProcessor.setRouterCamelContext(routerCamelContext);
- from("direct:importConfigRestDeposit")
+ from("direct:configUpdateRestDeposit")
.process(profileConfigUpdateProcessor)
.transform().constant("Success.")
.onException(Exception.class)
.transform().constant("Failure!");
- rest().put("/exportConfigAdmin").consumes("application/json").type(ExportConfiguration.class)
- .to("direct:exportConfigRestDeposit");
- from("direct:exportConfigRestDeposit")
- .process(profileConfigUpdateProcessor)
+ ConfigDeleteProcessor profileConfigDeleteProcessor = new ConfigDeleteProcessor();
+ profileConfigDeleteProcessor.setRouterCamelContext(routerCamelContext);
+ from("direct:configDeleteRestDeposit")
+ .process(profileConfigDeleteProcessor)
.transform().constant("Success.")
.onException(Exception.class)
.transform().constant("Failure!");
-
}
public void setRouterCamelContext(RouterCamelContext routerCamelContext) {
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8baf6269/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/AbstractConfigurationServiceEndpoint.java
----------------------------------------------------------------------
diff --git a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/AbstractConfigurationServiceEndpoint.java b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/AbstractConfigurationServiceEndpoint.java
index 89b4b0c..9d48a6a 100644
--- a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/AbstractConfigurationServiceEndpoint.java
+++ b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/AbstractConfigurationServiceEndpoint.java
@@ -79,9 +79,6 @@ public abstract class AbstractConfigurationServiceEndpoint<T> {
@Path("/{configId}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
- public void deleteConfiguration(@PathParam("configId") String configId) {
- this.configurationService.delete(configId);
- }
-
+ public abstract void deleteConfiguration(@PathParam("configId") String configId);
}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8baf6269/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ExportConfigurationServiceEndPoint.java
----------------------------------------------------------------------
diff --git a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ExportConfigurationServiceEndPoint.java b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ExportConfigurationServiceEndPoint.java
index 366049f..8da7887 100644
--- a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ExportConfigurationServiceEndPoint.java
+++ b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ExportConfigurationServiceEndPoint.java
@@ -19,6 +19,7 @@ package org.apache.unomi.router.rest;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.cxf.rs.security.cors.CrossOriginResourceSharing;
import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
@@ -107,6 +108,30 @@ public class ExportConfigurationServiceEndPoint extends AbstractConfigurationSer
return exportConfigSaved;
}
+ @Override
+ public void deleteConfiguration(String configId) {
+ this.configurationService.delete(configId);
+
+ CloseableHttpClient httpClient = HttpClients.createDefault();
+ try {
+ HttpDelete httpDelete = new HttpDelete(configSharingService.getProperty("internalServerAddress") + "/configUpdate/exportConfigAdmin/" + configId);
+
+ HttpResponse response = httpClient.execute(httpDelete);
+
+ if (response.getStatusLine().getStatusCode() != 200) {
+ logger.error("Failed to update the running config: Please check the accessibility to the URI: \n{}",
+ configSharingService.getProperty("internalServerAddress") + "/configUpdate/exportConfigAdmin/" + configId);
+ logger.error("HTTP Status code returned {}", response.getStatusLine().getStatusCode());
+ throw new PartialContentException("RUNNING_CONFIG_UPDATE_FAILED");
+ }
+ } catch (Exception e) {
+ logger.warn("Unable to delete Camel route [{}]", configId);
+ logger.debug("Unable to delete Camel route", e);
+ throw new PartialContentException("RUNNING_CONFIG_UPDATE_FAILED");
+
+ }
+ }
+
/**
* Save/Update the given import configuration.
* Prepare the file to be processed with Camel routes
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/8baf6269/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java
----------------------------------------------------------------------
diff --git a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java
index 7cc6b4e..4baf3c5 100644
--- a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java
+++ b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java
@@ -21,6 +21,7 @@ import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.apache.cxf.rs.security.cors.CrossOriginResourceSharing;
import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
@@ -97,11 +98,35 @@ public class ImportConfigurationServiceEndPoint extends AbstractConfigurationSer
return importConfigSaved;
}
+ @Override
+ public void deleteConfiguration(String configId) {
+ this.configurationService.delete(configId);
+
+ CloseableHttpClient httpClient = HttpClients.createDefault();
+ try {
+ HttpDelete httpDelete = new HttpDelete(configSharingService.getProperty("internalServerAddress") + "/configUpdate/importConfigAdmin/" + configId);
+
+ HttpResponse response = httpClient.execute(httpDelete);
+
+ if (response.getStatusLine().getStatusCode() != 200) {
+ logger.error("Failed to update the running config: Please check the accessibility to the URI: \n{}",
+ configSharingService.getProperty("internalServerAddress") + "/configUpdate/importConfigAdmin/" + configId);
+ logger.error("HTTP Status code returned {}", response.getStatusLine().getStatusCode());
+ throw new PartialContentException("RUNNING_CONFIG_UPDATE_FAILED");
+ }
+ } catch (Exception e) {
+ logger.warn("Unable to delete Camel route [{}]", configId);
+ logger.debug("Unable to delete Camel route", e);
+ throw new PartialContentException("RUNNING_CONFIG_UPDATE_FAILED");
+
+ }
+ }
+
/**
* Save/Update the given import configuration.
* Prepare the file to be processed with Camel routes
*
- * @param file file
+ * @param file file
* @param importConfigId config
* @return OK / NOK Http Code.
*/