http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesSecretsProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesSecretsProducer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesSecretsProducer.java deleted file mode 100644 index c5c5281..0000000 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesSecretsProducer.java +++ /dev/null @@ -1,198 +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.component.kubernetes.producer; - -import java.util.Map; - -import io.fabric8.kubernetes.api.model.DoneableSecret; -import io.fabric8.kubernetes.api.model.Secret; -import io.fabric8.kubernetes.api.model.SecretList; -import io.fabric8.kubernetes.client.dsl.MixedOperation; -import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; -import io.fabric8.kubernetes.client.dsl.Resource; - -import org.apache.camel.Exchange; -import org.apache.camel.component.kubernetes.KubernetesConstants; -import org.apache.camel.component.kubernetes.KubernetesEndpoint; -import org.apache.camel.impl.DefaultProducer; -import org.apache.camel.util.MessageHelper; -import org.apache.camel.util.ObjectHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class KubernetesSecretsProducer extends DefaultProducer { - - private static final Logger LOG = LoggerFactory - .getLogger(KubernetesSecretsProducer.class); - - public KubernetesSecretsProducer(KubernetesEndpoint endpoint) { - super(endpoint); - } - - @Override - public KubernetesEndpoint getEndpoint() { - return (KubernetesEndpoint) super.getEndpoint(); - } - - @Override - public void process(Exchange exchange) throws Exception { - String operation; - - if (ObjectHelper.isEmpty(getEndpoint().getKubernetesConfiguration() - .getOperation())) { - operation = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_OPERATION, String.class); - } else { - operation = getEndpoint().getKubernetesConfiguration() - .getOperation(); - } - - switch (operation) { - - case KubernetesOperations.LIST_SECRETS: - doList(exchange, operation); - break; - - case KubernetesOperations.LIST_SECRETS_BY_LABELS_OPERATION: - doListSecretsByLabels(exchange, operation); - break; - - case KubernetesOperations.GET_SECRET_OPERATION: - doGetSecret(exchange, operation); - break; - - case KubernetesOperations.CREATE_SECRET_OPERATION: - doCreateSecret(exchange, operation); - break; - - case KubernetesOperations.DELETE_SECRET_OPERATION: - doDeleteSecret(exchange, operation); - break; - - default: - throw new IllegalArgumentException("Unsupported operation " - + operation); - } - } - - protected void doList(Exchange exchange, String operation) throws Exception { - SecretList secretsList = getEndpoint().getKubernetesClient().secrets() - .list(); - exchange.getOut().setBody(secretsList.getItems()); - } - - protected void doListSecretsByLabels(Exchange exchange, String operation) - throws Exception { - SecretList secretsList = null; - Map<String, String> labels = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_SECRETS_LABELS, Map.class); - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - if (!ObjectHelper.isEmpty(namespaceName)) { - NonNamespaceOperation<Secret, SecretList, DoneableSecret, Resource<Secret, DoneableSecret>> secrets; - secrets = getEndpoint().getKubernetesClient().secrets() - .inNamespace(namespaceName); - for (Map.Entry<String, String> entry : labels.entrySet()) { - secrets.withLabel(entry.getKey(), entry.getValue()); - } - secretsList = secrets.list(); - } else { - MixedOperation<Secret, SecretList, DoneableSecret, Resource<Secret, DoneableSecret>> secrets; - secrets = getEndpoint().getKubernetesClient().secrets(); - for (Map.Entry<String, String> entry : labels.entrySet()) { - secrets.withLabel(entry.getKey(), entry.getValue()); - } - secretsList = secrets.list(); - } - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(secretsList.getItems()); - } - - protected void doGetSecret(Exchange exchange, String operation) - throws Exception { - Secret secret = null; - String secretName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_SECRET_NAME, String.class); - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - if (ObjectHelper.isEmpty(secretName)) { - LOG.error("Get a specific Secret require specify a Secret name"); - throw new IllegalArgumentException( - "Get a specific Secret require specify a Secret name"); - } - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Get a specific Secret require specify a namespace name"); - throw new IllegalArgumentException( - "Get a specific Secret require specify a namespace name"); - } - secret = getEndpoint().getKubernetesClient().secrets() - .inNamespace(namespaceName).withName(secretName).get(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(secret); - } - - protected void doCreateSecret(Exchange exchange, String operation) - throws Exception { - Secret secret = null; - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - Secret secretToCreate = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_SECRET, Secret.class); - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Create a specific secret require specify a namespace name"); - throw new IllegalArgumentException( - "Create a specific secret require specify a namespace name"); - } - if (ObjectHelper.isEmpty(secretToCreate)) { - LOG.error("Create a specific secret require specify a secret bean"); - throw new IllegalArgumentException( - "Create a specific secret require specify a secret bean"); - } - Map<String, String> labels = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_SECRETS_LABELS, Map.class); - secret = getEndpoint().getKubernetesClient().secrets() - .inNamespace(namespaceName).create(secretToCreate); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(secret); - } - - protected void doDeleteSecret(Exchange exchange, String operation) - throws Exception { - String secretName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_SECRET_NAME, String.class); - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - if (ObjectHelper.isEmpty(secretName)) { - LOG.error("Delete a specific secret require specify a secret name"); - throw new IllegalArgumentException( - "Delete a specific secret require specify a secret name"); - } - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Delete a specific secret require specify a namespace name"); - throw new IllegalArgumentException( - "Delete a specific secret require specify a namespace name"); - } - boolean secretDeleted = getEndpoint().getKubernetesClient().secrets() - .inNamespace(namespaceName).withName(secretName).delete(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(secretDeleted); - } -}
http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesServiceAccountsProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesServiceAccountsProducer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesServiceAccountsProducer.java deleted file mode 100644 index e4f07c1..0000000 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesServiceAccountsProducer.java +++ /dev/null @@ -1,198 +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.component.kubernetes.producer; - -import java.util.Map; - -import io.fabric8.kubernetes.api.model.DoneableServiceAccount; -import io.fabric8.kubernetes.api.model.ServiceAccount; -import io.fabric8.kubernetes.api.model.ServiceAccountList; -import io.fabric8.kubernetes.client.dsl.MixedOperation; -import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; -import io.fabric8.kubernetes.client.dsl.Resource; - -import org.apache.camel.Exchange; -import org.apache.camel.component.kubernetes.KubernetesConstants; -import org.apache.camel.component.kubernetes.KubernetesEndpoint; -import org.apache.camel.impl.DefaultProducer; -import org.apache.camel.util.MessageHelper; -import org.apache.camel.util.ObjectHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class KubernetesServiceAccountsProducer extends DefaultProducer { - - private static final Logger LOG = LoggerFactory - .getLogger(KubernetesServiceAccountsProducer.class); - - public KubernetesServiceAccountsProducer(KubernetesEndpoint endpoint) { - super(endpoint); - } - - @Override - public KubernetesEndpoint getEndpoint() { - return (KubernetesEndpoint) super.getEndpoint(); - } - - @Override - public void process(Exchange exchange) throws Exception { - String operation; - - if (ObjectHelper.isEmpty(getEndpoint().getKubernetesConfiguration() - .getOperation())) { - operation = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_OPERATION, String.class); - } else { - operation = getEndpoint().getKubernetesConfiguration() - .getOperation(); - } - - switch (operation) { - - case KubernetesOperations.LIST_SERVICE_ACCOUNTS: - doList(exchange, operation); - break; - - case KubernetesOperations.LIST_SERVICE_ACCOUNTS_BY_LABELS_OPERATION: - doListServiceAccountsByLabels(exchange, operation); - break; - - case KubernetesOperations.GET_SECRET_OPERATION: - doGetServiceAccount(exchange, operation); - break; - - case KubernetesOperations.CREATE_SERVICE_ACCOUNT_OPERATION: - doCreateServiceAccount(exchange, operation); - break; - - case KubernetesOperations.DELETE_SERVICE_ACCOUNT_OPERATION: - doDeleteServiceAccount(exchange, operation); - break; - - default: - throw new IllegalArgumentException("Unsupported operation " - + operation); - } - } - - protected void doList(Exchange exchange, String operation) throws Exception { - ServiceAccountList saList = getEndpoint().getKubernetesClient().serviceAccounts() - .list(); - exchange.getOut().setBody(saList.getItems()); - } - - protected void doListServiceAccountsByLabels(Exchange exchange, String operation) - throws Exception { - ServiceAccountList saList = null; - Map<String, String> labels = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_SERVICE_ACCOUNTS_LABELS, Map.class); - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - if (!ObjectHelper.isEmpty(namespaceName)) { - NonNamespaceOperation<ServiceAccount, ServiceAccountList, DoneableServiceAccount, Resource<ServiceAccount, DoneableServiceAccount>> serviceAccounts; - serviceAccounts = getEndpoint().getKubernetesClient().serviceAccounts() - .inNamespace(namespaceName); - for (Map.Entry<String, String> entry : labels.entrySet()) { - serviceAccounts.withLabel(entry.getKey(), entry.getValue()); - } - saList = serviceAccounts.list(); - } else { - MixedOperation<ServiceAccount, ServiceAccountList, DoneableServiceAccount, Resource<ServiceAccount, DoneableServiceAccount>> serviceAccounts; - serviceAccounts = getEndpoint().getKubernetesClient().serviceAccounts(); - for (Map.Entry<String, String> entry : labels.entrySet()) { - serviceAccounts.withLabel(entry.getKey(), entry.getValue()); - } - saList = serviceAccounts.list(); - } - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(saList.getItems()); - } - - protected void doGetServiceAccount(Exchange exchange, String operation) - throws Exception { - ServiceAccount sa = null; - String saName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_SERVICE_ACCOUNT_NAME, String.class); - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - if (ObjectHelper.isEmpty(saName)) { - LOG.error("Get a specific Service Account require specify a Service Account name"); - throw new IllegalArgumentException( - "Get a specific Service Account require specify a Service Account name"); - } - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Get a specific Service Account require specify a namespace name"); - throw new IllegalArgumentException( - "Get a specific Service Account require specify a namespace name"); - } - sa = getEndpoint().getKubernetesClient().serviceAccounts() - .inNamespace(namespaceName).withName(saName).get(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(sa); - } - - protected void doCreateServiceAccount(Exchange exchange, String operation) - throws Exception { - ServiceAccount sa = null; - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - ServiceAccount saToCreate = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_SERVICE_ACCOUNT, ServiceAccount.class); - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Create a specific Service Account require specify a namespace name"); - throw new IllegalArgumentException( - "Create a specific Service Account require specify a namespace name"); - } - if (ObjectHelper.isEmpty(saToCreate)) { - LOG.error("Create a specific Service Account require specify a Service Account bean"); - throw new IllegalArgumentException( - "Create a specific Service Account require specify a Service Account bean"); - } - Map<String, String> labels = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_SERVICE_ACCOUNTS_LABELS, Map.class); - sa = getEndpoint().getKubernetesClient().serviceAccounts() - .inNamespace(namespaceName).create(saToCreate); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(sa); - } - - protected void doDeleteServiceAccount(Exchange exchange, String operation) - throws Exception { - String saName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_SERVICE_ACCOUNT_NAME, String.class); - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - if (ObjectHelper.isEmpty(saName)) { - LOG.error("Delete a specific Service Account require specify a Service Account name"); - throw new IllegalArgumentException( - "Delete a specific Service Account require specify a Service Account name"); - } - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Delete a specific Service Account require specify a namespace name"); - throw new IllegalArgumentException( - "Delete a specific Service Account require specify a namespace name"); - } - boolean saDeleted = getEndpoint().getKubernetesClient().serviceAccounts() - .inNamespace(namespaceName).withName(saName).delete(); - - MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); - exchange.getOut().setBody(saDeleted); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesServicesProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesServicesProducer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesServicesProducer.java deleted file mode 100644 index 12d2de0..0000000 --- a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/producer/KubernetesServicesProducer.java +++ /dev/null @@ -1,209 +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.component.kubernetes.producer; - -import java.util.Map; - -import io.fabric8.kubernetes.api.model.DoneableService; -import io.fabric8.kubernetes.api.model.Service; -import io.fabric8.kubernetes.api.model.ServiceBuilder; -import io.fabric8.kubernetes.api.model.ServiceList; -import io.fabric8.kubernetes.api.model.ServiceSpec; -import io.fabric8.kubernetes.client.dsl.MixedOperation; -import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; -import io.fabric8.kubernetes.client.dsl.Resource; - -import org.apache.camel.Exchange; -import org.apache.camel.component.kubernetes.KubernetesConstants; -import org.apache.camel.component.kubernetes.KubernetesEndpoint; -import org.apache.camel.impl.DefaultProducer; -import org.apache.camel.util.ObjectHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class KubernetesServicesProducer extends DefaultProducer { - - private static final Logger LOG = LoggerFactory - .getLogger(KubernetesServicesProducer.class); - - public KubernetesServicesProducer(KubernetesEndpoint endpoint) { - super(endpoint); - } - - @Override - public KubernetesEndpoint getEndpoint() { - return (KubernetesEndpoint) super.getEndpoint(); - } - - @Override - public void process(Exchange exchange) throws Exception { - String operation; - - if (ObjectHelper.isEmpty(getEndpoint().getKubernetesConfiguration() - .getOperation())) { - operation = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_OPERATION, String.class); - } else { - operation = getEndpoint().getKubernetesConfiguration() - .getOperation(); - } - - switch (operation) { - - case KubernetesOperations.LIST_SERVICES_OPERATION: - doList(exchange, operation); - break; - - case KubernetesOperations.LIST_SERVICES_BY_LABELS_OPERATION: - doListServiceByLabels(exchange, operation); - break; - - case KubernetesOperations.GET_SERVICE_OPERATION: - doGetService(exchange, operation); - break; - - case KubernetesOperations.CREATE_SERVICE_OPERATION: - doCreateService(exchange, operation); - break; - - case KubernetesOperations.DELETE_SERVICE_OPERATION: - doDeleteService(exchange, operation); - break; - - default: - throw new IllegalArgumentException("Unsupported operation " - + operation); - } - } - - protected void doList(Exchange exchange, String operation) throws Exception { - ServiceList servicesList = null; - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - if (!ObjectHelper.isEmpty(namespaceName)) { - servicesList = getEndpoint().getKubernetesClient().services() - .inNamespace(namespaceName).list(); - } else { - servicesList = getEndpoint().getKubernetesClient().services() - .list(); - } - exchange.getOut().setBody(servicesList.getItems()); - } - - protected void doListServiceByLabels(Exchange exchange, String operation) - throws Exception { - ServiceList servicesList = null; - Map<String, String> labels = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_SERVICE_LABELS, Map.class); - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - if (!ObjectHelper.isEmpty(namespaceName)) { - NonNamespaceOperation<Service, ServiceList, DoneableService, Resource<Service, DoneableService>> services; - services = getEndpoint().getKubernetesClient().services() - .inNamespace(namespaceName); - for (Map.Entry<String, String> entry : labels.entrySet()) { - services.withLabel(entry.getKey(), entry.getValue()); - } - servicesList = services.list(); - } else { - MixedOperation<Service, ServiceList, DoneableService, Resource<Service, DoneableService>> services; - services = getEndpoint().getKubernetesClient().services(); - for (Map.Entry<String, String> entry : labels.entrySet()) { - services.withLabel(entry.getKey(), entry.getValue()); - } - servicesList = services.list(); - } - exchange.getOut().setBody(servicesList.getItems()); - } - - protected void doGetService(Exchange exchange, String operation) - throws Exception { - Service service = null; - String serviceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_SERVICE_NAME, String.class); - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - if (ObjectHelper.isEmpty(serviceName)) { - LOG.error("Get a specific service require specify a service name"); - throw new IllegalArgumentException( - "Get a specific service require specify a service name"); - } - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Get a specific service require specify a namespace name"); - throw new IllegalArgumentException( - "Get a specific service require specify a namespace name"); - } - service = getEndpoint().getKubernetesClient().services() - .inNamespace(namespaceName).withName(serviceName).get(); - exchange.getOut().setBody(service); - } - - protected void doCreateService(Exchange exchange, String operation) - throws Exception { - Service service = null; - String serviceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_SERVICE_NAME, String.class); - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - ServiceSpec serviceSpec = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_SERVICE_SPEC, ServiceSpec.class); - if (ObjectHelper.isEmpty(serviceName)) { - LOG.error("Create a specific service require specify a service name"); - throw new IllegalArgumentException( - "Create a specific service require specify a service name"); - } - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Create a specific service require specify a namespace name"); - throw new IllegalArgumentException( - "Create a specific service require specify a namespace name"); - } - if (ObjectHelper.isEmpty(serviceSpec)) { - LOG.error("Create a specific service require specify a service spec bean"); - throw new IllegalArgumentException( - "Create a specific service require specify a service spec bean"); - } - Map<String, String> labels = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_SERVICE_LABELS, Map.class); - Service serviceCreating = new ServiceBuilder() - .withNewMetadata().withName(serviceName).withLabels(labels) - .endMetadata().withSpec(serviceSpec).build(); - service = getEndpoint().getKubernetesClient().services() - .inNamespace(namespaceName).create(serviceCreating); - exchange.getOut().setBody(service); - } - - protected void doDeleteService(Exchange exchange, String operation) - throws Exception { - String serviceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_SERVICE_NAME, String.class); - String namespaceName = exchange.getIn().getHeader( - KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); - if (ObjectHelper.isEmpty(serviceName)) { - LOG.error("Delete a specific service require specify a service name"); - throw new IllegalArgumentException( - "Delete a specific service require specify a service name"); - } - if (ObjectHelper.isEmpty(namespaceName)) { - LOG.error("Delete a specific service require specify a namespace name"); - throw new IllegalArgumentException( - "Delete a specific service require specify a namespace name"); - } - boolean serviceDeleted = getEndpoint().getKubernetesClient().services() - .inNamespace(namespaceName).withName(serviceName).delete(); - exchange.getOut().setBody(serviceDeleted); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/replication_controllers/KubernetesReplicationControllersComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/replication_controllers/KubernetesReplicationControllersComponent.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/replication_controllers/KubernetesReplicationControllersComponent.java new file mode 100644 index 0000000..fcd8ded --- /dev/null +++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/replication_controllers/KubernetesReplicationControllersComponent.java @@ -0,0 +1,28 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.kubernetes.replication_controllers; + +import org.apache.camel.component.kubernetes.AbstractKubernetesComponent; +import org.apache.camel.component.kubernetes.KubernetesConfiguration; + +public class KubernetesReplicationControllersComponent extends AbstractKubernetesComponent { + + protected KubernetesReplicationControllersEndpoint doCreateEndpoint(String uri, String remaining, KubernetesConfiguration config) throws Exception { + KubernetesReplicationControllersEndpoint endpoint = new KubernetesReplicationControllersEndpoint(uri, this, config); + return endpoint; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/replication_controllers/KubernetesReplicationControllersConsumer.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/replication_controllers/KubernetesReplicationControllersConsumer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/replication_controllers/KubernetesReplicationControllersConsumer.java new file mode 100644 index 0000000..932fbc7 --- /dev/null +++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/replication_controllers/KubernetesReplicationControllersConsumer.java @@ -0,0 +1,142 @@ +/** + * 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.component.kubernetes.replication_controllers; + +import java.util.concurrent.ExecutorService; + +import io.fabric8.kubernetes.api.model.DoneableReplicationController; +import io.fabric8.kubernetes.api.model.ReplicationController; +import io.fabric8.kubernetes.api.model.ReplicationControllerList; +import io.fabric8.kubernetes.client.KubernetesClientException; +import io.fabric8.kubernetes.client.Watch; +import io.fabric8.kubernetes.client.Watcher; +import io.fabric8.kubernetes.client.dsl.MixedOperation; +import io.fabric8.kubernetes.client.dsl.RollableScalableResource; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.component.kubernetes.AbstractKubernetesEndpoint; +import org.apache.camel.component.kubernetes.KubernetesConstants; +import org.apache.camel.component.kubernetes.consumer.common.ReplicationControllerEvent; +import org.apache.camel.impl.DefaultConsumer; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class KubernetesReplicationControllersConsumer extends DefaultConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(KubernetesReplicationControllersConsumer.class); + + private final Processor processor; + private ExecutorService executor; + private ReplicationControllersConsumerTask rcWatcher; + + public KubernetesReplicationControllersConsumer(AbstractKubernetesEndpoint endpoint, Processor processor) { + super(endpoint, processor); + this.processor = processor; + } + + @Override + public AbstractKubernetesEndpoint getEndpoint() { + return (AbstractKubernetesEndpoint) super.getEndpoint(); + } + + @Override + protected void doStart() throws Exception { + super.doStart(); + + executor = getEndpoint().createExecutor(); + rcWatcher = new ReplicationControllersConsumerTask(); + executor.submit(rcWatcher); + } + + @Override + protected void doStop() throws Exception { + super.doStop(); + + LOG.debug("Stopping Kubernetes Replication Controllers Consumer"); + if (executor != null) { + if (getEndpoint() != null && getEndpoint().getCamelContext() != null) { + if (rcWatcher != null) { + rcWatcher.getWatch().close(); + } + getEndpoint().getCamelContext().getExecutorServiceManager().shutdownNow(executor); + } else { + if (rcWatcher != null) { + rcWatcher.getWatch().close(); + } + executor.shutdownNow(); + } + } + executor = null; + } + + class ReplicationControllersConsumerTask implements Runnable { + + private Watch watch; + + @Override + public void run() { + MixedOperation<ReplicationController, ReplicationControllerList, + DoneableReplicationController, RollableScalableResource<ReplicationController, DoneableReplicationController>> w = getEndpoint().getKubernetesClient().replicationControllers(); + if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getNamespace())) { + w.inNamespace(getEndpoint().getKubernetesConfiguration().getNamespace()); + } + if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getLabelKey()) + && ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getLabelValue())) { + w.withLabel(getEndpoint().getKubernetesConfiguration().getLabelKey(), getEndpoint().getKubernetesConfiguration().getLabelValue()); + } + if (ObjectHelper.isNotEmpty(getEndpoint().getKubernetesConfiguration().getResourceName())) { + w.withName(getEndpoint().getKubernetesConfiguration().getResourceName()); + } + watch = w.watch(new Watcher<ReplicationController>() { + + @Override + public void eventReceived(io.fabric8.kubernetes.client.Watcher.Action action, + ReplicationController resource) { + ReplicationControllerEvent rce = new ReplicationControllerEvent(action, resource); + Exchange exchange = getEndpoint().createExchange(); + exchange.getIn().setBody(rce.getReplicationController()); + exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_EVENT_ACTION, rce.getAction()); + exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_EVENT_TIMESTAMP, System.currentTimeMillis()); + try { + processor.process(exchange); + } catch (Exception e) { + getExceptionHandler().handleException("Error during processing", exchange, e); + } + + } + + @Override + public void onClose(KubernetesClientException cause) { + if (cause != null) { + LOG.error(cause.getMessage(), cause); + } + } + + }); + } + + public Watch getWatch() { + return watch; + } + + public void setWatch(Watch watch) { + this.watch = watch; + } + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/replication_controllers/KubernetesReplicationControllersEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/replication_controllers/KubernetesReplicationControllersEndpoint.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/replication_controllers/KubernetesReplicationControllersEndpoint.java new file mode 100644 index 0000000..713893f --- /dev/null +++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/replication_controllers/KubernetesReplicationControllersEndpoint.java @@ -0,0 +1,69 @@ +/** + * 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.component.kubernetes.replication_controllers; + +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.component.kubernetes.AbstractKubernetesEndpoint; +import org.apache.camel.component.kubernetes.KubernetesConfiguration; +import org.apache.camel.component.kubernetes.build_configs.KubernetesBuildConfigsProducer; +import org.apache.camel.component.kubernetes.builds.KubernetesBuildsProducer; +import org.apache.camel.component.kubernetes.config_maps.KubernetesConfigMapsProducer; +import org.apache.camel.component.kubernetes.namespaces.KubernetesNamespacesConsumer; +import org.apache.camel.component.kubernetes.namespaces.KubernetesNamespacesProducer; +import org.apache.camel.component.kubernetes.nodes.KubernetesNodesConsumer; +import org.apache.camel.component.kubernetes.nodes.KubernetesNodesProducer; +import org.apache.camel.component.kubernetes.persistent_volumes.KubernetesPersistentVolumesProducer; +import org.apache.camel.component.kubernetes.persistent_volumes_claims.KubernetesPersistentVolumesClaimsProducer; +import org.apache.camel.component.kubernetes.pods.KubernetesPodsConsumer; +import org.apache.camel.component.kubernetes.pods.KubernetesPodsProducer; +import org.apache.camel.component.kubernetes.resources_quota.KubernetesResourcesQuotaProducer; +import org.apache.camel.component.kubernetes.secrets.KubernetesSecretsProducer; +import org.apache.camel.component.kubernetes.service_accounts.KubernetesServiceAccountsProducer; +import org.apache.camel.component.kubernetes.services.KubernetesServicesConsumer; +import org.apache.camel.component.kubernetes.services.KubernetesServicesProducer; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The Kubernetes Replication Controllers component provides a producer to execute kubernetes replication controller + * operations and a consumer to consume replication controller events. + */ +@UriEndpoint(firstVersion = "2.17.0", scheme = "kubernetes-replication-controllers", title = "Kubernetes Replication Controller", + syntax = "kubernetes-replication-controllers:masterUrl", consumerClass = KubernetesReplicationControllersConsumer.class, label = "container,cloud,paas") +public class KubernetesReplicationControllersEndpoint extends AbstractKubernetesEndpoint { + + private static final Logger LOG = LoggerFactory.getLogger(KubernetesReplicationControllersEndpoint.class); + + public KubernetesReplicationControllersEndpoint(String uri, KubernetesReplicationControllersComponent component, KubernetesConfiguration config) { + super(uri, component, config); + } + + @Override + public Producer createProducer() throws Exception { + return new KubernetesReplicationControllersProducer(this); + } + + @Override + public Consumer createConsumer(Processor processor) throws Exception { + return new KubernetesReplicationControllersConsumer(this, processor); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/replication_controllers/KubernetesReplicationControllersProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/replication_controllers/KubernetesReplicationControllersProducer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/replication_controllers/KubernetesReplicationControllersProducer.java new file mode 100644 index 0000000..d4f44d6 --- /dev/null +++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/replication_controllers/KubernetesReplicationControllersProducer.java @@ -0,0 +1,269 @@ +/** + * 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.component.kubernetes.replication_controllers; + +import java.util.Map; + +import io.fabric8.kubernetes.api.model.DoneableReplicationController; +import io.fabric8.kubernetes.api.model.ReplicationController; +import io.fabric8.kubernetes.api.model.ReplicationControllerBuilder; +import io.fabric8.kubernetes.api.model.ReplicationControllerList; +import io.fabric8.kubernetes.api.model.ReplicationControllerSpec; +import io.fabric8.kubernetes.client.dsl.MixedOperation; +import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; +import io.fabric8.kubernetes.client.dsl.RollableScalableResource; + +import org.apache.camel.Exchange; +import org.apache.camel.component.kubernetes.AbstractKubernetesEndpoint; +import org.apache.camel.component.kubernetes.KubernetesConstants; +import org.apache.camel.component.kubernetes.KubernetesOperations; +import org.apache.camel.impl.DefaultProducer; +import org.apache.camel.util.MessageHelper; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class KubernetesReplicationControllersProducer extends DefaultProducer { + + private static final Logger LOG = LoggerFactory + .getLogger(KubernetesReplicationControllersProducer.class); + + public KubernetesReplicationControllersProducer(AbstractKubernetesEndpoint endpoint) { + super(endpoint); + } + + @Override + public AbstractKubernetesEndpoint getEndpoint() { + return (AbstractKubernetesEndpoint) super.getEndpoint(); + } + + @Override + public void process(Exchange exchange) throws Exception { + String operation; + + if (ObjectHelper.isEmpty(getEndpoint().getKubernetesConfiguration() + .getOperation())) { + operation = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_OPERATION, String.class); + } else { + operation = getEndpoint().getKubernetesConfiguration() + .getOperation(); + } + + switch (operation) { + + case KubernetesOperations.LIST_REPLICATION_CONTROLLERS_OPERATION: + doList(exchange, operation); + break; + + case KubernetesOperations.LIST_REPLICATION_CONTROLLERS_BY_LABELS_OPERATION: + doListReplicationControllersByLabels(exchange, operation); + break; + + case KubernetesOperations.GET_REPLICATION_CONTROLLER_OPERATION: + doGetReplicationController(exchange, operation); + break; + + case KubernetesOperations.CREATE_REPLICATION_CONTROLLER_OPERATION: + doCreateReplicationController(exchange, operation); + break; + + case KubernetesOperations.DELETE_REPLICATION_CONTROLLER_OPERATION: + doDeleteReplicationController(exchange, operation); + break; + + case KubernetesOperations.SCALE_REPLICATION_CONTROLLER_OPERATION: + doScaleReplicationController(exchange, operation); + break; + + default: + throw new IllegalArgumentException("Unsupported operation " + + operation); + } + } + + protected void doList(Exchange exchange, String operation) throws Exception { + ReplicationControllerList rcList = null; + String namespaceName = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); + if (!ObjectHelper.isEmpty(namespaceName)) { + rcList = getEndpoint().getKubernetesClient() + .replicationControllers().inNamespace(namespaceName).list(); + } else { + rcList = getEndpoint().getKubernetesClient() + .replicationControllers().list(); + } + + MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); + exchange.getOut().setBody(rcList.getItems()); + } + + protected void doListReplicationControllersByLabels(Exchange exchange, + String operation) throws Exception { + ReplicationControllerList rcList = null; + Map<String, String> labels = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLERS_LABELS, + Map.class); + String namespaceName = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); + if (!ObjectHelper.isEmpty(namespaceName)) { + + NonNamespaceOperation<ReplicationController, ReplicationControllerList, DoneableReplicationController, + RollableScalableResource<ReplicationController, DoneableReplicationController>> replicationControllers = getEndpoint().getKubernetesClient() + .replicationControllers().inNamespace(namespaceName); + for (Map.Entry<String, String> entry : labels.entrySet()) { + replicationControllers.withLabel(entry.getKey(), + entry.getValue()); + } + rcList = replicationControllers.list(); + } else { + MixedOperation<ReplicationController, ReplicationControllerList, DoneableReplicationController, + RollableScalableResource<ReplicationController, DoneableReplicationController>> replicationControllers = getEndpoint().getKubernetesClient() + .replicationControllers(); + for (Map.Entry<String, String> entry : labels.entrySet()) { + replicationControllers.withLabel(entry.getKey(), + entry.getValue()); + } + rcList = replicationControllers.list(); + } + + MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); + exchange.getOut().setBody(rcList.getItems()); + + } + + protected void doGetReplicationController(Exchange exchange, + String operation) throws Exception { + ReplicationController rc = null; + String rcName = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME, + String.class); + String namespaceName = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); + if (ObjectHelper.isEmpty(rcName)) { + LOG.error("Get a specific replication controller require specify a replication controller name"); + throw new IllegalArgumentException( + "Get a specific replication controller require specify a replication controller name"); + } + if (ObjectHelper.isEmpty(namespaceName)) { + LOG.error("Get a specific replication controller require specify a namespace name"); + throw new IllegalArgumentException( + "Get a specific replication controller require specify a namespace name"); + } + rc = getEndpoint().getKubernetesClient().replicationControllers() + .inNamespace(namespaceName).withName(rcName).get(); + + MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); + exchange.getOut().setBody(rc); + } + + protected void doCreateReplicationController(Exchange exchange, + String operation) throws Exception { + ReplicationController rc = null; + String rcName = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME, + String.class); + String namespaceName = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); + ReplicationControllerSpec rcSpec = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_SPEC, + ReplicationControllerSpec.class); + if (ObjectHelper.isEmpty(rcName)) { + LOG.error("Create a specific replication controller require specify a replication controller name"); + throw new IllegalArgumentException( + "Create a specific replication controller require specify a replication controller name"); + } + if (ObjectHelper.isEmpty(namespaceName)) { + LOG.error("Create a specific replication controller require specify a namespace name"); + throw new IllegalArgumentException( + "Create a specific replication controller require specify a namespace name"); + } + if (ObjectHelper.isEmpty(rcSpec)) { + LOG.error("Create a specific replication controller require specify a replication controller spec bean"); + throw new IllegalArgumentException( + "Create a specific replication controller require specify a replication controller spec bean"); + } + Map<String, String> labels = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLERS_LABELS, + Map.class); + ReplicationController rcCreating = new ReplicationControllerBuilder() + .withNewMetadata().withName(rcName).withLabels(labels) + .endMetadata().withSpec(rcSpec).build(); + rc = getEndpoint().getKubernetesClient().replicationControllers() + .inNamespace(namespaceName).create(rcCreating); + + MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); + exchange.getOut().setBody(rc); + } + + protected void doDeleteReplicationController(Exchange exchange, + String operation) throws Exception { + String rcName = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME, + String.class); + String namespaceName = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); + if (ObjectHelper.isEmpty(rcName)) { + LOG.error("Delete a specific replication controller require specify a replication controller name"); + throw new IllegalArgumentException( + "Delete a specific replication controller require specify a replication controller name"); + } + if (ObjectHelper.isEmpty(namespaceName)) { + LOG.error("Delete a specific replication controller require specify a namespace name"); + throw new IllegalArgumentException( + "Delete a specific replication controller require specify a namespace name"); + } + boolean rcDeleted = getEndpoint().getKubernetesClient() + .replicationControllers().inNamespace(namespaceName) + .withName(rcName).delete(); + + MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); + exchange.getOut().setBody(rcDeleted); + } + + protected void doScaleReplicationController(Exchange exchange, + String operation) throws Exception { + String rcName = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME, + String.class); + String namespaceName = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); + Integer replicasNumber = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_REPLICAS, Integer.class); + if (ObjectHelper.isEmpty(rcName)) { + LOG.error("Scale a specific replication controller require specify a replication controller name"); + throw new IllegalArgumentException( + "Scale a specific replication controller require specify a replication controller name"); + } + if (ObjectHelper.isEmpty(namespaceName)) { + LOG.error("Scale a specific replication controller require specify a namespace name"); + throw new IllegalArgumentException( + "Scale a specific replication controller require specify a namespace name"); + } + if (ObjectHelper.isEmpty(replicasNumber)) { + LOG.error("Scale a specific replication controller require specify a replicas number"); + throw new IllegalArgumentException( + "Scale a specific replication controller require specify a replicas number"); + } + ReplicationController rcScaled = getEndpoint().getKubernetesClient() + .replicationControllers().inNamespace(namespaceName) + .withName(rcName).scale(replicasNumber, true); + + MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); + exchange.getOut().setBody(rcScaled.getStatus().getReplicas()); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/resources_quota/KubernetesResourcesQuotaComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/resources_quota/KubernetesResourcesQuotaComponent.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/resources_quota/KubernetesResourcesQuotaComponent.java new file mode 100644 index 0000000..2cc246c --- /dev/null +++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/resources_quota/KubernetesResourcesQuotaComponent.java @@ -0,0 +1,28 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.kubernetes.resources_quota; + +import org.apache.camel.component.kubernetes.AbstractKubernetesComponent; +import org.apache.camel.component.kubernetes.KubernetesConfiguration; + +public class KubernetesResourcesQuotaComponent extends AbstractKubernetesComponent { + + protected KubernetesResourcesQuotaEndpoint doCreateEndpoint(String uri, String remaining, KubernetesConfiguration config) throws Exception { + KubernetesResourcesQuotaEndpoint endpoint = new KubernetesResourcesQuotaEndpoint(uri, this, config); + return endpoint; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/resources_quota/KubernetesResourcesQuotaEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/resources_quota/KubernetesResourcesQuotaEndpoint.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/resources_quota/KubernetesResourcesQuotaEndpoint.java new file mode 100644 index 0000000..641578e --- /dev/null +++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/resources_quota/KubernetesResourcesQuotaEndpoint.java @@ -0,0 +1,69 @@ +/** + * 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.component.kubernetes.resources_quota; + +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.component.kubernetes.AbstractKubernetesEndpoint; +import org.apache.camel.component.kubernetes.KubernetesConfiguration; +import org.apache.camel.component.kubernetes.build_configs.KubernetesBuildConfigsProducer; +import org.apache.camel.component.kubernetes.builds.KubernetesBuildsProducer; +import org.apache.camel.component.kubernetes.config_maps.KubernetesConfigMapsProducer; +import org.apache.camel.component.kubernetes.namespaces.KubernetesNamespacesConsumer; +import org.apache.camel.component.kubernetes.namespaces.KubernetesNamespacesProducer; +import org.apache.camel.component.kubernetes.nodes.KubernetesNodesConsumer; +import org.apache.camel.component.kubernetes.nodes.KubernetesNodesProducer; +import org.apache.camel.component.kubernetes.persistent_volumes.KubernetesPersistentVolumesProducer; +import org.apache.camel.component.kubernetes.persistent_volumes_claims.KubernetesPersistentVolumesClaimsProducer; +import org.apache.camel.component.kubernetes.pods.KubernetesPodsConsumer; +import org.apache.camel.component.kubernetes.pods.KubernetesPodsProducer; +import org.apache.camel.component.kubernetes.replication_controllers.KubernetesReplicationControllersConsumer; +import org.apache.camel.component.kubernetes.replication_controllers.KubernetesReplicationControllersProducer; +import org.apache.camel.component.kubernetes.secrets.KubernetesSecretsProducer; +import org.apache.camel.component.kubernetes.service_accounts.KubernetesServiceAccountsProducer; +import org.apache.camel.component.kubernetes.services.KubernetesServicesConsumer; +import org.apache.camel.component.kubernetes.services.KubernetesServicesProducer; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The Kubernetes Resources Quota component provides a producer to execute kubernetes resources quota operations. + */ +@UriEndpoint(firstVersion = "2.17.0", scheme = "kubernetes-resources-quota", title = "Kubernetes Resources Quota", + syntax = "kubernetes-resources-quota:masterUrl", producerOnly = true, label = "container,cloud,paas") +public class KubernetesResourcesQuotaEndpoint extends AbstractKubernetesEndpoint { + + private static final Logger LOG = LoggerFactory.getLogger(KubernetesResourcesQuotaEndpoint.class); + + public KubernetesResourcesQuotaEndpoint(String uri, KubernetesResourcesQuotaComponent component, KubernetesConfiguration config) { + super(uri, component, config); + } + + @Override + public Producer createProducer() throws Exception { + return new KubernetesResourcesQuotaProducer(this); + } + + @Override + public Consumer createConsumer(Processor processor) throws Exception { + throw new IllegalArgumentException("The kubernetes-resources-quota doesn't support consumer"); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/resources_quota/KubernetesResourcesQuotaProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/resources_quota/KubernetesResourcesQuotaProducer.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/resources_quota/KubernetesResourcesQuotaProducer.java new file mode 100644 index 0000000..54b91c0 --- /dev/null +++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/resources_quota/KubernetesResourcesQuotaProducer.java @@ -0,0 +1,219 @@ +/** + * 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.component.kubernetes.resources_quota; + +import java.util.Map; + +import io.fabric8.kubernetes.api.model.DoneableResourceQuota; +import io.fabric8.kubernetes.api.model.ResourceQuota; +import io.fabric8.kubernetes.api.model.ResourceQuotaBuilder; +import io.fabric8.kubernetes.api.model.ResourceQuotaList; +import io.fabric8.kubernetes.api.model.ResourceQuotaSpec; +import io.fabric8.kubernetes.client.dsl.MixedOperation; +import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; +import io.fabric8.kubernetes.client.dsl.Resource; + +import org.apache.camel.Exchange; +import org.apache.camel.component.kubernetes.AbstractKubernetesEndpoint; +import org.apache.camel.component.kubernetes.KubernetesConstants; +import org.apache.camel.component.kubernetes.KubernetesEndpoint; +import org.apache.camel.component.kubernetes.KubernetesOperations; +import org.apache.camel.impl.DefaultProducer; +import org.apache.camel.util.MessageHelper; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class KubernetesResourcesQuotaProducer extends DefaultProducer { + + private static final Logger LOG = LoggerFactory + .getLogger(KubernetesResourcesQuotaProducer.class); + + public KubernetesResourcesQuotaProducer(AbstractKubernetesEndpoint endpoint) { + super(endpoint); + } + + @Override + public AbstractKubernetesEndpoint getEndpoint() { + return (AbstractKubernetesEndpoint) super.getEndpoint(); + } + + @Override + public void process(Exchange exchange) throws Exception { + String operation; + + if (ObjectHelper.isEmpty(getEndpoint().getKubernetesConfiguration() + .getOperation())) { + operation = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_OPERATION, String.class); + } else { + operation = getEndpoint().getKubernetesConfiguration() + .getOperation(); + } + + switch (operation) { + + case KubernetesOperations.LIST_RESOURCES_QUOTA: + doList(exchange, operation); + break; + + case KubernetesOperations.LIST_SECRETS_BY_LABELS_OPERATION: + doListResourceQuotasByLabels(exchange, operation); + break; + + case KubernetesOperations.GET_RESOURCE_QUOTA_OPERATION: + doGetResourceQuota(exchange, operation); + break; + + case KubernetesOperations.CREATE_RESOURCE_QUOTA_OPERATION: + doCreateResourceQuota(exchange, operation); + break; + + case KubernetesOperations.DELETE_RESOURCE_QUOTA_OPERATION: + doDeleteResourceQuota(exchange, operation); + break; + + default: + throw new IllegalArgumentException("Unsupported operation " + + operation); + } + } + + protected void doList(Exchange exchange, String operation) throws Exception { + ResourceQuotaList resList = getEndpoint().getKubernetesClient() + .resourceQuotas().list(); + exchange.getOut().setBody(resList.getItems()); + } + + protected void doListResourceQuotasByLabels(Exchange exchange, + String operation) throws Exception { + ResourceQuotaList resList = null; + Map<String, String> labels = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_LABELS, + Map.class); + String namespaceName = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); + if (!ObjectHelper.isEmpty(namespaceName)) { + NonNamespaceOperation<ResourceQuota, ResourceQuotaList, DoneableResourceQuota, Resource<ResourceQuota, DoneableResourceQuota>> resQuota; + resQuota = getEndpoint().getKubernetesClient().resourceQuotas() + .inNamespace(namespaceName); + for (Map.Entry<String, String> entry : labels.entrySet()) { + resQuota.withLabel(entry.getKey(), entry.getValue()); + } + resList = resQuota.list(); + } else { + MixedOperation<ResourceQuota, ResourceQuotaList, DoneableResourceQuota, Resource<ResourceQuota, DoneableResourceQuota>> resQuota; + resQuota = getEndpoint().getKubernetesClient().resourceQuotas(); + for (Map.Entry<String, String> entry : labels.entrySet()) { + resQuota.withLabel(entry.getKey(), entry.getValue()); + } + resList = resQuota.list(); + } + + MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); + exchange.getOut().setBody(resList.getItems()); + } + + protected void doGetResourceQuota(Exchange exchange, String operation) + throws Exception { + ResourceQuota rq = null; + String rqName = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_NAME, + String.class); + String namespaceName = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); + if (ObjectHelper.isEmpty(rqName)) { + LOG.error("Get a specific Resource Quota require specify a Resource Quota name"); + throw new IllegalArgumentException( + "Get a specific Resource Quota require specify a Resource Quota name"); + } + if (ObjectHelper.isEmpty(namespaceName)) { + LOG.error("Get a specific Resource Quota require specify a namespace name"); + throw new IllegalArgumentException( + "Get a specific Resource Quota require specify a namespace name"); + } + rq = getEndpoint().getKubernetesClient().resourceQuotas() + .inNamespace(namespaceName).withName(rqName).get(); + + MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); + exchange.getOut().setBody(rq); + } + + protected void doCreateResourceQuota(Exchange exchange, String operation) + throws Exception { + ResourceQuota rq = null; + String rqName = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_NAME, + String.class); + String namespaceName = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); + ResourceQuotaSpec rqSpec = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_RESOURCE_QUOTA_SPEC, + ResourceQuotaSpec.class); + if (ObjectHelper.isEmpty(rqName)) { + LOG.error("Create a specific resource quota require specify a resource quota name"); + throw new IllegalArgumentException( + "Create a specific resource quota require specify a resource quota name"); + } + if (ObjectHelper.isEmpty(namespaceName)) { + LOG.error("Create a specific resource quota require specify a namespace name"); + throw new IllegalArgumentException( + "Create a specific resource quota require specify a namespace name"); + } + if (ObjectHelper.isEmpty(rqSpec)) { + LOG.error("Create a specific resource quota require specify a resource quota spec bean"); + throw new IllegalArgumentException( + "Create a specific resource quota require specify a resource quota spec bean"); + } + Map<String, String> labels = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_LABELS, + Map.class); + ResourceQuota rqCreating = new ResourceQuotaBuilder() + .withNewMetadata().withName(rqName).withLabels(labels) + .endMetadata().withSpec(rqSpec).build(); + rq = getEndpoint().getKubernetesClient().resourceQuotas() + .inNamespace(namespaceName).create(rqCreating); + + MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); + exchange.getOut().setBody(rq); + } + + protected void doDeleteResourceQuota(Exchange exchange, String operation) + throws Exception { + String rqName = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_NAME, + String.class); + String namespaceName = exchange.getIn().getHeader( + KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); + if (ObjectHelper.isEmpty(rqName)) { + LOG.error("Delete a specific resource quota require specify a resource quota name"); + throw new IllegalArgumentException( + "Delete a specific resource quota require specify a resource quota name"); + } + if (ObjectHelper.isEmpty(namespaceName)) { + LOG.error("Delete a specific resource quota require specify a namespace name"); + throw new IllegalArgumentException( + "Delete a specific resource quota require specify a namespace name"); + } + boolean rqDeleted = getEndpoint().getKubernetesClient() + .resourceQuotas().inNamespace(namespaceName).withName(rqName) + .delete(); + + MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); + exchange.getOut().setBody(rqDeleted); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/secrets/KubernetesSecretsComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/secrets/KubernetesSecretsComponent.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/secrets/KubernetesSecretsComponent.java new file mode 100644 index 0000000..5d7e7ef --- /dev/null +++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/secrets/KubernetesSecretsComponent.java @@ -0,0 +1,28 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.kubernetes.secrets; + +import org.apache.camel.component.kubernetes.AbstractKubernetesComponent; +import org.apache.camel.component.kubernetes.KubernetesConfiguration; + +public class KubernetesSecretsComponent extends AbstractKubernetesComponent { + + protected KubernetesSecretsEndpoint doCreateEndpoint(String uri, String remaining, KubernetesConfiguration config) throws Exception { + KubernetesSecretsEndpoint endpoint = new KubernetesSecretsEndpoint(uri, this, config); + return endpoint; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/89eee3b9/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/secrets/KubernetesSecretsEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/secrets/KubernetesSecretsEndpoint.java b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/secrets/KubernetesSecretsEndpoint.java new file mode 100644 index 0000000..094de9e --- /dev/null +++ b/components/camel-kubernetes/src/main/java/org/apache/camel/component/kubernetes/secrets/KubernetesSecretsEndpoint.java @@ -0,0 +1,68 @@ +/** + * 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.component.kubernetes.secrets; + +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.component.kubernetes.AbstractKubernetesEndpoint; +import org.apache.camel.component.kubernetes.KubernetesConfiguration; +import org.apache.camel.component.kubernetes.build_configs.KubernetesBuildConfigsProducer; +import org.apache.camel.component.kubernetes.builds.KubernetesBuildsProducer; +import org.apache.camel.component.kubernetes.config_maps.KubernetesConfigMapsProducer; +import org.apache.camel.component.kubernetes.namespaces.KubernetesNamespacesConsumer; +import org.apache.camel.component.kubernetes.namespaces.KubernetesNamespacesProducer; +import org.apache.camel.component.kubernetes.nodes.KubernetesNodesConsumer; +import org.apache.camel.component.kubernetes.nodes.KubernetesNodesProducer; +import org.apache.camel.component.kubernetes.persistent_volumes.KubernetesPersistentVolumesProducer; +import org.apache.camel.component.kubernetes.persistent_volumes_claims.KubernetesPersistentVolumesClaimsProducer; +import org.apache.camel.component.kubernetes.pods.KubernetesPodsConsumer; +import org.apache.camel.component.kubernetes.pods.KubernetesPodsProducer; +import org.apache.camel.component.kubernetes.replication_controllers.KubernetesReplicationControllersConsumer; +import org.apache.camel.component.kubernetes.replication_controllers.KubernetesReplicationControllersProducer; +import org.apache.camel.component.kubernetes.resources_quota.KubernetesResourcesQuotaProducer; +import org.apache.camel.component.kubernetes.service_accounts.KubernetesServiceAccountsProducer; +import org.apache.camel.component.kubernetes.services.KubernetesServicesConsumer; +import org.apache.camel.component.kubernetes.services.KubernetesServicesProducer; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The Kubernetes Secrets component provides a producer to execute kubernetes secret operations. + */ +@UriEndpoint(firstVersion = "2.17.0", scheme = "kubernetes-secrets", title = "Kubernetes Secrets", syntax = "kubernetes-secrets:masterUrl", producerOnly = true, label = "container,cloud,paas") +public class KubernetesSecretsEndpoint extends AbstractKubernetesEndpoint { + + private static final Logger LOG = LoggerFactory.getLogger(KubernetesSecretsEndpoint.class); + + public KubernetesSecretsEndpoint(String uri, KubernetesSecretsComponent component, KubernetesConfiguration config) { + super(uri, component, config); + } + + @Override + public Producer createProducer() throws Exception { + return new KubernetesSecretsProducer(this); + } + + @Override + public Consumer createConsumer(Processor processor) throws Exception { + throw new IllegalArgumentException("The kubernetes-secrets doesn't support consumer"); + } + +}
