How to use getService method of com.consol.citrus.kubernetes.command.CreateService class

Best Citrus code snippet using com.consol.citrus.kubernetes.command.CreateService.getService

Source:KubernetesExecuteAction.java Github

copy

Full Screen

1/*2 * Copyright 2006-2016 the original author or authors.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.consol.citrus.kubernetes.actions;17import java.util.Collections;18import java.util.HashMap;19import java.util.Map;20import java.util.Optional;21import com.consol.citrus.AbstractTestActionBuilder;22import com.consol.citrus.actions.AbstractTestAction;23import com.consol.citrus.context.TestContext;24import com.consol.citrus.exceptions.CitrusRuntimeException;25import com.consol.citrus.exceptions.ValidationException;26import com.consol.citrus.kubernetes.client.KubernetesClient;27import com.consol.citrus.kubernetes.command.CommandResult;28import com.consol.citrus.kubernetes.command.CommandResultCallback;29import com.consol.citrus.kubernetes.command.CreatePod;30import com.consol.citrus.kubernetes.command.CreateService;31import com.consol.citrus.kubernetes.command.DeletePod;32import com.consol.citrus.kubernetes.command.DeleteResult;33import com.consol.citrus.kubernetes.command.DeleteService;34import com.consol.citrus.kubernetes.command.GetPod;35import com.consol.citrus.kubernetes.command.GetService;36import com.consol.citrus.kubernetes.command.Info;37import com.consol.citrus.kubernetes.command.InfoResult;38import com.consol.citrus.kubernetes.command.KubernetesCommand;39import com.consol.citrus.kubernetes.command.ListEndpoints;40import com.consol.citrus.kubernetes.command.ListEvents;41import com.consol.citrus.kubernetes.command.ListNamespaces;42import com.consol.citrus.kubernetes.command.ListNodes;43import com.consol.citrus.kubernetes.command.ListPods;44import com.consol.citrus.kubernetes.command.ListReplicationControllers;45import com.consol.citrus.kubernetes.command.ListServices;46import com.consol.citrus.kubernetes.command.WatchNamespaces;47import com.consol.citrus.kubernetes.command.WatchNodes;48import com.consol.citrus.kubernetes.command.WatchPods;49import com.consol.citrus.kubernetes.command.WatchReplicationControllers;50import com.consol.citrus.kubernetes.command.WatchServices;51import com.consol.citrus.message.DefaultMessage;52import com.consol.citrus.validation.MessageValidator;53import com.consol.citrus.validation.context.ValidationContext;54import com.consol.citrus.validation.json.JsonMessageValidationContext;55import com.consol.citrus.validation.json.JsonPathMessageValidationContext;56import com.fasterxml.jackson.core.JsonProcessingException;57import io.fabric8.kubernetes.api.model.EndpointsList;58import io.fabric8.kubernetes.api.model.EventList;59import io.fabric8.kubernetes.api.model.KubernetesResource;60import io.fabric8.kubernetes.api.model.Namespace;61import io.fabric8.kubernetes.api.model.NamespaceList;62import io.fabric8.kubernetes.api.model.Node;63import io.fabric8.kubernetes.api.model.NodeList;64import io.fabric8.kubernetes.api.model.Pod;65import io.fabric8.kubernetes.api.model.PodList;66import io.fabric8.kubernetes.api.model.ReplicationController;67import io.fabric8.kubernetes.api.model.ReplicationControllerList;68import io.fabric8.kubernetes.api.model.Service;69import io.fabric8.kubernetes.api.model.ServiceList;70import org.slf4j.Logger;71import org.slf4j.LoggerFactory;72import org.springframework.core.io.Resource;73import org.springframework.util.CollectionUtils;74import org.springframework.util.StringUtils;75/**76 * Executes kubernetes command with given kubernetes client implementation. Possible command result is stored within command object.77 *78 * @author Christoph Deppisch79 * @since 2.780 */81public class KubernetesExecuteAction extends AbstractTestAction {82 /** Kubernetes client instance */83 private final KubernetesClient kubernetesClient;84 /** Kubernetes command to execute */85 private final KubernetesCommand command;86 /** Control command result for validation */87 private final String commandResult;88 /** Control path expressions in command result */89 private final Map<String, Object> commandResultExpressions;90 /** Validator used to validate expected json results */91 private final MessageValidator<? extends ValidationContext> jsonMessageValidator;92 private final MessageValidator<? extends ValidationContext> jsonPathMessageValidator;93 public static final String DEFAULT_JSON_MESSAGE_VALIDATOR = "defaultJsonMessageValidator";94 public static final String DEFAULT_JSON_PATH_MESSAGE_VALIDATOR = "defaultJsonPathMessageValidator";95 /** Logger */96 private static Logger log = LoggerFactory.getLogger(KubernetesExecuteAction.class);97 /**98 * Default constructor.99 */100 public KubernetesExecuteAction(Builder builder) {101 super("kubernetes-execute", builder);102 this.kubernetesClient = builder.kubernetesClient;103 this.command = builder.command;104 this.commandResult = builder.commandResult;105 this.commandResultExpressions = builder.commandResultExpressions;106 this.jsonMessageValidator = builder.jsonMessageValidator;107 this.jsonPathMessageValidator = builder.jsonPathMessageValidator;108 }109 @Override110 public void doExecute(TestContext context) {111 try {112 if (log.isDebugEnabled()) {113 log.debug(String.format("Executing Kubernetes command '%s'", command.getName()));114 }115 command.execute(kubernetesClient, context);116 validateCommandResult(command, context);117 log.info(String.format("Kubernetes command execution successful: '%s'", command.getName()));118 } catch (CitrusRuntimeException e) {119 throw e;120 } catch (Exception e) {121 throw new CitrusRuntimeException("Unable to perform kubernetes command", e);122 }123 }124 /**125 * Validate command results.126 * @param command127 * @param context128 */129 private void validateCommandResult(KubernetesCommand command, TestContext context) {130 if (log.isDebugEnabled()) {131 log.debug("Starting Kubernetes command result validation");132 }133 CommandResult<?> result = command.getCommandResult();134 if (StringUtils.hasText(commandResult) || !CollectionUtils.isEmpty(commandResultExpressions)) {135 if (result == null) {136 throw new ValidationException("Missing Kubernetes command result");137 }138 try {139 String commandResultJson = kubernetesClient.getEndpointConfiguration()140 .getObjectMapper().writeValueAsString(result);141 if (StringUtils.hasText(commandResult)) {142 getMessageValidator(context).validateMessage(new DefaultMessage(commandResultJson), new DefaultMessage(commandResult), context, Collections.singletonList(new JsonMessageValidationContext()));143 log.info("Kubernetes command result validation successful - all values OK!");144 }145 if (!CollectionUtils.isEmpty(commandResultExpressions)) {146 JsonPathMessageValidationContext validationContext = new JsonPathMessageValidationContext.Builder()147 .expressions(commandResultExpressions)148 .build();149 getPathValidator(context).validateMessage(new DefaultMessage(commandResultJson), new DefaultMessage(commandResult), context, Collections.singletonList(validationContext));150 log.info("Kubernetes command result path validation successful - all values OK!");151 }152 } catch (JsonProcessingException e) {153 throw new CitrusRuntimeException(e);154 }155 }156 if (command.getResultCallback() != null && result != null) {157 command.getResultCallback().validateCommandResult(result, context);158 }159 }160 /**161 * Find proper JSON message validator. Uses several strategies to lookup default JSON message validator.162 * @param context163 * @return164 */165 private MessageValidator<? extends ValidationContext> getMessageValidator(TestContext context) {166 if (jsonMessageValidator != null) {167 return jsonMessageValidator;168 }169 // try to find json message validator in registry170 Optional<MessageValidator<? extends ValidationContext>> defaultJsonMessageValidator = context.getMessageValidatorRegistry().findMessageValidator(DEFAULT_JSON_MESSAGE_VALIDATOR);171 if (!defaultJsonMessageValidator.isPresent()172 && context.getReferenceResolver().isResolvable(DEFAULT_JSON_MESSAGE_VALIDATOR)) {173 defaultJsonMessageValidator = Optional.of(context.getReferenceResolver().resolve(DEFAULT_JSON_MESSAGE_VALIDATOR, MessageValidator.class));174 }175 if (!defaultJsonMessageValidator.isPresent()) {176 // try to find json message validator via resource path lookup177 defaultJsonMessageValidator = MessageValidator.lookup("json");178 }179 if (defaultJsonMessageValidator.isPresent()) {180 return defaultJsonMessageValidator.get();181 }182 throw new CitrusRuntimeException("Unable to locate proper JSON message validator - please add validator to project");183 }184 /**185 * Find proper JSON path message validator. Uses several strategies to lookup default JSON path message validator.186 * @param context187 * @return188 */189 private MessageValidator<? extends ValidationContext> getPathValidator(TestContext context) {190 if (jsonPathMessageValidator != null) {191 return jsonPathMessageValidator;192 }193 // try to find json message validator in registry194 Optional<MessageValidator<? extends ValidationContext>> defaultJsonMessageValidator = context.getMessageValidatorRegistry().findMessageValidator(DEFAULT_JSON_PATH_MESSAGE_VALIDATOR);195 if (!defaultJsonMessageValidator.isPresent()196 && context.getReferenceResolver().isResolvable(DEFAULT_JSON_PATH_MESSAGE_VALIDATOR)) {197 defaultJsonMessageValidator = Optional.of(context.getReferenceResolver().resolve(DEFAULT_JSON_PATH_MESSAGE_VALIDATOR, MessageValidator.class));198 }199 if (!defaultJsonMessageValidator.isPresent()) {200 // try to find json message validator via resource path lookup201 defaultJsonMessageValidator = MessageValidator.lookup("json-path");202 }203 if (defaultJsonMessageValidator.isPresent()) {204 return defaultJsonMessageValidator.get();205 }206 throw new CitrusRuntimeException("Unable to locate proper JSON path message validator - please add validator to project");207 }208 /**209 * Gets the kubernetes command to execute.210 * @return211 */212 public KubernetesCommand getCommand() {213 return command;214 }215 /**216 * Gets the kubernetes client.217 * @return218 */219 public KubernetesClient getKubernetesClient() {220 return kubernetesClient;221 }222 /**223 * Gets the expected control command result data.224 * @return225 */226 public String getCommandResult() {227 return commandResult;228 }229 /**230 * Gets the expected control command result expressions such as JsonPath expressions.231 * @return232 */233 public Map<String, Object> getCommandResultExpressions() {234 return commandResultExpressions;235 }236 /**237 * Action builder.238 */239 public static final class Builder extends AbstractTestActionBuilder<KubernetesExecuteAction, Builder> {240 private KubernetesClient kubernetesClient = new KubernetesClient();241 private KubernetesCommand command;242 private String commandResult;243 private Map<String, Object> commandResultExpressions = new HashMap<>();244 private MessageValidator<? extends ValidationContext> jsonMessageValidator;245 private MessageValidator<? extends ValidationContext> jsonPathMessageValidator;246 /**247 * Fluent API action building entry method used in Java DSL.248 * @return249 */250 public static Builder kubernetes() {251 return new Builder();252 }253 /**254 * Use a custom kubernetes client.255 */256 public Builder client(KubernetesClient kubernetesClient) {257 this.kubernetesClient = kubernetesClient;258 return this;259 }260 /**261 * Use a kubernetes command.262 */263 public Builder command(KubernetesCommand command) {264 this.command = command;265 return this;266 }267 /**268 * Adds expected command result.269 * @param result270 * @return271 */272 public Builder result(String result) {273 this.commandResult = result;274 return this;275 }276 /**277 * Adds JsonPath command result validation.278 * @param path279 * @param value280 * @return281 */282 public Builder validate(String path, Object value) {283 this.commandResultExpressions.put(path, value);284 return this;285 }286 public Builder validator(MessageValidator<? extends ValidationContext> validator) {287 this.jsonMessageValidator = validator;288 return this;289 }290 public Builder pathExpressionValidator(MessageValidator<? extends ValidationContext> validator) {291 this.jsonPathMessageValidator = validator;292 return this;293 }294 /**295 * Use a info command.296 */297 public BaseActionBuilder<InfoResult, ?> info() {298 return new BaseActionBuilder<>(new Info());299 }300 /**301 * Pods action builder.302 */303 public PodsActionBuilder pods() {304 return new PodsActionBuilder();305 }306 /**307 * Services action builder.308 */309 public ServicesActionBuilder services() {310 return new ServicesActionBuilder();311 }312 /**313 * ReplicationControllers action builder.314 */315 public ReplicationControllersActionBuilder replicationControllers() {316 return new ReplicationControllersActionBuilder();317 }318 /**319 * Endpoints action builder.320 */321 public EndpointsActionBuilder endpoints() {322 return new EndpointsActionBuilder();323 }324 /**325 * Nodes action builder.326 */327 public NodesActionBuilder nodes() {328 return new NodesActionBuilder();329 }330 /**331 * Events action builder.332 */333 public EventsActionBuilder events() {334 return new EventsActionBuilder();335 }336 /**337 * Namespaces action builder.338 */339 public NamespacesActionBuilder namespaces() {340 return new NamespacesActionBuilder();341 }342 /**343 * Base kubernetes action builder with namespace.344 */345 public class NamespacedActionBuilder<R extends KubernetesResource> extends BaseActionBuilder<R, NamespacedActionBuilder<R>> {346 /**347 * Constructor using command.348 * @param command349 */350 NamespacedActionBuilder(KubernetesCommand command) {351 super(command);352 }353 /**354 * Sets the namespace parameter.355 * @param key356 * @return357 */358 public NamespacedActionBuilder<R> namespace(String key) {359 command.namespace(key);360 return this;361 }362 }363 /**364 * Base kubernetes action builder with name option.365 */366 public class NamedActionBuilder<R extends KubernetesResource> extends BaseActionBuilder<R, NamedActionBuilder<R>> {367 /**368 * Constructor using command.369 * @param command370 */371 NamedActionBuilder(KubernetesCommand command) {372 super(command);373 }374 /**375 * Sets the name parameter.376 * @param key377 * @return378 */379 public NamedActionBuilder<R> name(String key) {380 command.name(key);381 return this;382 }383 /**384 * Sets the namespace parameter.385 * @param key386 * @return387 */388 public NamedActionBuilder<R> namespace(String key) {389 command.namespace(key);390 return this;391 }392 }393 /**394 * Base kubernetes action builder.395 */396 public class BaseActionBuilder<R extends KubernetesResource, B extends BaseActionBuilder<R, B>> extends AbstractTestActionBuilder<KubernetesExecuteAction, B> {397 /** Kubernetes command */398 protected final KubernetesCommand command;399 /**400 * Constructor using command.401 * @param command402 */403 BaseActionBuilder(KubernetesCommand command) {404 this.command = command;405 command(command);406 }407 /**408 * Adds expected command result.409 * @param result410 * @return411 */412 public B result(String result) {413 commandResult = result;414 return self;415 }416 /**417 * Adds JsonPath command result validation.418 * @param path419 * @param value420 * @return421 */422 public B validate(String path, Object value) {423 commandResultExpressions.put(path, value);424 return self;425 }426 /**427 * Adds command result callback.428 * @param callback429 * @return430 */431 public B validate(CommandResultCallback<R> callback) {432 command.validate(callback);433 return self;434 }435 /**436 * Sets the label parameter.437 * @param key438 * @param value439 * @return440 */441 public B label(String key, String value) {442 command.label(key, value);443 return self;444 }445 /**446 * Sets the label parameter.447 * @param key448 * @return449 */450 public B label(String key) {451 command.label(key);452 return self;453 }454 /**455 * Sets the without label parameter.456 * @param key457 * @param value458 * @return459 */460 public B withoutLabel(String key, String value) {461 command.withoutLabel(key, value);462 return self;463 }464 /**465 * Sets the without label parameter.466 * @param key467 * @return468 */469 public B withoutLabel(String key) {470 command.withoutLabel(key);471 return self;472 }473 /**474 * Sets command.475 * @param command476 * @return477 */478 protected B command(KubernetesCommand command) {479 Builder.this.command(command);480 return self;481 }482 @Override483 public KubernetesExecuteAction build() {484 return Builder.this.build();485 }486 }487 /**488 * Pods action builder.489 */490 public class PodsActionBuilder {491 /**492 * List pods.493 */494 public NamespacedActionBuilder<PodList> list() {495 ListPods command = new ListPods();496 return new NamespacedActionBuilder<>(command);497 }498 /**499 * Creates new pod.500 * @param pod501 */502 public NamedActionBuilder<Pod> create(Pod pod) {503 CreatePod command = new CreatePod();504 command.setPod(pod);505 return new NamedActionBuilder<>(command);506 }507 /**508 * Create new pod from template.509 * @param template510 */511 public NamedActionBuilder<Pod> create(Resource template) {512 CreatePod command = new CreatePod();513 command.setTemplateResource(template);514 return new NamedActionBuilder<>(command);515 }516 /**517 * Create new pod from template path.518 * @param templatePath519 */520 public NamedActionBuilder<Pod> create(String templatePath) {521 CreatePod command = new CreatePod();522 command.setTemplate(templatePath);523 return new NamedActionBuilder<>(command);524 }525 /**526 * Gets pod by name.527 * @param name528 */529 public NamedActionBuilder<Pod> get(String name) {530 GetPod command = new GetPod();531 command.name(name);532 return new NamedActionBuilder<>(command);533 }534 /**535 * Deletes pod by name.536 * @param name537 */538 public NamedActionBuilder<DeleteResult> delete(String name) {539 DeletePod command = new DeletePod();540 command.name(name);541 return new NamedActionBuilder<>(command);542 }543 /**544 * Watch pods.545 */546 public NamedActionBuilder<Pod> watch() {547 return new NamedActionBuilder<>(new WatchPods());548 }549 }550 /**551 * Services action builder.552 */553 public class ServicesActionBuilder {554 /**555 * List services.556 */557 public NamespacedActionBuilder<ServiceList> list() {558 return new NamespacedActionBuilder<>(new ListServices());559 }560 /**561 * Creates new service.562 * @param pod563 */564 public NamedActionBuilder<Service> create(Service pod) {565 CreateService command = new CreateService();566 command.setService(pod);567 return new NamedActionBuilder<>(command);568 }569 /**570 * Create new service from template.571 * @param template572 */573 public NamedActionBuilder<Service> create(Resource template) {574 CreateService command = new CreateService();575 command.setTemplateResource(template);576 return new NamedActionBuilder<>(command);577 }578 /**579 * Create new service from template path.580 * @param templatePath581 */582 public NamedActionBuilder<Service> create(String templatePath) {583 CreateService command = new CreateService();584 command.setTemplate(templatePath);585 return new NamedActionBuilder<>(command);586 }587 /**588 * Gets service by name.589 * @param name590 */591 public NamedActionBuilder<Service> get(String name) {592 GetService command = new GetService();593 command.name(name);594 return new NamedActionBuilder<>(command);595 }596 /**597 * Deletes service by name.598 * @param name599 */600 public NamedActionBuilder<DeleteResult> delete(String name) {601 DeleteService command = new DeleteService();602 command.name(name);603 return new NamedActionBuilder<>(command);604 }605 /**606 * Watch services.607 */608 public NamedActionBuilder<Service> watch() {609 return new NamedActionBuilder<>(new WatchServices());610 }611 }612 /**613 * Endpoints action builder.614 */615 public class EndpointsActionBuilder {616 /**617 * List endpoints.618 */619 public NamespacedActionBuilder<EndpointsList> list() {620 return new NamespacedActionBuilder<>(new ListEndpoints());621 }622 }623 /**624 * Nodes action builder.625 */626 public class NodesActionBuilder {627 /**628 * List nodes.629 */630 public BaseActionBuilder<NodeList, ?> list() {631 return new BaseActionBuilder<>(new ListNodes());632 }633 /**634 * Watch nodes.635 */636 public BaseActionBuilder<Node, ?> watch() {637 return new BaseActionBuilder<>(new WatchNodes());638 }639 }640 /**641 * Namespaces action builder.642 */643 public class NamespacesActionBuilder {644 /**645 * List namespaces.646 */647 public BaseActionBuilder<NamespaceList, ?> list() {648 return new BaseActionBuilder<>(new ListNamespaces());649 }650 /**651 * Watch namespaces.652 */653 public BaseActionBuilder<Namespace, ?> watch() {654 return new BaseActionBuilder<>(new WatchNamespaces());655 }656 }657 /**658 * Events action builder.659 */660 public class EventsActionBuilder {661 /**662 * List endpoints.663 */664 public NamespacedActionBuilder<EventList> list() {665 return new NamespacedActionBuilder<>(new ListEvents());666 }667 }668 /**669 * ReplicationControllers action builder.670 */671 public class ReplicationControllersActionBuilder {672 /**673 * List replication controllers.674 */675 public NamespacedActionBuilder<ReplicationControllerList> list() {676 return new NamespacedActionBuilder<>(new ListReplicationControllers());677 }678 /**679 * Watch pods.680 */681 public NamespacedActionBuilder<ReplicationController> watch() {682 return new NamespacedActionBuilder<>(new WatchReplicationControllers());683 }684 }685 @Override686 public KubernetesExecuteAction build() {687 return new KubernetesExecuteAction(this);688 }689 }690}...

Full Screen

Full Screen

Source:KubernetesActionBuilder.java Github

copy

Full Screen

1/*2 * Copyright 2006-2016 the original author or authors.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.consol.citrus.dsl.builder;17import com.consol.citrus.kubernetes.actions.KubernetesExecuteAction;18import com.consol.citrus.kubernetes.client.KubernetesClient;19import com.consol.citrus.kubernetes.command.*;20import io.fabric8.kubernetes.api.model.*;21import org.springframework.core.io.Resource;22/**23 * Action executes kubernetes commands.24 * 25 * @author Christoph Deppisch26 * @since 2.727 */28public class KubernetesActionBuilder extends AbstractTestActionBuilder<KubernetesExecuteAction> {29 /**30 * Constructor using action field.31 * @param action32 */33 public KubernetesActionBuilder(KubernetesExecuteAction action) {34 super(action);35 }36 /**37 * Default constructor.38 */39 public KubernetesActionBuilder() {40 super(new KubernetesExecuteAction());41 }42 /**43 * Use a custom kubernetes client.44 */45 public KubernetesActionBuilder client(KubernetesClient kubernetesClient) {46 action.setKubernetesClient(kubernetesClient);47 return this;48 }49 /**50 * Use a kubernetes command.51 */52 public <T extends KubernetesCommand> T command(T command) {53 action.setCommand(command);54 return command;55 }56 /**57 * Use a info command.58 */59 public BaseActionBuilder<BaseActionBuilder, InfoResult> info() {60 return new BaseActionBuilder<>(new Info());61 }62 /**63 * Pods action builder.64 */65 public PodsActionBuilder pods() {66 return new PodsActionBuilder();67 }68 /**69 * Services action builder.70 */71 public ServicesActionBuilder services() {72 return new ServicesActionBuilder();73 }74 /**75 * ReplicationControllers action builder.76 */77 public ReplicationControllersActionBuilder replicationControllers() {78 return new ReplicationControllersActionBuilder();79 }80 /**81 * Endpoints action builder.82 */83 public EndpointsActionBuilder endpoints() {84 return new EndpointsActionBuilder();85 }86 /**87 * Nodes action builder.88 */89 public NodesActionBuilder nodes() {90 return new NodesActionBuilder();91 }92 /**93 * Events action builder.94 */95 public EventsActionBuilder events() {96 return new EventsActionBuilder();97 }98 /**99 * Namespaces action builder.100 */101 public NamespacesActionBuilder namespaces() {102 return new NamespacesActionBuilder();103 }104 /**105 * Base kubernetes action builder with namespace.106 */107 public class NamespacedActionBuilder<R extends KubernetesResource> extends BaseActionBuilder<NamespacedActionBuilder<R>, R> {108 /**109 * Constructor using command.110 * @param command111 */112 NamespacedActionBuilder(KubernetesCommand<R> command) {113 super(command);114 }115 /**116 * Sets the namespace parameter.117 * @param key118 * @return119 */120 public NamespacedActionBuilder<R> namespace(String key) {121 command.namespace(key);122 return this;123 }124 }125 /**126 * Base kubernetes action builder with name option.127 */128 public class NamedActionBuilder<R extends KubernetesResource> extends BaseActionBuilder<NamedActionBuilder<R>, R> {129 /**130 * Constructor using command.131 * @param command132 */133 NamedActionBuilder(KubernetesCommand<R> command) {134 super(command);135 }136 /**137 * Sets the name parameter.138 * @param key139 * @return140 */141 public NamedActionBuilder<R> name(String key) {142 command.name(key);143 return this;144 }145 /**146 * Sets the namespace parameter.147 * @param key148 * @return149 */150 public NamedActionBuilder<R> namespace(String key) {151 command.namespace(key);152 return this;153 }154 }155 /**156 * Base kubernetes action builder.157 */158 public class BaseActionBuilder<T extends BaseActionBuilder, R extends KubernetesResource> extends AbstractTestActionBuilder<KubernetesExecuteAction> {159 /** Kubernetes command */160 protected final KubernetesCommand<R> command;161 /** Self reference for fluent API */162 protected T self;163 /**164 * Constructor using command.165 * @param command166 */167 BaseActionBuilder(KubernetesCommand<R> command) {168 super(KubernetesActionBuilder.this.action);169 self = (T) this;170 this.command = command;171 command(command);172 }173 /**174 * Adds expected command result.175 * @param result176 * @return177 */178 public T result(String result) {179 action.setCommandResult(result);180 return self;181 }182 /**183 * Adds JsonPath command result validation.184 * @param path185 * @param value186 * @return187 */188 public T validate(String path, Object value) {189 action.getCommandResultExpressions().put(path, value);190 return self;191 }192 /**193 * Adds command result callback.194 * @param callback195 * @return196 */197 public T validate(CommandResultCallback<R> callback) {198 command.validate(callback);199 return self;200 }201 /**202 * Sets the label parameter.203 * @param key204 * @param value205 * @return206 */207 public T label(String key, String value) {208 command.label(key, value);209 return self;210 }211 /**212 * Sets the label parameter.213 * @param key214 * @return215 */216 public T label(String key) {217 command.label(key);218 return self;219 }220 /**221 * Sets the without label parameter.222 * @param key223 * @param value224 * @return225 */226 public T withoutLabel(String key, String value) {227 command.withoutLabel(key, value);228 return self;229 }230 /**231 * Sets the without label parameter.232 * @param key233 * @return234 */235 public T withoutLabel(String key) {236 command.withoutLabel(key);237 return self;238 }239 /**240 * Sets command.241 * @param command242 * @return243 */244 protected T command(KubernetesCommand<R> command) {245 KubernetesActionBuilder.this.command(command);246 return self;247 }248 }249 /**250 * Pods action builder.251 */252 public class PodsActionBuilder {253 /**254 * List pods.255 */256 public NamespacedActionBuilder<PodList> list() {257 ListPods command = new ListPods();258 return new NamespacedActionBuilder<>(command);259 }260 /**261 * Creates new pod.262 * @param pod263 */264 public NamedActionBuilder<Pod> create(Pod pod) {265 CreatePod command = new CreatePod();266 command.setPod(pod);267 return new NamedActionBuilder<>(command);268 }269 /**270 * Create new pod from template.271 * @param template272 */273 public NamedActionBuilder<Pod> create(Resource template) {274 CreatePod command = new CreatePod();275 command.setTemplateResource(template);276 return new NamedActionBuilder<>(command);277 }278 /**279 * Create new pod from template path.280 * @param templatePath281 */282 public NamedActionBuilder<Pod> create(String templatePath) {283 CreatePod command = new CreatePod();284 command.setTemplate(templatePath);285 return new NamedActionBuilder<>(command);286 }287 /**288 * Gets pod by name.289 * @param name290 */291 public NamedActionBuilder<Pod> get(String name) {292 GetPod command = new GetPod();293 command.name(name);294 return new NamedActionBuilder<>(command);295 }296 /**297 * Deletes pod by name.298 * @param name299 */300 public NamedActionBuilder<DeleteResult> delete(String name) {301 DeletePod command = new DeletePod();302 command.name(name);303 return new NamedActionBuilder<>(command);304 }305 /**306 * Watch pods.307 */308 public NamedActionBuilder<Pod> watch() {309 return new NamedActionBuilder<>(new WatchPods());310 }311 }312 /**313 * Services action builder.314 */315 public class ServicesActionBuilder {316 /**317 * List services.318 */319 public NamespacedActionBuilder<ServiceList> list() {320 return new NamespacedActionBuilder<>(new ListServices());321 }322 /**323 * Creates new service.324 * @param pod325 */326 public NamedActionBuilder<Service> create(Service pod) {327 CreateService command = new CreateService();328 command.setService(pod);329 return new NamedActionBuilder<>(command);330 }331 /**332 * Create new service from template.333 * @param template334 */335 public NamedActionBuilder<Service> create(Resource template) {336 CreateService command = new CreateService();337 command.setTemplateResource(template);338 return new NamedActionBuilder<>(command);339 }340 /**341 * Create new service from template path.342 * @param templatePath343 */344 public NamedActionBuilder<Service> create(String templatePath) {345 CreateService command = new CreateService();346 command.setTemplate(templatePath);347 return new NamedActionBuilder<>(command);348 }349 /**350 * Gets service by name.351 * @param name352 */353 public NamedActionBuilder<Service> get(String name) {354 GetService command = new GetService();355 command.name(name);356 return new NamedActionBuilder<>(command);357 }358 /**359 * Deletes service by name.360 * @param name361 */362 public NamedActionBuilder<DeleteResult> delete(String name) {363 DeleteService command = new DeleteService();364 command.name(name);365 return new NamedActionBuilder<>(command);366 }367 /**368 * Watch services.369 */370 public NamedActionBuilder<Service> watch() {371 return new NamedActionBuilder<>(new WatchServices());372 }373 }374 /**375 * Endpoints action builder.376 */377 public class EndpointsActionBuilder {378 /**379 * List endpoints.380 */381 public NamespacedActionBuilder<EndpointsList> list() {382 return new NamespacedActionBuilder<>(new ListEndpoints());383 }384 }385 /**386 * Nodes action builder.387 */388 public class NodesActionBuilder {389 /**390 * List nodes.391 */392 public BaseActionBuilder<BaseActionBuilder, NodeList> list() {393 return new BaseActionBuilder<>(new ListNodes());394 }395 /**396 * Watch nodes.397 */398 public BaseActionBuilder<BaseActionBuilder, Node> watch() {399 return new BaseActionBuilder<>(new WatchNodes());400 }401 }402 /**403 * Namespaces action builder.404 */405 public class NamespacesActionBuilder {406 /**407 * List namespaces.408 */409 public BaseActionBuilder<BaseActionBuilder, NamespaceList> list() {410 return new BaseActionBuilder<>(new ListNamespaces());411 }412 /**413 * Watch namespaces.414 */415 public BaseActionBuilder<BaseActionBuilder, Namespace> watch() {416 return new BaseActionBuilder<>(new WatchNamespaces());417 }418 }419 /**420 * Events action builder.421 */422 public class EventsActionBuilder {423 /**424 * List endpoints.425 */426 public NamespacedActionBuilder<EventList> list() {427 return new NamespacedActionBuilder<>(new ListEvents());428 }429 }430 /**431 * ReplicationControllers action builder.432 */433 public class ReplicationControllersActionBuilder {434 /**435 * List replication controllers.436 */437 public NamespacedActionBuilder<ReplicationControllerList> list() {438 return new NamespacedActionBuilder<>(new ListReplicationControllers());439 }440 /**441 * Watch pods.442 */443 public NamespacedActionBuilder<ReplicationController> watch() {444 return new NamespacedActionBuilder<>(new WatchReplicationControllers());445 }446 }447}...

Full Screen

Full Screen

Source:CreateService.java Github

copy

Full Screen

...159 * Gets the service.160 *161 * @return162 */163 public Service getService() {164 return getResource();165 }166 /**167 * Sets the service.168 *169 * @param service170 */171 public CreateService setService(Service service) {172 setResource(service);173 return this;174 }175}...

Full Screen

Full Screen

getService

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.kubernetes;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;4import com.consol.citrus.kubernetes.command.CreateService;5import com.consol.citrus.kubernetes.command.GetPod;6import com.consol.citrus.kubernetes.command.GetService;7import com.consol.citrus.kubernetes.settings.KubernetesSettings;8import io.fabric8.kubernetes.api.model.Service;9import io.fabric8.kubernetes.api.model.ServicePort;10import io.fabric8.kubernetes.api.model.ServiceSpec;11import org.springframework.beans.factory.annotation.Autowired;12import org.springframework.core.io.ClassPathResource;13import org.testng.annotations.Test;14import java.util.ArrayList;15import java.util.List;16public class GetServiceTest extends TestNGCitrusTestDesigner {17 private KubernetesSettings kubernetesSettings;18 public void getServiceTest() {19 Service service = new Service();20 service.setApiVersion("v1");21 service.setKind("Service");22 service.setMetadata(kubernetesSettings.getMetadataBuilder().withName("test-service").build());23 ServiceSpec serviceSpec = new ServiceSpec();24 serviceSpec.setType("ClusterIP");25 List<ServicePort> ports = new ArrayList<>();26 ports.add(new ServicePort("http", 80, 80, "TCP"));27 serviceSpec.setPorts(ports);28 serviceSpec.setSelector(kubernetesSettings.getMetadataBuilder().withName("test-pod").build());29 service.setSpec(serviceSpec);30 CreateService createService = new CreateService.Builder()31 .withService(service)32 .build();33 create(createService);34 GetService getService = new GetService.Builder()35 .withServiceName("test-service")36 .build();37 get(getService);38 echo("Validating response");39 validateScript(new ClassPathResource("validate-get-service-response.js"));40 }41}42package com.consol.citrus.kubernetes;43import com.consol.citrus.annotations.CitrusTest;44import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;45import com.consol.citrus.kubernetes.command.CreateService;46import com

Full Screen

Full Screen

getService

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.kubernetes.command.CreateService;2import com.consol.citrus.kubernetes.command.GetService;3import com.consol.citrus.kubernetes.client.KubernetesClient;4import com.consol.citrus.kubernetes.command.Result;5import java.io.IOException;6import java.util.HashMap;7import java.util.Map;8public class 3 {9 public static void main(String[] args) throws IOException {10 CreateService createService = new CreateService();11 createService.setServiceName("hello-world");12 createService.setServiceType("NodePort");13 createService.setPort(80);14 Map<String, String> labels = new HashMap<>();15 labels.put("app", "hello-world");16 labels.put("version", "v1");17 createService.setLabels(labels);18 Result createServiceResult = kubernetesClient.execute(createService);19 GetService getService = new GetService();20 getService.setServiceName("hello-world");21 Result getServiceResult = kubernetesClient.execute(getService);22 System.out.println(getServiceResult.getOutput());23 }24}25import com.consol.citrus.kubernetes.command.CreateService;26import com.consol.citrus.kubernetes.command.UpdateService;27import com.consol.citrus.kubernetes.client.KubernetesClient;28import com.consol.citrus.kubernetes.command.Result;29import java.io.IOException;30import java.util.HashMap;31import java.util.Map;32public class 4 {33 public static void main(String[] args) throws IOException {34 CreateService createService = new CreateService();35 createService.setServiceName("hello-world");36 createService.setServiceType("NodePort");37 createService.setPort(80);38 Map<String, String> labels = new HashMap<>();39 labels.put("app", "hello-world");40 labels.put("version", "v1");41 createService.setLabels(labels);

Full Screen

Full Screen

getService

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.kubernetes.command.CreateService;2import com.consol.citrus.kubernetes.command.GetService;3import com.consol.citrus.kubernetes.command.GetServices;4import com.consol.citrus.kubernetes.command.GetServiceStatus;5import com.consol.citrus.kubernetes.command.DeleteService;6import io.fabric8.kubernetes.api.model.Service;7import io.fabric8.kubernetes.api.model.ServiceList;8import io.fabric8.kubernetes.api.model.ServiceStatus;9import io.fabric8.kubernetes.client.KubernetesClient;10import io.fabric8.kubernetes.client.server.mock.KubernetesServer;11import org.testng.annotations.BeforeClass;12import org.testng.annotations.Test;13import java.util.HashMap;14import java.util.Map;15import static org.testng.Assert.assertEquals;16import static org.testng.Assert.assertNotNull;17public class GetServiceIT {18 private KubernetesServer kubernetesServer;19 public void setup() {20 kubernetesServer = new KubernetesServer(true, true);21 kubernetesServer.before();22 }23 public void testGetService() {24 KubernetesClient kubernetesClient = kubernetesServer.getClient();25 Map<String, String> labels = new HashMap<>();26 labels.put("app", "test");27 Service service = new CreateService.Builder()28 .kubernetesClient(kubernetesClient)29 .name("test-service")30 .namespace("test-namespace")31 .labels(labels)32 .build()33 .getService();34 assertNotNull(service);35 Service service1 = new GetService.Builder()36 .kubernetesClient(kubernetesClient)37 .name("test-service")38 .namespace("test-namespace")39 .build()40 .getService();41 assertNotNull(service1);42 assertEquals(service1.getMetadata().getName(), "test-service");43 assertEquals(service1.getMetadata().getNamespace(), "test-namespace");44 assertEquals(service1.getMetadata().getLabels().get("app"), "test");45 ServiceStatus serviceStatus = new GetServiceStatus.Builder()46 .kubernetesClient(kubernetesClient)47 .name("test-service")48 .namespace("test-namespace")49 .build()50 .getServiceStatus();51 assertNotNull(serviceStatus);52 assertEquals(serviceStatus.getMetadata().getName(), "test-service");53 assertEquals(serviceStatus.getMetadata().getNamespace(), "test-namespace");54 assertEquals(serviceStatus.getMetadata().getLabels().get("app"), "test");

Full Screen

Full Screen

getService

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.kubernetes.command.GetServices;2import com.consol.citrus.kubernetes.command.GetServicesCommand;3import com.consol.citrus.kubernetes.command.GetServicesResult;4import com.consol.citrus.kubernetes.client.KubernetesClient;5import com.consol.citrus.kubernetes.message.KubernetesMessageHeaders;6import io.fabric8.kubernetes.api.model.Service;7import io.fabric8.kubernetes.api.model.ServiceList;8import com.consol.citrus.kubernetes.command.GetServicesResult;9import com.consol.citrus.kubernetes.client.KubernetesClient;10import com.consol.citrus.kubernetes.message.KubernetesMessageHeaders;11import io.fabric8.kubernetes.api.model.Service;12import io.fabric8.kubernetes.api.model.ServiceList;13import org.springframework.beans.factory.annotation.Autowired;14import org.springframework.http.HttpMethod;15import org.springframework.web.client.RestTemplate;16import org.testng.annotations.Test;17import org.testng.Assert;18import java.util.Map;19import java.util.List;20public class TestKubernetes {21 private KubernetesClient kubernetesClient;22 public void testCreateService() {23 Service service = new Service();24 service.setApiVersion("v1");25 service.setKind("Service");26 service.getMetadata().setName("my-service");27 service.getSpec().setSelector("app");28 service.getSpec().setType("LoadBalancer");29 service.getSpec().getPorts().get(0).setPort(80);30 service.getSpec().getPorts().get(0).setTargetPort(9376);31 service.getSpec().getPorts().get(0).setProtocol("TCP");32 GetServices getServices = new GetServices();33 getServices.setService(service);34 GetServicesResult getServicesResult = kubernetesClient.execute(getServices);35 ServiceList serviceList = getServicesResult.getServices();36 Assert.assertEquals(serviceList.getMetadata().getName(), "my-service");37 Assert.assertEquals(serviceList.getSpec().getSelector().get("app"), "my-service");38 Assert.assertEquals(serviceList.getSpec().getType(), "LoadBalancer");39 Assert.assertEquals(serviceList.getSpec().getPorts().get(0).getPort(), 80);40 Assert.assertEquals(serviceList.getSpec().getPorts().get(0).getTargetPort(), 9376);41 Assert.assertEquals(serviceList.getSpec().getPorts().get(0).getProtocol(), "TCP");42 }43}

Full Screen

Full Screen

getService

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.kubernetes.command;2import com.consol.citrus.kubernetes.client.KubernetesClient;3import com.consol.citrus.kubernetes.message.KubernetesMessageHeaders;4import io.fabric8.kubernetes.api.model.Service;5import io.fabric8.kubernetes.client.KubernetesClientException;6import org.slf4j.Logger;7import org.slf4j.LoggerFactory;8import org.springframework.util.StringUtils;9import org.springframework.ws.soap.SoapHeader;10import org.springframework.ws.soap.SoapHeaderElement;11import org.springframework.ws.soap.SoapMessage;12import org.springframework.ws.soap.SoapMessageFactory;13import org.springframework.ws.soap.SoapVersion;14import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;15import org.springframework.ws.soap.saaj.SaajSoapMessageUtils;16import org.springframework.ws.soap.server.endpoint.SoapFaultDefinition;17import org.springframework.ws.soap.server.endpoint.SoapFaultDefinitionEditor;18import org.springframework.ws.soap.server.endpoint.annotation.FaultCode;19import org.springframework.ws.soap.server.endpoint.annotation.FaultCodeResolver;20import org.springframework.ws.soap.server.endpoint.annotation.SoapAction;21import org.springframework.ws.soap.server.endpoint.annotation.SoapHeader;22import org.springframework.ws.soap.server.endpoint.annotation.SoapHeaderParam;23import org.springframework.ws.soap.server.endpoint.annotation.SoapHeaders;24import org.springframework.ws.soap.server.endpoint.annotation.SoapResponsePayload;25import org.springframework.ws.soap.server.endpoint.annotation.SoapResponsePayloads;26import org.springframework.ws.soap.server.endpoint.annotation.SoapVersionMapping;27import org.springframework.ws.soap.server.endpoint.annotation.SoapVersionMappings;

Full Screen

Full Screen

getService

Using AI Code Generation

copy

Full Screen

1public class 3 {2 public static void main(String[] args) {3 CreateService createService = new CreateService();4 createService.getService();5 }6}7public class 4 {8 public static void main(String[] args) {9 CreatePod createPod = new CreatePod();10 createPod.getPod();11 }12}13public class 5 {14 public static void main(String[] args) {15 CreateReplicationController createReplicationController = new CreateReplicationController();16 createReplicationController.getReplicationController();17 }18}19public class 6 {20 public static void main(String[] args) {21 CreateSecret createSecret = new CreateSecret();22 createSecret.getSecret();23 }24}25public class 7 {26 public static void main(String[] args) {27 CreateServiceAccount createServiceAccount = new CreateServiceAccount();28 createServiceAccount.getServiceAccount();29 }30}31public class 8 {32 public static void main(String[] args) {33 CreateStorageClass createStorageClass = new CreateStorageClass();34 createStorageClass.getStorageClass();35 }36}37public class 9 {38 public static void main(String[] args) {39 CreateVolume createVolume = new CreateVolume();40 createVolume.getVolume();41 }42}43public class 10 {44 public static void main(String[] args) {45 CreateVolumeAttachment createVolumeAttachment = new CreateVolumeAttachment();46 createVolumeAttachment.getVolumeAttachment();

Full Screen

Full Screen

getService

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.kubernetes;2import com.consol.citrus.kubernetes.command.CreateService;3import com.consol.citrus.kubernetes.command.GetPods;4import com.consol.citrus.kubernetes.command.GetServices;5import com.consol.citrus.kubernetes.command.KubernetesCommand;6import com.consol.citrus.kubernetes.command.KubernetesCommandResult;7import com.consol.citrus.kubernetes.command.RemoveService;8import com.consol.citrus.kubernetes.command.ResultType;9import com.consol.citrus.kubernetes.settings.KubernetesSettings;10import com.consol.citrus.kubernetes.settings.KubernetesSettingsBuilder;11import io.fabric8.kubernetes.api.model.Service;12import io.fabric8.kubernetes.client.KubernetesClient;13import io.fabric8.kubernetes.client.KubernetesClientException;14import io.fabric8.kubernetes.client.LocalPortForward;15import io.fabric8.kubernetes.client.utils.Utils;16import org.slf4j.Logger;17import org.slf4j.LoggerFactory;18import java.io.IOException;19import java.net.ServerSocket;20import java.util.ArrayList;21import java.util.List;22import java.util.Map;23public class KubernetesClientImpl implements KubernetesClient {24 private static final Logger LOG = LoggerFactory.getLogger(KubernetesClientImpl.class);25 private final KubernetesSettings settings;26 private final KubernetesCommandExecutor commandExecutor;27 private final io.fabric8.kubernetes.client.KubernetesClient kubernetesClient;28 private final Service service;29 private final List<LocalPortForward> localPortForwardList;30 public KubernetesClientImpl(KubernetesSettings settings) {31 this.settings = settings;32 this.commandExecutor = new KubernetesCommandExecutor(settings);33 this.kubernetesClient = null;34 this.service = null;35 this.localPortForwardList = new ArrayList<>();36 }37 public KubernetesClientImpl(KubernetesSettings settings, io.fabric8.kubernetes.client.KubernetesClient kubernetesClient) {38 this.settings = settings;39 this.commandExecutor = new KubernetesCommandExecutor(settings);

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Citrus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful