You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/04/26 10:56:17 UTC
[1/4] camel git commit: CAMEL-9683: Renamed to ServiceCall
Repository: camel
Updated Branches:
refs/heads/kube-lb 7c9f11973 -> 3b0b4d036
CAMEL-9683: Renamed to ServiceCall
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ea4e10e9
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ea4e10e9
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ea4e10e9
Branch: refs/heads/kube-lb
Commit: ea4e10e9f9285a13e2761e9b44f7a520a98fc07f
Parents: 7c9f119
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 26 09:55:28 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 26 09:56:11 2016 +0200
----------------------------------------------------------------------
.../apache/camel/model/ProcessorDefinition.java | 8 +-
.../ServiceCallConfigurationDefinition.java | 326 +++++++++++++++++++
.../camel/model/ServiceCallDefinition.java | 201 ++++++++++++
.../model/ToServiceConfigurationDefinition.java | 326 -------------------
.../apache/camel/model/ToServiceDefinition.java | 201 ------------
.../resources/org/apache/camel/model/jaxb.index | 4 +-
.../processor/KubernetesProcessorFactory.java | 16 +-
.../processor/KubernetesServiceDiscovery.java | 1 -
.../processor/KubernetesServiceProcessor.java | 1 +
.../apache/camel/model/ServiceCallDefinition | 18 +
.../org/apache/camel/model/ToServiceDefinition | 18 -
.../processor/ServiceCallRouteTest.java | 54 +++
.../processor/ToServiceRouteTest.java | 54 ---
13 files changed, 614 insertions(+), 614 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ea4e10e9/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index 6c0e8f9..4849b9a 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -654,18 +654,18 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
}
/**
- * Sends the exchange to the given service
+ * Calls the service
*
* @param name the service name
* @param uri the endpoint uri to use for calling the service
* @return the builder
*/
@SuppressWarnings("unchecked")
- public Type toService(String name, String uri, ToServiceConfigurationDefinition configuration) {
- ToServiceDefinition answer = new ToServiceDefinition();
+ public Type serviceCall(String name, String uri, ServiceCallConfigurationDefinition configuration) {
+ ServiceCallDefinition answer = new ServiceCallDefinition();
answer.setName(name);
answer.setUri(uri);
- answer.setToServiceConfiguration(configuration);
+ answer.setServiceCallConfiguration(configuration);
addOutput(answer);
return (Type) this;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/ea4e10e9/camel-core/src/main/java/org/apache/camel/model/ServiceCallConfigurationDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ServiceCallConfigurationDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ServiceCallConfigurationDefinition.java
new file mode 100644
index 0000000..2363a63
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/ServiceCallConfigurationDefinition.java
@@ -0,0 +1,326 @@
+/**
+ * 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.camel.model;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.spi.Metadata;
+
+@Metadata(label = "eip,routing")
+@XmlRootElement(name = "toServiceConfiguration")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ServiceCallConfigurationDefinition extends IdentifiedType {
+
+ @XmlTransient
+ private ServiceCallDefinition parent;
+ @XmlAttribute @Metadata(required = "true")
+ private String masterUrl;
+ @XmlAttribute
+ private String namespace;
+ @XmlAttribute
+ private String apiVersion;
+ @XmlAttribute @Metadata(label = "security")
+ private String username;
+ @XmlAttribute @Metadata(label = "security")
+ private String password;
+ @XmlAttribute @Metadata(label = "security")
+ private String oauthToken;
+ @XmlAttribute @Metadata(label = "security")
+ private String caCertData;
+ @XmlAttribute @Metadata(label = "security")
+ private String caCertFile;
+ @XmlAttribute @Metadata(label = "security")
+ private String clientCertData;
+ @XmlAttribute @Metadata(label = "security")
+ private String clientCertFile;
+ @XmlAttribute @Metadata(label = "security")
+ private String clientKeyAlgo;
+ @XmlAttribute @Metadata(label = "security")
+ private String clientKeyData;
+ @XmlAttribute @Metadata(label = "security")
+ private String clientKeyFile;
+ @XmlAttribute @Metadata(label = "security")
+ private String clientKeyPassphrase;
+ @XmlAttribute @Metadata(label = "security")
+ private Boolean trustCerts;
+
+ public ServiceCallConfigurationDefinition() {
+ }
+
+ public ServiceCallConfigurationDefinition(ServiceCallDefinition parent) {
+ this.parent = parent;
+ }
+
+ // Getter/Setter
+ // -------------------------------------------------------------------------
+
+ public String getMasterUrl() {
+ return masterUrl;
+ }
+
+ public void setMasterUrl(String masterUrl) {
+ this.masterUrl = masterUrl;
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ public String getApiVersion() {
+ return apiVersion;
+ }
+
+ public void setApiVersion(String apiVersion) {
+ this.apiVersion = apiVersion;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getCaCertData() {
+ return caCertData;
+ }
+
+ public void setCaCertData(String caCertData) {
+ this.caCertData = caCertData;
+ }
+
+ public String getCaCertFile() {
+ return caCertFile;
+ }
+
+ public void setCaCertFile(String caCertFile) {
+ this.caCertFile = caCertFile;
+ }
+
+ public String getClientCertData() {
+ return clientCertData;
+ }
+
+ public void setClientCertData(String clientCertData) {
+ this.clientCertData = clientCertData;
+ }
+
+ public String getClientCertFile() {
+ return clientCertFile;
+ }
+
+ public void setClientCertFile(String clientCertFile) {
+ this.clientCertFile = clientCertFile;
+ }
+
+ public String getClientKeyAlgo() {
+ return clientKeyAlgo;
+ }
+
+ public void setClientKeyAlgo(String clientKeyAlgo) {
+ this.clientKeyAlgo = clientKeyAlgo;
+ }
+
+ public String getClientKeyData() {
+ return clientKeyData;
+ }
+
+ public void setClientKeyData(String clientKeyData) {
+ this.clientKeyData = clientKeyData;
+ }
+
+ public String getClientKeyFile() {
+ return clientKeyFile;
+ }
+
+ public void setClientKeyFile(String clientKeyFile) {
+ this.clientKeyFile = clientKeyFile;
+ }
+
+ public String getClientKeyPassphrase() {
+ return clientKeyPassphrase;
+ }
+
+ public void setClientKeyPassphrase(String clientKeyPassphrase) {
+ this.clientKeyPassphrase = clientKeyPassphrase;
+ }
+
+ public String getOauthToken() {
+ return oauthToken;
+ }
+
+ public void setOauthToken(String oauthToken) {
+ this.oauthToken = oauthToken;
+ }
+
+ public Boolean getTrustCerts() {
+ return trustCerts;
+ }
+
+ public void setTrustCerts(Boolean trustCerts) {
+ this.trustCerts = trustCerts;
+ }
+
+
+ // Fluent API
+ // -------------------------------------------------------------------------
+
+ /**
+ * Sets the URL to the master
+ */
+ public ServiceCallConfigurationDefinition masterUrl(String masterUrl) {
+ setMasterUrl(masterUrl);
+ return this;
+ }
+
+ /**
+ * Sets the namespace to use
+ */
+ public ServiceCallConfigurationDefinition namespace(String namespace) {
+ setNamespace(namespace);
+ return this;
+ }
+
+ /**
+ * Sets the API version
+ */
+ public ServiceCallConfigurationDefinition apiVersion(String apiVersion) {
+ setApiVersion(apiVersion);
+ return this;
+ }
+
+ /**
+ * Sets the username for authentication
+ */
+ public ServiceCallConfigurationDefinition username(String username) {
+ setUsername(username);
+ return this;
+ }
+
+ /**
+ * Sets the password for authentication
+ */
+ public ServiceCallConfigurationDefinition password(String password) {
+ setPassword(password);
+ return this;
+ }
+
+ /**
+ * Sets the OAUTH token for authentication (instead of username/password)
+ */
+ public ServiceCallConfigurationDefinition oauthToken(String oauthToken) {
+ setOauthToken(oauthToken);
+ return this;
+ }
+
+ /**
+ * Sets the Certificate Authority data
+ */
+ public ServiceCallConfigurationDefinition caCertData(String caCertData) {
+ setCaCertData(caCertData);
+ return this;
+ }
+
+ /**
+ * Sets the Certificate Authority data that are loaded from the file
+ */
+ public ServiceCallConfigurationDefinition caCertFile(String caCertFile) {
+ setCaCertFile(caCertFile);
+ return this;
+ }
+
+ /**
+ * Sets the Client Certificate data
+ */
+ public ServiceCallConfigurationDefinition clientCertData(String clientCertData) {
+ setClientCertData(clientCertData);
+ return this;
+ }
+
+ /**
+ * Sets the Client Certificate data that are loaded from the file
+ */
+ public ServiceCallConfigurationDefinition clientCertFile(String clientCertFile) {
+ setClientCertFile(clientCertFile);
+ return this;
+ }
+
+ /**
+ * Sets the Client Keystore algorithm, such as RSA.
+ */
+ public ServiceCallConfigurationDefinition clientKeyAlgo(String clientKeyAlgo) {
+ setClientKeyAlgo(clientKeyAlgo);
+ return this;
+ }
+
+ /**
+ * Sets the Client Keystore data
+ */
+ public ServiceCallConfigurationDefinition clientKeyData(String clientKeyData) {
+ setClientKeyData(clientKeyData);
+ return this;
+ }
+
+ /**
+ * Sets the Client Keystore data that are loaded from the file
+ */
+ public ServiceCallConfigurationDefinition clientKeyFile(String clientKeyFile) {
+ setClientKeyFile(clientKeyFile);
+ return this;
+ }
+
+ /**
+ * Sets the Client Keystore passphrase
+ */
+ public ServiceCallConfigurationDefinition clientKeyPassphrase(String clientKeyPassphrase) {
+ setClientKeyPassphrase(clientKeyPassphrase);
+ return this;
+ }
+
+ /**
+ * Sets whether to turn on trust certificate check
+ */
+ public ServiceCallConfigurationDefinition trustCerts(boolean trustCerts) {
+ setTrustCerts(trustCerts);
+ return this;
+ }
+
+ /**
+ * End of configuration
+ */
+ public ServiceCallDefinition end() {
+ return parent;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/ea4e10e9/camel-core/src/main/java/org/apache/camel/model/ServiceCallDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ServiceCallDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ServiceCallDefinition.java
new file mode 100644
index 0000000..7b2d1a5
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/ServiceCallDefinition.java
@@ -0,0 +1,201 @@
+/**
+ * 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.camel.model;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Processor;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.RouteContext;
+
+@Metadata(label = "eip,routing")
+@XmlRootElement(name = "serviceCall")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ServiceCallDefinition extends NoOutputDefinition<ServiceCallDefinition> {
+
+ // TODO: load balancing strategy
+
+ @XmlElement
+ private ServiceCallConfigurationDefinition serviceCallConfiguration;
+ @XmlAttribute @Metadata(required = "true")
+ private String uri;
+ @XmlAttribute
+ private ExchangePattern pattern;
+ @XmlAttribute @Metadata(defaultValue = "default")
+ private String namespace;
+ @XmlAttribute @Metadata(required = "true")
+ private String name;
+ @XmlAttribute
+ private String discovery;
+ @XmlAttribute
+ private String serviceCallConfigurationRef;
+
+ public ServiceCallDefinition() {
+ }
+
+ // serviceCall("myService") (will use http by default)
+ // serviceCall("myService/foo") (will use http by default)
+ // serviceCall("http:myService/foo")
+ // serviceCall("myService", "http:myService.host:myService.port/foo")
+ // serviceCall("myService", "netty4:tcp:myService?connectTimeout=1000")
+
+ @Override
+ public String toString() {
+ return "ServiceCall[" + name + "]";
+ }
+
+ @Override
+ public String getLabel() {
+ return "serviceCall";
+ }
+
+ @Override
+ public Processor createProcessor(RouteContext routeContext) throws Exception {
+ if (discovery != null) {
+ throw new IllegalStateException("Cannot find Camel component on the classpath implementing the discovery provider: " + discovery);
+ } else {
+ throw new IllegalStateException("Cannot find Camel component supporting the ToService EIP. Add camel-kubernetes if you are using Kubernetes.");
+ }
+ }
+
+ // Fluent API
+ // -------------------------------------------------------------------------
+
+ /**
+ * Sets the optional {@link ExchangePattern} used to invoke this endpoint
+ */
+ public ServiceCallDefinition pattern(ExchangePattern pattern) {
+ setPattern(pattern);
+ return this;
+ }
+
+ /**
+ * Sets the namespace of the service to use
+ */
+ public ServiceCallDefinition namespace(String namespace) {
+ setNamespace(namespace);
+ return this;
+ }
+
+ /**
+ * Sets the name of the service to use
+ */
+ public ServiceCallDefinition name(String name) {
+ setName(name);
+ return this;
+ }
+
+ /**
+ * Sets the discovery provided to use.
+ * <p/>
+ * Use kubernetes to use kubernetes.
+ * Use ribbon to use ribbon.
+ */
+ public ServiceCallDefinition discovery(String discovery) {
+ setDiscovery(discovery);
+ return this;
+ }
+
+ public ServiceCallConfigurationDefinition serviceCallConfiguration() {
+ serviceCallConfiguration = new ServiceCallConfigurationDefinition(this);
+ return serviceCallConfiguration;
+ }
+
+ /**
+ * Configures the ServiceCall using the given configuration
+ */
+ public ServiceCallDefinition serviceCallConfiguration(ServiceCallConfigurationDefinition configuration) {
+ serviceCallConfiguration = configuration;
+ return this;
+ }
+
+ /**
+ * Refers to a ServiceCall configuration to use
+ */
+ public ServiceCallDefinition serviceCallConfiguration(String ref) {
+ serviceCallConfigurationRef = ref;
+ return this;
+ }
+
+ // Properties
+ // -------------------------------------------------------------------------
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ public ExchangePattern getPattern() {
+ return pattern;
+ }
+
+ public void setPattern(ExchangePattern pattern) {
+ this.pattern = pattern;
+ }
+
+ public String getDiscovery() {
+ return discovery;
+ }
+
+ public void setDiscovery(String discovery) {
+ this.discovery = discovery;
+ }
+
+ public ServiceCallConfigurationDefinition getServiceCallConfiguration() {
+ return serviceCallConfiguration;
+ }
+
+ public void setServiceCallConfiguration(ServiceCallConfigurationDefinition serviceCallConfiguration) {
+ this.serviceCallConfiguration = serviceCallConfiguration;
+ }
+
+ public String getServiceCallConfigurationRef() {
+ return serviceCallConfigurationRef;
+ }
+
+ public void setServiceCallConfigurationRef(String serviceCallConfigurationRef) {
+ this.serviceCallConfigurationRef = serviceCallConfigurationRef;
+ }
+
+ public String getUri() {
+ return uri;
+ }
+
+ /**
+ * The uri of the endpoint to send to.
+ * The uri can be dynamic computed using the {@link org.apache.camel.language.simple.SimpleLanguage} expression.
+ */
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/ea4e10e9/camel-core/src/main/java/org/apache/camel/model/ToServiceConfigurationDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ToServiceConfigurationDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ToServiceConfigurationDefinition.java
deleted file mode 100644
index f42205e..0000000
--- a/camel-core/src/main/java/org/apache/camel/model/ToServiceConfigurationDefinition.java
+++ /dev/null
@@ -1,326 +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.
- */
-package org.apache.camel.model;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlTransient;
-
-import org.apache.camel.spi.Metadata;
-
-@Metadata(label = "eip,routing")
-@XmlRootElement(name = "toServiceConfiguration")
-@XmlAccessorType(XmlAccessType.FIELD)
-public class ToServiceConfigurationDefinition extends IdentifiedType {
-
- @XmlTransient
- private ToServiceDefinition parent;
- @XmlAttribute @Metadata(required = "true")
- private String masterUrl;
- @XmlAttribute
- private String namespace;
- @XmlAttribute
- private String apiVersion;
- @XmlAttribute @Metadata(label = "security")
- private String username;
- @XmlAttribute @Metadata(label = "security")
- private String password;
- @XmlAttribute @Metadata(label = "security")
- private String oauthToken;
- @XmlAttribute @Metadata(label = "security")
- private String caCertData;
- @XmlAttribute @Metadata(label = "security")
- private String caCertFile;
- @XmlAttribute @Metadata(label = "security")
- private String clientCertData;
- @XmlAttribute @Metadata(label = "security")
- private String clientCertFile;
- @XmlAttribute @Metadata(label = "security")
- private String clientKeyAlgo;
- @XmlAttribute @Metadata(label = "security")
- private String clientKeyData;
- @XmlAttribute @Metadata(label = "security")
- private String clientKeyFile;
- @XmlAttribute @Metadata(label = "security")
- private String clientKeyPassphrase;
- @XmlAttribute @Metadata(label = "security")
- private Boolean trustCerts;
-
- public ToServiceConfigurationDefinition() {
- }
-
- public ToServiceConfigurationDefinition(ToServiceDefinition parent) {
- this.parent = parent;
- }
-
- // Getter/Setter
- // -------------------------------------------------------------------------
-
- public String getMasterUrl() {
- return masterUrl;
- }
-
- public void setMasterUrl(String masterUrl) {
- this.masterUrl = masterUrl;
- }
-
- public String getNamespace() {
- return namespace;
- }
-
- public void setNamespace(String namespace) {
- this.namespace = namespace;
- }
-
- public String getApiVersion() {
- return apiVersion;
- }
-
- public void setApiVersion(String apiVersion) {
- this.apiVersion = apiVersion;
- }
-
- public String getUsername() {
- return username;
- }
-
- public void setUsername(String username) {
- this.username = username;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
- public String getCaCertData() {
- return caCertData;
- }
-
- public void setCaCertData(String caCertData) {
- this.caCertData = caCertData;
- }
-
- public String getCaCertFile() {
- return caCertFile;
- }
-
- public void setCaCertFile(String caCertFile) {
- this.caCertFile = caCertFile;
- }
-
- public String getClientCertData() {
- return clientCertData;
- }
-
- public void setClientCertData(String clientCertData) {
- this.clientCertData = clientCertData;
- }
-
- public String getClientCertFile() {
- return clientCertFile;
- }
-
- public void setClientCertFile(String clientCertFile) {
- this.clientCertFile = clientCertFile;
- }
-
- public String getClientKeyAlgo() {
- return clientKeyAlgo;
- }
-
- public void setClientKeyAlgo(String clientKeyAlgo) {
- this.clientKeyAlgo = clientKeyAlgo;
- }
-
- public String getClientKeyData() {
- return clientKeyData;
- }
-
- public void setClientKeyData(String clientKeyData) {
- this.clientKeyData = clientKeyData;
- }
-
- public String getClientKeyFile() {
- return clientKeyFile;
- }
-
- public void setClientKeyFile(String clientKeyFile) {
- this.clientKeyFile = clientKeyFile;
- }
-
- public String getClientKeyPassphrase() {
- return clientKeyPassphrase;
- }
-
- public void setClientKeyPassphrase(String clientKeyPassphrase) {
- this.clientKeyPassphrase = clientKeyPassphrase;
- }
-
- public String getOauthToken() {
- return oauthToken;
- }
-
- public void setOauthToken(String oauthToken) {
- this.oauthToken = oauthToken;
- }
-
- public Boolean getTrustCerts() {
- return trustCerts;
- }
-
- public void setTrustCerts(Boolean trustCerts) {
- this.trustCerts = trustCerts;
- }
-
-
- // Fluent API
- // -------------------------------------------------------------------------
-
- /**
- * Sets the URL to the master
- */
- public ToServiceConfigurationDefinition masterUrl(String masterUrl) {
- setMasterUrl(masterUrl);
- return this;
- }
-
- /**
- * Sets the namespace to use
- */
- public ToServiceConfigurationDefinition namespace(String namespace) {
- setNamespace(namespace);
- return this;
- }
-
- /**
- * Sets the API version
- */
- public ToServiceConfigurationDefinition apiVersion(String apiVersion) {
- setApiVersion(apiVersion);
- return this;
- }
-
- /**
- * Sets the username for authentication
- */
- public ToServiceConfigurationDefinition username(String username) {
- setUsername(username);
- return this;
- }
-
- /**
- * Sets the password for authentication
- */
- public ToServiceConfigurationDefinition password(String password) {
- setPassword(password);
- return this;
- }
-
- /**
- * Sets the OAUTH token for authentication (instead of username/password)
- */
- public ToServiceConfigurationDefinition oauthToken(String oauthToken) {
- setOauthToken(oauthToken);
- return this;
- }
-
- /**
- * Sets the Certificate Authority data
- */
- public ToServiceConfigurationDefinition caCertData(String caCertData) {
- setCaCertData(caCertData);
- return this;
- }
-
- /**
- * Sets the Certificate Authority data that are loaded from the file
- */
- public ToServiceConfigurationDefinition caCertFile(String caCertFile) {
- setCaCertFile(caCertFile);
- return this;
- }
-
- /**
- * Sets the Client Certificate data
- */
- public ToServiceConfigurationDefinition clientCertData(String clientCertData) {
- setClientCertData(clientCertData);
- return this;
- }
-
- /**
- * Sets the Client Certificate data that are loaded from the file
- */
- public ToServiceConfigurationDefinition clientCertFile(String clientCertFile) {
- setClientCertFile(clientCertFile);
- return this;
- }
-
- /**
- * Sets the Client Keystore algorithm, such as RSA.
- */
- public ToServiceConfigurationDefinition clientKeyAlgo(String clientKeyAlgo) {
- setClientKeyAlgo(clientKeyAlgo);
- return this;
- }
-
- /**
- * Sets the Client Keystore data
- */
- public ToServiceConfigurationDefinition clientKeyData(String clientKeyData) {
- setClientKeyData(clientKeyData);
- return this;
- }
-
- /**
- * Sets the Client Keystore data that are loaded from the file
- */
- public ToServiceConfigurationDefinition clientKeyFile(String clientKeyFile) {
- setClientKeyFile(clientKeyFile);
- return this;
- }
-
- /**
- * Sets the Client Keystore passphrase
- */
- public ToServiceConfigurationDefinition clientKeyPassphrase(String clientKeyPassphrase) {
- setClientKeyPassphrase(clientKeyPassphrase);
- return this;
- }
-
- /**
- * Sets whether to turn on trust certificate check
- */
- public ToServiceConfigurationDefinition trustCerts(boolean trustCerts) {
- setTrustCerts(trustCerts);
- return this;
- }
-
- /**
- * End of configuration
- */
- public ToServiceDefinition end() {
- return parent;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/ea4e10e9/camel-core/src/main/java/org/apache/camel/model/ToServiceDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ToServiceDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ToServiceDefinition.java
deleted file mode 100644
index 1c5dfc4..0000000
--- a/camel-core/src/main/java/org/apache/camel/model/ToServiceDefinition.java
+++ /dev/null
@@ -1,201 +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.
- */
-package org.apache.camel.model;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-
-import org.apache.camel.ExchangePattern;
-import org.apache.camel.Processor;
-import org.apache.camel.spi.Metadata;
-import org.apache.camel.spi.RouteContext;
-
-@Metadata(label = "eip,routing")
-@XmlRootElement(name = "toService")
-@XmlAccessorType(XmlAccessType.FIELD)
-public class ToServiceDefinition extends NoOutputDefinition<ToServiceDefinition> {
-
- // TODO: load balancing strategy
-
- @XmlElement
- private ToServiceConfigurationDefinition toServiceConfiguration;
- @XmlAttribute @Metadata(required = "true")
- private String uri;
- @XmlAttribute
- private ExchangePattern pattern;
- @XmlAttribute @Metadata(defaultValue = "default")
- private String namespace;
- @XmlAttribute @Metadata(required = "true")
- private String name;
- @XmlAttribute
- private String discovery;
- @XmlAttribute
- private String toServiceConfigurationRef;
-
- public ToServiceDefinition() {
- }
-
- // toService("myService") (will use http by default)
- // toService("myService/foo") (will use http by default)
- // toService("http:myService/foo")
- // toService("myService", "http:myService.host:myService.port/foo")
- // toService("myService", "netty4:tcp:myService?connectTimeout=1000")
-
- @Override
- public String toString() {
- return "ToService[" + name + "]";
- }
-
- @Override
- public String getLabel() {
- return "toService";
- }
-
- @Override
- public Processor createProcessor(RouteContext routeContext) throws Exception {
- if (discovery != null) {
- throw new IllegalStateException("Cannot find Camel component on the classpath implementing the discovery provider: " + discovery);
- } else {
- throw new IllegalStateException("Cannot find Camel component supporting the ToService EIP. Add camel-kubernetes if you are using Kubernetes.");
- }
- }
-
- // Fluent API
- // -------------------------------------------------------------------------
-
- /**
- * Sets the optional {@link ExchangePattern} used to invoke this endpoint
- */
- public ToServiceDefinition pattern(ExchangePattern pattern) {
- setPattern(pattern);
- return this;
- }
-
- /**
- * Sets the namespace of the service to use
- */
- public ToServiceDefinition namespace(String namespace) {
- setNamespace(namespace);
- return this;
- }
-
- /**
- * Sets the name of the service to use
- */
- public ToServiceDefinition name(String name) {
- setName(name);
- return this;
- }
-
- /**
- * Sets the discovery provided to use.
- * <p/>
- * Use kubernetes to use kubernetes.
- * Use ribbon to use ribbon.
- */
- public ToServiceDefinition discovery(String discovery) {
- setDiscovery(discovery);
- return this;
- }
-
- public ToServiceConfigurationDefinition toServiceConfiguration() {
- toServiceConfiguration = new ToServiceConfigurationDefinition(this);
- return toServiceConfiguration;
- }
-
- /**
- * Configures the Hystrix EIP using the given configuration
- */
- public ToServiceDefinition toServiceConfiguration(ToServiceConfigurationDefinition configuration) {
- toServiceConfiguration = configuration;
- return this;
- }
-
- /**
- * Refers to a Hystrix configuration to use for configuring the Hystrix EIP.
- */
- public ToServiceDefinition toServiceConfiguration(String ref) {
- toServiceConfigurationRef = ref;
- return this;
- }
-
- // Properties
- // -------------------------------------------------------------------------
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getNamespace() {
- return namespace;
- }
-
- public void setNamespace(String namespace) {
- this.namespace = namespace;
- }
-
- public ExchangePattern getPattern() {
- return pattern;
- }
-
- public void setPattern(ExchangePattern pattern) {
- this.pattern = pattern;
- }
-
- public String getDiscovery() {
- return discovery;
- }
-
- public void setDiscovery(String discovery) {
- this.discovery = discovery;
- }
-
- public ToServiceConfigurationDefinition getToServiceConfiguration() {
- return toServiceConfiguration;
- }
-
- public void setToServiceConfiguration(ToServiceConfigurationDefinition toServiceConfiguration) {
- this.toServiceConfiguration = toServiceConfiguration;
- }
-
- public String getToServiceConfigurationRef() {
- return toServiceConfigurationRef;
- }
-
- public void setToServiceConfigurationRef(String toServiceConfigurationRef) {
- this.toServiceConfigurationRef = toServiceConfigurationRef;
- }
-
- public String getUri() {
- return uri;
- }
-
- /**
- * The uri of the endpoint to send to.
- * The uri can be dynamic computed using the {@link org.apache.camel.language.simple.SimpleLanguage} expression.
- */
- public void setUri(String uri) {
- this.uri = uri;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/ea4e10e9/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/org/apache/camel/model/jaxb.index b/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
index 549557f..18892e0 100644
--- a/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
+++ b/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
@@ -74,6 +74,8 @@ RoutesDefinition
RoutingSlipDefinition
SamplingDefinition
ScriptDefinition
+ServiceCallDefinition
+ServiceCallConfigurationDefinition
SetBodyDefinition
SetExchangePatternDefinition
SetFaultBodyDefinition
@@ -89,8 +91,6 @@ ThrottleDefinition
ThrowExceptionDefinition
ToDefinition
ToDynamicDefinition
-ToServiceDefinition
-ToServiceConfigurationDefinition
TransactedDefinition
TransformDefinition
TryDefinition
http://git-wip-us.apache.org/repos/asf/camel/blob/ea4e10e9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesProcessorFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesProcessorFactory.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesProcessorFactory.java
index 104ace7..2cc103d 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesProcessorFactory.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesProcessorFactory.java
@@ -23,8 +23,8 @@ import org.apache.camel.ExchangePattern;
import org.apache.camel.Processor;
import org.apache.camel.component.kubernetes.KubernetesConfiguration;
import org.apache.camel.model.ProcessorDefinition;
-import org.apache.camel.model.ToServiceConfigurationDefinition;
-import org.apache.camel.model.ToServiceDefinition;
+import org.apache.camel.model.ServiceCallConfigurationDefinition;
+import org.apache.camel.model.ServiceCallDefinition;
import org.apache.camel.spi.ProcessorFactory;
import org.apache.camel.spi.RouteContext;
import org.apache.camel.util.CamelContextHelper;
@@ -40,8 +40,8 @@ public class KubernetesProcessorFactory implements ProcessorFactory {
@Override
public Processor createProcessor(RouteContext routeContext, ProcessorDefinition<?> definition) throws Exception {
- if (definition instanceof ToServiceDefinition) {
- ToServiceDefinition ts = (ToServiceDefinition) definition;
+ if (definition instanceof ServiceCallDefinition) {
+ ServiceCallDefinition ts = (ServiceCallDefinition) definition;
// discovery must either not be set, or if set then must be us
if (ts.getDiscovery() != null && !"kubernetes".equals(ts.getDiscovery())) {
@@ -53,10 +53,10 @@ public class KubernetesProcessorFactory implements ProcessorFactory {
String uri = ts.getUri();
ExchangePattern mep = ts.getPattern();
- ToServiceConfigurationDefinition config = ts.getToServiceConfiguration();
- ToServiceConfigurationDefinition configRef = null;
- if (ts.getToServiceConfigurationRef() != null) {
- configRef = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), ts.getToServiceConfigurationRef(), ToServiceConfigurationDefinition.class);
+ ServiceCallConfigurationDefinition config = ts.getServiceCallConfiguration();
+ ServiceCallConfigurationDefinition configRef = null;
+ if (ts.getServiceCallConfigurationRef() != null) {
+ configRef = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), ts.getServiceCallConfigurationRef(), ServiceCallConfigurationDefinition.class);
}
// extract the properties from the configuration from the model
http://git-wip-us.apache.org/repos/asf/camel/blob/ea4e10e9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceDiscovery.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceDiscovery.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceDiscovery.java
index 42f7002..ce870c9 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceDiscovery.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceDiscovery.java
@@ -23,7 +23,6 @@ import io.fabric8.kubernetes.api.model.EndpointAddress;
import io.fabric8.kubernetes.api.model.EndpointPort;
import io.fabric8.kubernetes.api.model.EndpointSubset;
import io.fabric8.kubernetes.api.model.Endpoints;
-import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.openshift.client.OpenShiftClient;
import org.apache.camel.support.ServiceSupport;
import org.apache.camel.util.IOHelper;
http://git-wip-us.apache.org/repos/asf/camel/blob/ea4e10e9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceProcessor.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceProcessor.java
index d9bfd5b..a07c047 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceProcessor.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceProcessor.java
@@ -136,6 +136,7 @@ public class KubernetesServiceProcessor extends ServiceSupport implements AsyncP
}
private OpenShiftClient createKubernetesClient() {
+ // TODO: need to use OpenShiftClient until fabric8-client can auto detect OS vs Kube environment
LOG.debug("Create Kubernetes client with the following Configuration: " + configuration.toString());
ConfigBuilder builder = new ConfigBuilder();
http://git-wip-us.apache.org/repos/asf/camel/blob/ea4e10e9/components/camel-kubernetes/src/main/resources/META-INF/services/org/apache/camel/model/ServiceCallDefinition
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/resources/META-INF/services/org/apache/camel/model/ServiceCallDefinition b/components/camel-kubernetes/src/main/resources/META-INF/services/org/apache/camel/model/ServiceCallDefinition
new file mode 100644
index 0000000..acf5be8
--- /dev/null
+++ b/components/camel-kubernetes/src/main/resources/META-INF/services/org/apache/camel/model/ServiceCallDefinition
@@ -0,0 +1,18 @@
+#
+# 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=org.apache.camel.component.kubernetes.processor.KubernetesProcessorFactory
http://git-wip-us.apache.org/repos/asf/camel/blob/ea4e10e9/components/camel-kubernetes/src/main/resources/META-INF/services/org/apache/camel/model/ToServiceDefinition
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/resources/META-INF/services/org/apache/camel/model/ToServiceDefinition b/components/camel-kubernetes/src/main/resources/META-INF/services/org/apache/camel/model/ToServiceDefinition
deleted file mode 100644
index acf5be8..0000000
--- a/components/camel-kubernetes/src/main/resources/META-INF/services/org/apache/camel/model/ToServiceDefinition
+++ /dev/null
@@ -1,18 +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=org.apache.camel.component.kubernetes.processor.KubernetesProcessorFactory
http://git-wip-us.apache.org/repos/asf/camel/blob/ea4e10e9/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/processor/ServiceCallRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/processor/ServiceCallRouteTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/processor/ServiceCallRouteTest.java
new file mode 100644
index 0000000..6595b48
--- /dev/null
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/processor/ServiceCallRouteTest.java
@@ -0,0 +1,54 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.camel.component.kubernetes.processor;
+
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.ServiceCallConfigurationDefinition;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class ServiceCallRouteTest extends CamelTestSupport {
+
+ @Test
+ public void testServiceCall() throws Exception {
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ ServiceCallConfigurationDefinition config = new ServiceCallConfigurationDefinition();
+ config.setMasterUrl("https://fabric8-master.vagrant.f8:8443");
+ config.setUsername("admin");
+ config.setPassword("admin");
+// config.setOauthToken("eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6ImZhYnJpYzgtdG9rZW4tZzNsdGoiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZmFicmljOCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6ImU0NGJhYzA0LWZmYjQtMTFlNS05MWM0LTA4MDAyN2I1YzJmNCIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDpkZWZhdWx0OmZhYnJpYzgifQ.yqhevtuqliAV7RlRhaSjG8oFSOn2V1vfmj5V9JKpaOCWbWXMYS0y_v4QPfI4vIGsJtpZgasrt-8brkiOkq7zx0BJxVm-Ae5QIE1uJNeWFYcno823SUV2ebHykhp0eUEtCmWtHByBIoTTF8dG3NZ6jWow7KVGN289Y2ryi8QoYupfQ9ABddVVcduolStIqBu3pu-dJqIvlt6L8wE6AHfhS4uSaPwcimbs5hrg6gB_iONCSCSayhOyiT6fNlXdpxndRRBg9MP3X3f4dD3kDyHE0860HzqZ05jFIwGfV_rbFJeNY3SLDQNO_QFXqUZKg01OH-OJaqDSjuV48P9b6n4uHA");
+ config.setNamespace("default");
+
+ from("direct:start")
+ .serviceCall("cdi-camel-jetty", "http:cdi-camel-jetty", config)
+ .to("mock:result");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/ea4e10e9/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/processor/ToServiceRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/processor/ToServiceRouteTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/processor/ToServiceRouteTest.java
deleted file mode 100644
index a7d51fc..0000000
--- a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/processor/ToServiceRouteTest.java
+++ /dev/null
@@ -1,54 +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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.camel.component.kubernetes.processor;
-
-import org.apache.camel.RoutesBuilder;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.model.ToServiceConfigurationDefinition;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
-
-public class ToServiceRouteTest extends CamelTestSupport {
-
- @Test
- public void testToService() throws Exception {
- getMockEndpoint("mock:result").expectedMessageCount(1);
-
- template.sendBody("direct:start", "Hello World");
-
- assertMockEndpointsSatisfied();
- }
-
- @Override
- protected RoutesBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- ToServiceConfigurationDefinition config = new ToServiceConfigurationDefinition();
- config.setMasterUrl("https://fabric8-master.vagrant.f8:8443");
- config.setUsername("admin");
- config.setPassword("admin");
-// config.setOauthToken("eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6ImZhYnJpYzgtdG9rZW4tZzNsdGoiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZmFicmljOCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6ImU0NGJhYzA0LWZmYjQtMTFlNS05MWM0LTA4MDAyN2I1YzJmNCIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDpkZWZhdWx0OmZhYnJpYzgifQ.yqhevtuqliAV7RlRhaSjG8oFSOn2V1vfmj5V9JKpaOCWbWXMYS0y_v4QPfI4vIGsJtpZgasrt-8brkiOkq7zx0BJxVm-Ae5QIE1uJNeWFYcno823SUV2ebHykhp0eUEtCmWtHByBIoTTF8dG3NZ6jWow7KVGN289Y2ryi8QoYupfQ9ABddVVcduolStIqBu3pu-dJqIvlt6L8wE6AHfhS4uSaPwcimbs5hrg6gB_iONCSCSayhOyiT6fNlXdpxndRRBg9MP3X3f4dD3kDyHE0860HzqZ05jFIwGfV_rbFJeNY3SLDQNO_QFXqUZKg01OH-OJaqDSjuV48P9b6n4uHA");
- config.setNamespace("default");
-
- from("direct:start")
- .toService("cdi-camel-jetty", "http:cdi-camel-jetty", config)
- .to("mock:result");
- }
- };
- }
-}
[2/4] camel git commit: CAMEL-9683: A new toService EIP that uses a
client discovery to lookup alive services and pick a service ip/port to use
when calling the service from Camel route. Allows to plugin different
providers.
Posted by da...@apache.org.
CAMEL-9683: A new toService EIP that uses a client discovery to lookup alive services and pick a service ip/port to use when calling the service from Camel route. Allows to plugin different providers.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ce5886fe
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ce5886fe
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ce5886fe
Branch: refs/heads/kube-lb
Commit: ce5886fe6773088f735f9b1757c59ba5191c8f7d
Parents: ea4e10e
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 26 10:03:08 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 26 10:03:08 2016 +0200
----------------------------------------------------------------------
.../processor/KubernetesProcessorFactory.java | 7 +-
.../KubernetesServiceCallProcessor.java | 181 ++++++++++++++++++
.../processor/KubernetesServiceDiscovery.java | 3 +
.../processor/KubernetesServiceProcessor.java | 187 -------------------
.../processor/RandomLoadBalancer.java | 31 +++
.../processor/ServiceCallLoadBalancer.java | 25 +++
6 files changed, 244 insertions(+), 190 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ce5886fe/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesProcessorFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesProcessorFactory.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesProcessorFactory.java
index 2cc103d..9596bc5 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesProcessorFactory.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesProcessorFactory.java
@@ -30,6 +30,9 @@ import org.apache.camel.spi.RouteContext;
import org.apache.camel.util.CamelContextHelper;
import org.apache.camel.util.IntrospectionSupport;
+/**
+ * {@link ProcessorFactory} that creates the Kubernetes implementation of the ServiceCall EIP.
+ */
public class KubernetesProcessorFactory implements ProcessorFactory {
@Override
@@ -71,14 +74,12 @@ public class KubernetesProcessorFactory implements ProcessorFactory {
KubernetesConfiguration kc = new KubernetesConfiguration();
IntrospectionSupport.setProperties(kc, parameters);
- // TODO: allow to specify kubernetes/openshift etc
-
// use namespace from config if not provided
if (namespace == null) {
namespace = kc.getNamespace();
}
- return new KubernetesServiceProcessor(name, namespace, uri, mep, kc);
+ return new KubernetesServiceCallProcessor(name, namespace, uri, mep, kc);
} else {
return null;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/ce5886fe/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallProcessor.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallProcessor.java
new file mode 100644
index 0000000..48e4c7c
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallProcessor.java
@@ -0,0 +1,181 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.camel.component.kubernetes.processor;
+
+import java.util.List;
+import java.util.concurrent.RejectedExecutionException;
+
+import io.fabric8.kubernetes.client.Config;
+import io.fabric8.kubernetes.client.ConfigBuilder;
+import io.fabric8.openshift.client.DefaultOpenShiftClient;
+import io.fabric8.openshift.client.OpenShiftClient;
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.AsyncProcessor;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Traceable;
+import org.apache.camel.component.kubernetes.KubernetesConfiguration;
+import org.apache.camel.spi.IdAware;
+import org.apache.camel.support.ServiceSupport;
+import org.apache.camel.util.AsyncProcessorHelper;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ServiceHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Kubernetes based implementation of the the ServiceCall EIP.
+ */
+public class KubernetesServiceCallProcessor extends ServiceSupport implements AsyncProcessor, Traceable, IdAware {
+
+ private static final Logger LOG = LoggerFactory.getLogger(KubernetesServiceCallProcessor.class);
+
+ private String id;
+ private final String name;
+ private final String namespace;
+ private final String uri;
+ private final ExchangePattern exchangePattern;
+ private final KubernetesConfiguration configuration;
+
+ private KubernetesServiceDiscovery discovery;
+ private ServiceCallLoadBalancer loadBalancer = new RandomLoadBalancer();
+
+ // TODO: allow to plugin custom load balancer like ribbon
+
+ public KubernetesServiceCallProcessor(String name, String namespace, String uri, ExchangePattern exchangePattern, KubernetesConfiguration configuration) {
+ this.name = name;
+ this.namespace = namespace;
+ this.uri = uri;
+ this.exchangePattern = exchangePattern;
+ this.configuration = configuration;
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ AsyncProcessorHelper.process(this, exchange);
+ }
+
+ @Override
+ public boolean process(Exchange exchange, AsyncCallback callback) {
+ List<Server> servers = null;
+ try {
+ servers = discovery.getUpdatedListOfServers();
+ if (servers == null || servers.isEmpty()) {
+ exchange.setException(new RejectedExecutionException("No active services with name " + name + " in namespace " + namespace));
+ }
+ } catch (Throwable e) {
+ exchange.setException(e);
+ }
+
+ if (exchange.getException() != null) {
+ callback.done(true);
+ return true;
+ }
+
+ // let the client load balancer chose which server to use
+ Server server = loadBalancer.choseServer(servers);
+ String ip = server.getIp();
+ int port = server.getPort();
+ LOG.debug("Random selected service {} active at server: {}:{}", name, ip, port);
+
+ // build uri based on the name
+
+ // TODO build uri
+ callback.done(true);
+ return true;
+ }
+
+ @Override
+ public String getId() {
+ return id;
+ }
+
+ @Override
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ @Override
+ public String getTraceLabel() {
+ return "kubernetes";
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ ObjectHelper.notEmpty(name, "name", this);
+ ObjectHelper.notEmpty(namespace, "namespace", this);
+ ObjectHelper.notEmpty(configuration.getMasterUrl(), "masterUrl", this);
+
+ discovery = new KubernetesServiceDiscovery(name, namespace, null, createKubernetesClient());
+ ServiceHelper.startService(discovery);
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ ServiceHelper.stopService(discovery);
+ }
+
+ private OpenShiftClient createKubernetesClient() {
+ // TODO: need to use OpenShiftClient until fabric8-client can auto detect OS vs Kube environment
+ LOG.debug("Create Kubernetes client with the following Configuration: " + configuration.toString());
+
+ ConfigBuilder builder = new ConfigBuilder();
+ builder.withMasterUrl(configuration.getMasterUrl());
+ if ((ObjectHelper.isNotEmpty(configuration.getUsername())
+ && ObjectHelper.isNotEmpty(configuration.getPassword()))
+ && ObjectHelper.isEmpty(configuration.getOauthToken())) {
+ builder.withUsername(configuration.getUsername());
+ builder.withPassword(configuration.getPassword());
+ } else {
+ builder.withOauthToken(configuration.getOauthToken());
+ }
+ if (ObjectHelper.isNotEmpty(configuration.getCaCertData())) {
+ builder.withCaCertData(configuration.getCaCertData());
+ }
+ if (ObjectHelper.isNotEmpty(configuration.getCaCertFile())) {
+ builder.withCaCertFile(configuration.getCaCertFile());
+ }
+ if (ObjectHelper.isNotEmpty(configuration.getClientCertData())) {
+ builder.withClientCertData(configuration.getClientCertData());
+ }
+ if (ObjectHelper.isNotEmpty(configuration.getClientCertFile())) {
+ builder.withClientCertFile(configuration.getClientCertFile());
+ }
+ if (ObjectHelper.isNotEmpty(configuration.getApiVersion())) {
+ builder.withApiVersion(configuration.getApiVersion());
+ }
+ if (ObjectHelper.isNotEmpty(configuration.getClientKeyAlgo())) {
+ builder.withClientKeyAlgo(configuration.getClientKeyAlgo());
+ }
+ if (ObjectHelper.isNotEmpty(configuration.getClientKeyData())) {
+ builder.withClientKeyData(configuration.getClientKeyData());
+ }
+ if (ObjectHelper.isNotEmpty(configuration.getClientKeyFile())) {
+ builder.withClientKeyFile(configuration.getClientKeyFile());
+ }
+ if (ObjectHelper.isNotEmpty(configuration.getClientKeyPassphrase())) {
+ builder.withClientKeyPassphrase(configuration.getClientKeyPassphrase());
+ }
+ if (ObjectHelper.isNotEmpty(configuration.getTrustCerts())) {
+ builder.withTrustCerts(configuration.getTrustCerts());
+ }
+
+ Config conf = builder.build();
+ return new DefaultOpenShiftClient(conf);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/ce5886fe/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceDiscovery.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceDiscovery.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceDiscovery.java
index ce870c9..81e1fca 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceDiscovery.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceDiscovery.java
@@ -30,6 +30,9 @@ import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ * Discovers services in Kubernetes.
+ */
public class KubernetesServiceDiscovery extends ServiceSupport {
private static final Logger LOG = LoggerFactory.getLogger(KubernetesServiceDiscovery.class);
http://git-wip-us.apache.org/repos/asf/camel/blob/ce5886fe/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceProcessor.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceProcessor.java
deleted file mode 100644
index a07c047..0000000
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceProcessor.java
+++ /dev/null
@@ -1,187 +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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.camel.component.kubernetes.processor;
-
-import java.util.List;
-import java.util.Random;
-import java.util.concurrent.RejectedExecutionException;
-
-import io.fabric8.kubernetes.client.Config;
-import io.fabric8.kubernetes.client.ConfigBuilder;
-import io.fabric8.openshift.client.DefaultOpenShiftClient;
-import io.fabric8.openshift.client.OpenShiftClient;
-import org.apache.camel.AsyncCallback;
-import org.apache.camel.AsyncProcessor;
-import org.apache.camel.Exchange;
-import org.apache.camel.ExchangePattern;
-import org.apache.camel.Traceable;
-import org.apache.camel.component.kubernetes.KubernetesConfiguration;
-import org.apache.camel.spi.IdAware;
-import org.apache.camel.support.ServiceSupport;
-import org.apache.camel.util.AsyncProcessorHelper;
-import org.apache.camel.util.ObjectHelper;
-import org.apache.camel.util.ServiceHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class KubernetesServiceProcessor extends ServiceSupport implements AsyncProcessor, Traceable, IdAware {
-
- private static final Logger LOG = LoggerFactory.getLogger(KubernetesServiceProcessor.class);
-
- private String id;
- private final String name;
- private final String namespace;
- private final String uri;
- private final ExchangePattern exchangePattern;
- private final KubernetesConfiguration configuration;
-
- private KubernetesServiceDiscovery discovery;
-
- // TODO: allow to plugin custom load balancer like ribbon
-
- public KubernetesServiceProcessor(String name, String namespace, String uri, ExchangePattern exchangePattern, KubernetesConfiguration configuration) {
- this.name = name;
- this.namespace = namespace;
- this.uri = uri;
- this.exchangePattern = exchangePattern;
- this.configuration = configuration;
- }
-
- @Override
- public void process(Exchange exchange) throws Exception {
- AsyncProcessorHelper.process(this, exchange);
- }
-
- @Override
- public boolean process(Exchange exchange, AsyncCallback callback) {
- // TODO: in try .. catch and the callback stuff
-
- List<Server> services = null;
- try {
- services = discovery.getUpdatedListOfServers();
- if (services == null || services.isEmpty()) {
- exchange.setException(new RejectedExecutionException("No active services with name " + name + " in namespace " + namespace));
- }
- } catch (Throwable e) {
- exchange.setException(e);
- }
-
- if (exchange.getException() != null) {
- callback.done(true);
- return true;
- }
-
- // what strategy to use? random
- int size = services.size();
- int ran = new Random().nextInt(size);
- Server server = services.get(ran);
-
- String ip = server.getIp();
- int port = server.getPort();
-
- LOG.debug("Random selected service {} active at: {}:{}", name, ip, port);
-
- // build uri based on the name
-
-
- // TODO: lookup service
- // TODO: apply LB strategy
- // TODO build uri
- callback.done(true);
- return true;
- }
-
- @Override
- public String getId() {
- return id;
- }
-
- @Override
- public void setId(String id) {
- this.id = id;
- }
-
- @Override
- public String getTraceLabel() {
- return "kubernetes";
- }
-
- @Override
- protected void doStart() throws Exception {
- ObjectHelper.notEmpty(name, "name", this);
- ObjectHelper.notEmpty(namespace, "namespace", this);
- ObjectHelper.notEmpty(configuration.getMasterUrl(), "masterUrl", this);
-
- discovery = new KubernetesServiceDiscovery(name, namespace, null, createKubernetesClient());
- ServiceHelper.startService(discovery);
- }
-
- @Override
- protected void doStop() throws Exception {
- ServiceHelper.stopService(discovery);
- }
-
- private OpenShiftClient createKubernetesClient() {
- // TODO: need to use OpenShiftClient until fabric8-client can auto detect OS vs Kube environment
- LOG.debug("Create Kubernetes client with the following Configuration: " + configuration.toString());
-
- ConfigBuilder builder = new ConfigBuilder();
- builder.withMasterUrl(configuration.getMasterUrl());
- if ((ObjectHelper.isNotEmpty(configuration.getUsername())
- && ObjectHelper.isNotEmpty(configuration.getPassword()))
- && ObjectHelper.isEmpty(configuration.getOauthToken())) {
- builder.withUsername(configuration.getUsername());
- builder.withPassword(configuration.getPassword());
- } else {
- builder.withOauthToken(configuration.getOauthToken());
- }
- if (ObjectHelper.isNotEmpty(configuration.getCaCertData())) {
- builder.withCaCertData(configuration.getCaCertData());
- }
- if (ObjectHelper.isNotEmpty(configuration.getCaCertFile())) {
- builder.withCaCertFile(configuration.getCaCertFile());
- }
- if (ObjectHelper.isNotEmpty(configuration.getClientCertData())) {
- builder.withClientCertData(configuration.getClientCertData());
- }
- if (ObjectHelper.isNotEmpty(configuration.getClientCertFile())) {
- builder.withClientCertFile(configuration.getClientCertFile());
- }
- if (ObjectHelper.isNotEmpty(configuration.getApiVersion())) {
- builder.withApiVersion(configuration.getApiVersion());
- }
- if (ObjectHelper.isNotEmpty(configuration.getClientKeyAlgo())) {
- builder.withClientKeyAlgo(configuration.getClientKeyAlgo());
- }
- if (ObjectHelper.isNotEmpty(configuration.getClientKeyData())) {
- builder.withClientKeyData(configuration.getClientKeyData());
- }
- if (ObjectHelper.isNotEmpty(configuration.getClientKeyFile())) {
- builder.withClientKeyFile(configuration.getClientKeyFile());
- }
- if (ObjectHelper.isNotEmpty(configuration.getClientKeyPassphrase())) {
- builder.withClientKeyPassphrase(configuration.getClientKeyPassphrase());
- }
- if (ObjectHelper.isNotEmpty(configuration.getTrustCerts())) {
- builder.withTrustCerts(configuration.getTrustCerts());
- }
-
- Config conf = builder.build();
- return new DefaultOpenShiftClient(conf);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/ce5886fe/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/RandomLoadBalancer.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/RandomLoadBalancer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/RandomLoadBalancer.java
new file mode 100644
index 0000000..aa35384
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/RandomLoadBalancer.java
@@ -0,0 +1,31 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.camel.component.kubernetes.processor;
+
+import java.util.List;
+import java.util.Random;
+
+public class RandomLoadBalancer implements ServiceCallLoadBalancer {
+
+ @Override
+ public Server choseServer(List<Server> services) {
+ int size = services.size();
+ int ran = new Random().nextInt(size);
+ Server server = services.get(ran);
+ return server;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/ce5886fe/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallLoadBalancer.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallLoadBalancer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallLoadBalancer.java
new file mode 100644
index 0000000..28b5e66
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallLoadBalancer.java
@@ -0,0 +1,25 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.camel.component.kubernetes.processor;
+
+import java.util.List;
+
+public interface ServiceCallLoadBalancer {
+
+ Server choseServer(List<Server> services);
+
+}
[4/4] camel git commit: CAMEL-9683: A new toService EIP that uses a
client discovery to lookup alive services and pick a service ip/port to use
when calling the service from Camel route. Allows to plugin different
providers.
Posted by da...@apache.org.
CAMEL-9683: A new toService EIP that uses a client discovery to lookup alive services and pick a service ip/port to use when calling the service from Camel route. Allows to plugin different providers.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3b0b4d03
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3b0b4d03
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3b0b4d03
Branch: refs/heads/kube-lb
Commit: 3b0b4d0366b3ccc3a3e825da17c7bca0317bf186
Parents: 36de036
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 26 10:56:06 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 26 10:56:06 2016 +0200
----------------------------------------------------------------------
.../kubernetes/processor/KubernetesProcessorFactory.java | 6 +++---
.../processor/KubernetesServiceCallProcessor.java | 6 +++---
.../kubernetes/processor/KubernetesServiceDiscovery.java | 9 ++++-----
.../component/kubernetes/processor/RandomLoadBalancer.java | 6 +++---
.../apache/camel/component/kubernetes/processor/Server.java | 6 +++---
.../kubernetes/processor/ServiceCallExpression.java | 6 +++---
.../kubernetes/processor/ServiceCallLoadBalancer.java | 6 +++---
.../kubernetes/processor/ServiceCallRouteTest.java | 8 +++++---
8 files changed, 27 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/3b0b4d03/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesProcessorFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesProcessorFactory.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesProcessorFactory.java
index 9596bc5..13f77e2 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesProcessorFactory.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesProcessorFactory.java
@@ -5,9 +5,9 @@
* 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ * 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.
http://git-wip-us.apache.org/repos/asf/camel/blob/3b0b4d03/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallProcessor.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallProcessor.java
index 1583180..8bdfe09 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallProcessor.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallProcessor.java
@@ -5,9 +5,9 @@
* 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ * 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.
http://git-wip-us.apache.org/repos/asf/camel/blob/3b0b4d03/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceDiscovery.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceDiscovery.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceDiscovery.java
index 81e1fca..ff44e44 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceDiscovery.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceDiscovery.java
@@ -5,9 +5,9 @@
* 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ * 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.
@@ -56,8 +56,7 @@ public class KubernetesServiceDiscovery extends ServiceSupport {
List<Server> result = new ArrayList<Server>();
if (endpoints != null) {
if (LOG.isDebugEnabled()) {
- LOG.debug("Found [" + endpoints.getSubsets().size() + "] endpoints in namespace [" +
- namespace + "] for name [" + name + "] and portName [" + portName + "]");
+ LOG.debug("Found {} endpoints in namespace: {} for name: {} and portName: {}", endpoints.getSubsets().size(), namespace, name, portName);
}
for (EndpointSubset subset : endpoints.getSubsets()) {
if (subset.getPorts().size() == 1) {
http://git-wip-us.apache.org/repos/asf/camel/blob/3b0b4d03/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/RandomLoadBalancer.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/RandomLoadBalancer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/RandomLoadBalancer.java
index aa35384..86a9b6c 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/RandomLoadBalancer.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/RandomLoadBalancer.java
@@ -5,9 +5,9 @@
* 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ * 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.
http://git-wip-us.apache.org/repos/asf/camel/blob/3b0b4d03/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/Server.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/Server.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/Server.java
index 021fc86..d0a4471 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/Server.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/Server.java
@@ -5,9 +5,9 @@
* 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ * 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.
http://git-wip-us.apache.org/repos/asf/camel/blob/3b0b4d03/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallExpression.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallExpression.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallExpression.java
index 2cb1bf1..1c2a43a 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallExpression.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallExpression.java
@@ -5,9 +5,9 @@
* 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ * 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.
http://git-wip-us.apache.org/repos/asf/camel/blob/3b0b4d03/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallLoadBalancer.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallLoadBalancer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallLoadBalancer.java
index 28b5e66..f2dc7ad 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallLoadBalancer.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallLoadBalancer.java
@@ -5,9 +5,9 @@
* 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ * 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.
http://git-wip-us.apache.org/repos/asf/camel/blob/3b0b4d03/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/processor/ServiceCallRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/processor/ServiceCallRouteTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/processor/ServiceCallRouteTest.java
index 6164d0c..b6b675a 100644
--- a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/processor/ServiceCallRouteTest.java
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/processor/ServiceCallRouteTest.java
@@ -5,9 +5,9 @@
* 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ * 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.
@@ -20,8 +20,10 @@ import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.ServiceCallConfigurationDefinition;
import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Ignore;
import org.junit.Test;
+@Ignore("Manual test")
public class ServiceCallRouteTest extends CamelTestSupport {
@Test
[3/4] camel git commit: CAMEL-9683: A new toService EIP that uses a
client discovery to lookup alive services and pick a service ip/port to use
when calling the service from Camel route. Allows to plugin different
providers.
Posted by da...@apache.org.
CAMEL-9683: A new toService EIP that uses a client discovery to lookup alive services and pick a service ip/port to use when calling the service from Camel route. Allows to plugin different providers.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/36de036c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/36de036c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/36de036c
Branch: refs/heads/kube-lb
Commit: 36de036c5f729d81b40668de515e4c3c6cefc5dd
Parents: ce5886f
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Apr 26 10:45:46 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Apr 26 10:45:46 2016 +0200
----------------------------------------------------------------------
components/camel-kubernetes/pom.xml | 5 ++
.../kubernetes/KubernetesConstants.java | 5 ++
.../KubernetesServiceCallProcessor.java | 63 ++++++++++++--
.../processor/ServiceCallExpression.java | 92 ++++++++++++++++++++
.../processor/ServiceCallRouteTest.java | 3 +-
5 files changed, 157 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/36de036c/components/camel-kubernetes/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/pom.xml b/components/camel-kubernetes/pom.xml
index 1d39ba4..699f9cd 100644
--- a/components/camel-kubernetes/pom.xml
+++ b/components/camel-kubernetes/pom.xml
@@ -50,6 +50,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-http</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons-codec-version}</version>
http://git-wip-us.apache.org/repos/asf/camel/blob/36de036c/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesConstants.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesConstants.java
index 6613f19..e92c7ce 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesConstants.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/KubernetesConstants.java
@@ -17,6 +17,11 @@
package org.apache.camel.component.kubernetes;
public interface KubernetesConstants {
+
+ // Service Call EIP
+ String KUBERNETES_SERVER_IP = "CamelKubernetesServerIp";
+ String KUBERNETES_SERVER_PORT = "CamelKubernetesServerPort";
+
// Producer
String KUBERNETES_OPERATION = "CamelKubernetesOperation";
String KUBERNETES_NAMESPACE_NAME = "CamelKubernetesNamespaceName";
http://git-wip-us.apache.org/repos/asf/camel/blob/36de036c/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallProcessor.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallProcessor.java
index 48e4c7c..1583180 100644
--- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallProcessor.java
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/KubernetesServiceCallProcessor.java
@@ -25,10 +25,14 @@ import io.fabric8.openshift.client.DefaultOpenShiftClient;
import io.fabric8.openshift.client.OpenShiftClient;
import org.apache.camel.AsyncCallback;
import org.apache.camel.AsyncProcessor;
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.Traceable;
import org.apache.camel.component.kubernetes.KubernetesConfiguration;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.processor.SendDynamicProcessor;
import org.apache.camel.spi.IdAware;
import org.apache.camel.support.ServiceSupport;
import org.apache.camel.util.AsyncProcessorHelper;
@@ -40,28 +44,53 @@ import org.slf4j.LoggerFactory;
/**
* Kubernetes based implementation of the the ServiceCall EIP.
*/
-public class KubernetesServiceCallProcessor extends ServiceSupport implements AsyncProcessor, Traceable, IdAware {
+public class KubernetesServiceCallProcessor extends ServiceSupport implements AsyncProcessor, CamelContextAware, Traceable, IdAware {
private static final Logger LOG = LoggerFactory.getLogger(KubernetesServiceCallProcessor.class);
+ private CamelContext camelContext;
private String id;
private final String name;
+ private final String scheme;
+ private final String contextPath;
private final String namespace;
private final String uri;
private final ExchangePattern exchangePattern;
private final KubernetesConfiguration configuration;
-
private KubernetesServiceDiscovery discovery;
+
private ServiceCallLoadBalancer loadBalancer = new RandomLoadBalancer();
+ private final ServiceCallExpression serviceCallExpression;
+ private SendDynamicProcessor processor;
// TODO: allow to plugin custom load balancer like ribbon
public KubernetesServiceCallProcessor(String name, String namespace, String uri, ExchangePattern exchangePattern, KubernetesConfiguration configuration) {
- this.name = name;
+ // setup from the provided name which can contain scheme and context-path information as well
+ String serviceName;
+ if (name.contains("/")) {
+ serviceName = ObjectHelper.before(name, "/");
+ this.contextPath = ObjectHelper.after(name, "/");
+ } else if (name.contains("?")) {
+ serviceName = ObjectHelper.before(name, "?");
+ this.contextPath = ObjectHelper.after(name, "?");
+ } else {
+ serviceName = name;
+ this.contextPath = null;
+ }
+ if (serviceName.contains(":")) {
+ this.scheme = ObjectHelper.before(serviceName, ":");
+ this.name = ObjectHelper.after(serviceName, ":");
+ } else {
+ this.scheme = null;
+ this.name = serviceName;
+ }
+
this.namespace = namespace;
this.uri = uri;
this.exchangePattern = exchangePattern;
this.configuration = configuration;
+ this.serviceCallExpression = new ServiceCallExpression(this.name, this.scheme, this.contextPath, this.uri);
}
@Override
@@ -92,11 +121,22 @@ public class KubernetesServiceCallProcessor extends ServiceSupport implements As
int port = server.getPort();
LOG.debug("Random selected service {} active at server: {}:{}", name, ip, port);
- // build uri based on the name
+ // set selected server as header
+ exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_SERVER_IP, ip);
+ exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_SERVER_PORT, port);
- // TODO build uri
- callback.done(true);
- return true;
+ // use the dynamic send processor to call the service
+ return processor.process(exchange, callback);
+ }
+
+ @Override
+ public CamelContext getCamelContext() {
+ return camelContext;
+ }
+
+ @Override
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
}
@Override
@@ -121,12 +161,17 @@ public class KubernetesServiceCallProcessor extends ServiceSupport implements As
ObjectHelper.notEmpty(configuration.getMasterUrl(), "masterUrl", this);
discovery = new KubernetesServiceDiscovery(name, namespace, null, createKubernetesClient());
- ServiceHelper.startService(discovery);
+ processor = new SendDynamicProcessor(uri, serviceCallExpression);
+ processor.setCamelContext(getCamelContext());
+ if (exchangePattern != null) {
+ processor.setPattern(exchangePattern);
+ }
+ ServiceHelper.startServices(discovery, processor);
}
@Override
protected void doStop() throws Exception {
- ServiceHelper.stopService(discovery);
+ ServiceHelper.stopServices(processor, discovery);
}
private OpenShiftClient createKubernetesClient() {
http://git-wip-us.apache.org/repos/asf/camel/blob/36de036c/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallExpression.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallExpression.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallExpression.java
new file mode 100644
index 0000000..2cb1bf1
--- /dev/null
+++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/processor/ServiceCallExpression.java
@@ -0,0 +1,92 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.camel.component.kubernetes.processor;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.kubernetes.KubernetesConstants;
+import org.apache.camel.support.ExpressionAdapter;
+import org.apache.camel.util.ExchangeHelper;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ServiceCallExpression extends ExpressionAdapter {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ServiceCallExpression.class);
+
+ private final String name;
+ private final String scheme;
+ private final String contextPath;
+ private final String uri;
+
+ public ServiceCallExpression(String name, String scheme, String contextPath, String uri) {
+ this.name = name;
+ this.scheme = scheme;
+ this.contextPath = contextPath;
+ this.uri = uri;
+ }
+
+ @Override
+ public Object evaluate(Exchange exchange) {
+ try {
+ String ip = ExchangeHelper.getMandatoryHeader(exchange, KubernetesConstants.KUBERNETES_SERVER_IP, String.class);
+ int port = ExchangeHelper.getMandatoryHeader(exchange, KubernetesConstants.KUBERNETES_SERVER_PORT, int.class);
+ return buildCamelEndpointUri(ip, port, name, uri, contextPath, scheme);
+ } catch (Exception e) {
+ throw ObjectHelper.wrapRuntimeCamelException(e);
+ }
+ }
+
+ protected static String buildCamelEndpointUri(String ip, int port, String name, String uri, String contextPath, String scheme) {
+ // serviceCall("myService") (will use http by default)
+ // serviceCall("myService/foo") (will use http by default)
+ // serviceCall("http:myService/foo")
+ // serviceCall("myService", "http:myService.host:myService.port/foo")
+ // serviceCall("myService", "netty4:tcp:myService?connectTimeout=1000")
+
+ // build basic uri if none provided
+ String answer = uri;
+ if (answer == null) {
+ if (scheme == null) {
+ if (port == 443) {
+ scheme = "https";
+ } else {
+ scheme = "http";
+ }
+ }
+ answer = scheme + "://" + ip + ":" + port;
+ if (contextPath != null) {
+ answer += "" + contextPath;
+ }
+ } else {
+ // we have existing uri, then replace the serviceName with ip:port
+ if (answer.contains(name + ".host")) {
+ answer = answer.replaceFirst(name + "\\.host", ip);
+ }
+ if (answer.contains(name + ".port")) {
+ answer = answer.replaceFirst(name + "\\.port", "" + port);
+ }
+ if (answer.contains(name)) {
+ answer = answer.replaceFirst(name, ip + ":" + port);
+ }
+ }
+
+ LOG.debug("Camel endpoint uri: {} for calling service: {} + on server {}:{}", answer, name, ip, port);
+ return answer;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/36de036c/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/processor/ServiceCallRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/processor/ServiceCallRouteTest.java b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/processor/ServiceCallRouteTest.java
index 6595b48..6164d0c 100644
--- a/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/processor/ServiceCallRouteTest.java
+++ b/components/camel-kubernetes/src/test/java/org/apache/camel/component/kubernetes/processor/ServiceCallRouteTest.java
@@ -42,11 +42,10 @@ public class ServiceCallRouteTest extends CamelTestSupport {
config.setMasterUrl("https://fabric8-master.vagrant.f8:8443");
config.setUsername("admin");
config.setPassword("admin");
-// config.setOauthToken("eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6ImZhYnJpYzgtdG9rZW4tZzNsdGoiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZmFicmljOCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6ImU0NGJhYzA0LWZmYjQtMTFlNS05MWM0LTA4MDAyN2I1YzJmNCIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDpkZWZhdWx0OmZhYnJpYzgifQ.yqhevtuqliAV7RlRhaSjG8oFSOn2V1vfmj5V9JKpaOCWbWXMYS0y_v4QPfI4vIGsJtpZgasrt-8brkiOkq7zx0BJxVm-Ae5QIE1uJNeWFYcno823SUV2ebHykhp0eUEtCmWtHByBIoTTF8dG3NZ6jWow7KVGN289Y2ryi8QoYupfQ9ABddVVcduolStIqBu3pu-dJqIvlt6L8wE6AHfhS4uSaPwcimbs5hrg6gB_iONCSCSayhOyiT6fNlXdpxndRRBg9MP3X3f4dD3kDyHE0860HzqZ05jFIwGfV_rbFJeNY3SLDQNO_QFXqUZKg01OH-OJaqDSjuV48P9b6n4uHA");
config.setNamespace("default");
from("direct:start")
- .serviceCall("cdi-camel-jetty", "http:cdi-camel-jetty", config)
+ .serviceCall("cdi-camel-jetty", null, config)
.to("mock:result");
}
};