-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(#1280): Add camel jbang plugin support
* Add camel jbang plugin configuration action * Add camel jbang plugin kubernetes actions: run, verify and delete * Support XML and Yaml
- Loading branch information
1 parent
fd607bc
commit 8b9a476
Showing
13 changed files
with
2,431 additions
and
1 deletion.
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
...ts/citrus-camel/src/main/java/org/citrusframework/camel/actions/AddCamelPluginAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* Copyright the original author or authors. | ||
* | ||
* Licensed 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.citrusframework.camel.actions; | ||
|
||
import org.citrusframework.context.TestContext; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/** | ||
* Install a specific plugin to a Camel JBang tooling. | ||
*/ | ||
public class AddCamelPluginAction extends AbstractCamelJBangAction { | ||
|
||
/** Logger */ | ||
private static final Logger logger = LoggerFactory.getLogger(AddCamelPluginAction.class); | ||
|
||
/** Camel Jbang plugin name */ | ||
private final String name; | ||
/** Camel Jbang command arguments */ | ||
private final List<String> args; | ||
|
||
/** | ||
* Default constructor. | ||
*/ | ||
public AddCamelPluginAction(AddCamelPluginAction.Builder builder) { | ||
super("plugin", builder); | ||
this.name = builder.name; | ||
this.args = builder.args; | ||
} | ||
|
||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public void doExecute(TestContext context) { | ||
logger.info("Adding Camel plugin '%s' ...".formatted(name)); | ||
List<String> installedPlugins = camelJBang().getPlugins(); | ||
|
||
if (!installedPlugins.contains(name)) { | ||
List<String> fullArgs = new ArrayList<>(); | ||
fullArgs.add("add"); | ||
fullArgs.add(name); | ||
if (args != null){ | ||
fullArgs.addAll(args); | ||
} | ||
camelJBang().camelApp().run("plugin", fullArgs.toArray(String[]::new)); | ||
} else { | ||
logger.info("Adding Camel plugin '%s' skipped: already installed".formatted(name)); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Action builder. | ||
*/ | ||
public static final class Builder extends AbstractCamelJBangAction.Builder<AddCamelPluginAction, AddCamelPluginAction.Builder> { | ||
private String name; | ||
private final List<String> args = new ArrayList<>(); | ||
|
||
|
||
/** | ||
* Sets the plugin name. | ||
* @param name | ||
* @return | ||
*/ | ||
public Builder pluginName(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
|
||
/** | ||
* Adds a command argument. | ||
* @param arg | ||
* @return | ||
*/ | ||
public Builder withArg(String arg) { | ||
this.args.add(arg); | ||
return this; | ||
} | ||
|
||
/** | ||
* Adds a command argument with name and value. | ||
* @param name | ||
* @param value | ||
* @return | ||
*/ | ||
public Builder withArg(String name, String value) { | ||
this.args.add(name); | ||
this.args.add(value); | ||
return this; | ||
} | ||
|
||
/** | ||
* Adds command arguments. | ||
* @param args | ||
* @return | ||
*/ | ||
public Builder withArgs(String... args) { | ||
this.args.addAll(Arrays.asList(args)); | ||
return this; | ||
} | ||
|
||
@Override | ||
public AddCamelPluginAction build() { | ||
return new AddCamelPluginAction(this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
196 changes: 196 additions & 0 deletions
196
...us-camel/src/main/java/org/citrusframework/camel/actions/CamelKubernetesDeleteAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
/* | ||
* Copyright the original author or authors. | ||
* | ||
* Licensed 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.citrusframework.camel.actions; | ||
|
||
import org.citrusframework.context.TestContext; | ||
import org.citrusframework.spi.Resource; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Delete kubernetes resources deployed from a Camel project or Camel integration with Camel JBang tooling. | ||
*/ | ||
public class CamelKubernetesDeleteAction extends AbstractCamelJBangAction { | ||
|
||
/** | ||
* Logger | ||
*/ | ||
private static final Logger logger = LoggerFactory.getLogger(CamelKubernetesDeleteAction.class); | ||
|
||
/** | ||
* Camel integration resource | ||
*/ | ||
private final Resource integrationResource; | ||
|
||
/** | ||
* Camel integration name | ||
*/ | ||
private final String integrationName; | ||
|
||
/** | ||
* Camel Jbang cluster type target | ||
*/ | ||
private final String clusterType; | ||
|
||
/** | ||
* Project directory | ||
*/ | ||
private final String workingDir; | ||
|
||
/** | ||
* Kubernetes Namespace | ||
*/ | ||
private final String namespace; | ||
|
||
/** | ||
* Default constructor. | ||
*/ | ||
public CamelKubernetesDeleteAction(Builder builder) { | ||
super("delete-kubernetes", builder); | ||
|
||
this.integrationResource = builder.integrationResource; | ||
this.integrationName = builder.integrationName; | ||
this.clusterType = builder.clusterType; | ||
this.workingDir = builder.workingDir; | ||
this.namespace = builder.namespace; | ||
|
||
} | ||
|
||
@Override | ||
public void doExecute(TestContext context) { | ||
logger.info("Deleting integration deployed from a Camel Kubernetes project ..."); | ||
List<String> fullArgs = new ArrayList<>(); | ||
fullArgs.add("delete"); | ||
if (integrationResource != null) { | ||
fullArgs.add(integrationResource.getFile().toPath().toAbsolutePath().toString()); | ||
} | ||
if (integrationName != null) { | ||
fullArgs.add("--name"); | ||
fullArgs.add(integrationName); | ||
} | ||
if (clusterType != null) { | ||
fullArgs.add("--cluster-type"); | ||
fullArgs.add(clusterType); | ||
} | ||
if (workingDir != null) { | ||
fullArgs.add("--working-dir"); | ||
fullArgs.add(workingDir); | ||
} | ||
if (namespace != null) { | ||
fullArgs.add("--namespace"); | ||
fullArgs.add(namespace); | ||
} | ||
camelJBang().camelApp().run("kubernetes", fullArgs.toArray(String[]::new)); | ||
|
||
} | ||
|
||
public Resource getIntegrationResource() { | ||
return integrationResource; | ||
} | ||
|
||
public String getIntegrationName() { | ||
return integrationName; | ||
} | ||
|
||
public String getClusterType() { | ||
return clusterType; | ||
} | ||
|
||
public String getWorkingDir() { | ||
return workingDir; | ||
} | ||
|
||
public String getNamespace() { | ||
return namespace; | ||
} | ||
|
||
/** | ||
* Action builder. | ||
*/ | ||
public static final class Builder extends AbstractCamelJBangAction.Builder<CamelKubernetesDeleteAction, CamelKubernetesDeleteAction.Builder> { | ||
|
||
private Resource integrationResource; | ||
private String integrationName; | ||
private String clusterType; | ||
private String workingDir; | ||
private String namespace; | ||
|
||
|
||
/** | ||
* Delete Camel JBang kubernetes resources integration resource. | ||
* | ||
* @param resource | ||
* @return | ||
*/ | ||
public Builder integration(Resource resource) { | ||
this.integrationResource = resource; | ||
return this; | ||
} | ||
|
||
/** | ||
* Delete Camel JBang kubernetes resources for this integration. | ||
* | ||
* @param name | ||
* @return | ||
*/ | ||
public Builder integration(String name) { | ||
this.integrationName = name; | ||
return this; | ||
} | ||
|
||
/** | ||
* Set cluster type target. | ||
* | ||
* @param clusterType | ||
* @return | ||
*/ | ||
public Builder clusterType(String clusterType) { | ||
this.clusterType = clusterType; | ||
return this; | ||
} | ||
|
||
/** | ||
* The working directory where to find exported project sources. | ||
* | ||
* @param dir directory path | ||
* @return | ||
*/ | ||
public Builder workingDir(String dir) { | ||
this.workingDir = dir; | ||
return this; | ||
} | ||
|
||
/** | ||
* The Namespace wherethe kubernetes resources are deployed. | ||
* | ||
* @param namespace namespace | ||
* @return | ||
*/ | ||
public Builder namespace(String namespace) { | ||
this.namespace = namespace; | ||
return this; | ||
} | ||
|
||
@Override | ||
public CamelKubernetesDeleteAction build() { | ||
return new CamelKubernetesDeleteAction(this); | ||
} | ||
} | ||
} |
Oops, something went wrong.