From 722b8aff5754998a7c2def0d7759a3205c97de84 Mon Sep 17 00:00:00 2001 From: Jeff Cantrill Date: Fri, 4 Sep 2015 21:18:40 -0400 Subject: [PATCH] [OSJC-220] Refactor property retrieval to make more maintainable --- .../internal/restclient/ResourceFactory.java | 2 +- .../internal/restclient/model/Build.java | 5 + .../restclient/model/BuildConfig.java | 29 ++- .../restclient/model/DeploymentConfig.java | 13 +- .../restclient/model/ImageStream.java | 2 + .../restclient/model/KubernetesResource.java | 26 +-- .../internal/restclient/model/List.java | 4 +- .../internal/restclient/model/Pod.java | 5 + .../internal/restclient/model/Project.java | 1 - .../model/ReplicationController.java | 6 + .../internal/restclient/model/Route.java | 12 ++ .../internal/restclient/model/Secret.java | 4 + .../internal/restclient/model/Service.java | 5 +- .../internal/restclient/model/Status.java | 5 + .../model/deploy/ImageChangeTrigger.java | 4 + .../project/OpenshiftProjectRequest.java | 3 + .../properties/BuildConfigPropertyKeys.java | 45 ---- .../DeploymentConfigPropertyKeys.java | 33 --- .../KubernetesApiModelProperties.java | 107 ---------- .../OpenShiftApiModelProperties.java | 193 ------------------ .../ResourcePropertiesRegistry.java | 103 +--------- .../properties/ResourcePropertyKeys.java | 77 +------ .../restclient/model/template/Template.java | 10 +- .../restclient/model/user/OpenShiftUser.java | 2 + .../model/volume/AbstractVolume.java | 3 +- .../model/volume/PersistentVolumeClaim.java | 4 + .../internal/util/JBossDmrExtentions.java | 42 ++-- .../resources/TemplateTraceabilityTest.java | 2 + ...rverTemplateProcessingIntegrationTest.java | 2 +- .../model/KubernetesResourceTest.java | 14 +- .../internal/restclient/model/RouteTest.java | 8 +- .../internal/restclient/model/StatusTest.java | 9 +- .../model/build/BuildConfigTest.java | 16 +- .../model/template/TemplateTest.java | 5 +- .../restclient/model/v1/BuildConfigTest.java | 9 +- .../model/v1/DeploymentConfigTest.java | 5 +- .../restclient/model/v1/TemplateTest.java | 4 +- .../model/v1beta3/BuildConfigTest.java | 4 +- .../model/v1beta3/DeploymentConfigTest.java | 4 +- .../restclient/model/v1beta3/PVCTest.java | 4 +- .../model/v1beta3/TemplateTest.java | 4 +- 41 files changed, 195 insertions(+), 640 deletions(-) delete mode 100644 src/main/java/com/openshift/internal/restclient/model/properties/BuildConfigPropertyKeys.java delete mode 100644 src/main/java/com/openshift/internal/restclient/model/properties/DeploymentConfigPropertyKeys.java delete mode 100644 src/main/java/com/openshift/internal/restclient/model/properties/KubernetesApiModelProperties.java delete mode 100644 src/main/java/com/openshift/internal/restclient/model/properties/OpenShiftApiModelProperties.java diff --git a/src/main/java/com/openshift/internal/restclient/ResourceFactory.java b/src/main/java/com/openshift/internal/restclient/ResourceFactory.java index d5c634f6..d49ae344 100644 --- a/src/main/java/com/openshift/internal/restclient/ResourceFactory.java +++ b/src/main/java/com/openshift/internal/restclient/ResourceFactory.java @@ -193,7 +193,7 @@ private IResource create(ModelNode node, String version, String kind, boolean st try { node.get(APIVERSION).set(version); node.get(KIND).set(kind.toString()); - Map properyKeyMap = ResourcePropertiesRegistry.getInstance().get(version, kind, strict); + Map properyKeyMap = ResourcePropertiesRegistry.getInstance().get(version, kind); if(IMPL_MAP.containsKey(kind)) { Constructor constructor = IMPL_MAP.get(kind).getConstructor(ModelNode.class, IClient.class, Map.class); return constructor.newInstance(node, client, properyKeyMap); diff --git a/src/main/java/com/openshift/internal/restclient/model/Build.java b/src/main/java/com/openshift/internal/restclient/model/Build.java index 2c9f70fb..834206f6 100644 --- a/src/main/java/com/openshift/internal/restclient/model/Build.java +++ b/src/main/java/com/openshift/internal/restclient/model/Build.java @@ -20,6 +20,11 @@ * @author Jeff Cantrill */ public class Build extends KubernetesResource implements IBuild{ + + private static final String BUILD_MESSAGE = "status.message"; + private static final String BUILD_PODNAME = "podName"; + private static final String BUILD_STATUS = "status.phase"; + public Build(ModelNode node, IClient client, Map propertyKeys) { super(node, client, propertyKeys); diff --git a/src/main/java/com/openshift/internal/restclient/model/BuildConfig.java b/src/main/java/com/openshift/internal/restclient/model/BuildConfig.java index 56ba5e4c..c9588d7e 100644 --- a/src/main/java/com/openshift/internal/restclient/model/BuildConfig.java +++ b/src/main/java/com/openshift/internal/restclient/model/BuildConfig.java @@ -15,7 +15,6 @@ import org.apache.commons.lang.StringUtils; import org.jboss.dmr.ModelNode; -import com.openshift.internal.restclient.OpenShiftAPIVersion; import com.openshift.internal.restclient.capability.CapabilityInitializer; import com.openshift.internal.restclient.model.build.CustomBuildStrategy; import com.openshift.internal.restclient.model.build.DockerBuildStrategy; @@ -44,9 +43,33 @@ * @author Jeff Cantrill */ public class BuildConfig extends KubernetesResource implements IBuildConfig { + + private static final String BUILDCONFIG_SOURCE_CONTEXTDIR = "spec.source.contextDir"; + private static final String BUILDCONFIG_SOURCE_TYPE = "spec.source.type"; + private static final String BUILDCONFIG_SOURCE_URI = "spec.source.git.uri"; + private static final String BUILDCONFIG_SOURCE_REF = "spec.source.git.ref"; + public static final String BUILDCONFIG_TYPE = "spec.strategy.type"; + private static final String BUILDCONFIG_CUSTOM_IMAGE = "spec.strategy.customStrategy.image"; + private static final String BUILDCONFIG_CUSTOM_EXPOSEDOCKERSOCKET = "spec.strategy.customStrategy.exposeDockerSocket"; + private static final String BUILDCONFIG_CUSTOM_ENV = "spec.strategy.customStrategy.env"; + public static final String BUILDCONFIG_DOCKER_CONTEXTDIR = "spec.strategy.dockerStrategy.contextDir"; + public static final String BUILDCONFIG_DOCKER_NOCACHE = "spec.strategy.dockerStrategy.noCache"; + public static final String BUILDCONFIG_DOCKER_BASEIMAGE = "spec.strategy.dockerStrategy.baseImage"; + private static final String BUILDCONFIG_OUTPUT_REPO = "spec.output.to.name"; + private static final String BUILDCONFIG_STI_IMAGE = "spec.strategy.sourceStrategy.from.name"; + private static final String BUILDCONFIG_STI_SCRIPTS = "spec.strategy.sourceStrategy.scripts"; + private static final String BUILDCONFIG_STI_INCREMENTAL = "spec.strategy.sourceStrategy.incremental"; + private static final String BUILDCONFIG_STI_ENV = "spec.strategy.sourceStrategy.env"; + private static final String BUILDCONFIG_TRIGGERS = "spec.triggers"; + private static final String BUILD_CONFIG_WEBHOOK_GITHUB_SECRET = "github.secret"; + private static final String BUILD_CONFIG_WEBHOOK_GENERIC_SECRET = "generic.secret"; + private static final String BUILD_CONFIG_IMAGECHANGE_IMAGE = "imageChange.image"; + private static final String BUILD_CONFIG_IMAGECHANGE_NAME = "imageChange.from.name"; + private static final String BUILD_CONFIG_IMAGECHANGE_TAG = "imageChange.tag"; + - public BuildConfig(ModelNode node, IClient client, Map propertyKeys) { - super(node, client, propertyKeys); + public BuildConfig(ModelNode node, IClient client, Map overrideProperties) { + super(node, client, null); CapabilityInitializer.initializeCapabilities(getModifiableCapabilities(), this, client); } diff --git a/src/main/java/com/openshift/internal/restclient/model/DeploymentConfig.java b/src/main/java/com/openshift/internal/restclient/model/DeploymentConfig.java index 05f520ab..60ed5a9e 100644 --- a/src/main/java/com/openshift/internal/restclient/model/DeploymentConfig.java +++ b/src/main/java/com/openshift/internal/restclient/model/DeploymentConfig.java @@ -24,7 +24,18 @@ */ public class DeploymentConfig extends KubernetesResource implements IDeploymentConfig{ + public static final String DEPLOYMENTCONFIG_CONTAINERS = "spec.template.spec.containers"; + private static final String VOLUMES = "spec.template.spec.volumes"; + private static final String DEPLOYMENTCONFIG_REPLICAS = "spec.replicas"; + private static final String DEPLOYMENTCONFIG_REPLICA_SELECTOR = "spec.selector"; + private static final String DEPLOYMENTCONFIG_TEMPLATE_LABELS = "spec.template.metadata.labels"; + private static final String DEPLOYMENTCONFIG_TRIGGERS = "spec.triggers"; + private static final String DEPLOYMENTCONFIG_STRATEGY = "spec.strategy.type"; + + private static final String IMAGE = "image"; + private static final String ENV = "env"; private static final String TYPE = "type"; + private final Map propertyKeys; public DeploymentConfig(ModelNode node, IClient client, Map propertyKeys) { @@ -103,7 +114,7 @@ public void addContainer(String name, DockerImageURI tag, Set containerPo if(emptyDirVolumes.size() > 0) { ModelNode volumeMounts = container.get("volumeMounts"); - ModelNode volumes = get(DEPLOYMENTCONFIG_VOLUMES); + ModelNode volumes = get(VOLUMES); for (String path : emptyDirVolumes) { EmptyDirVolume volume = new EmptyDirVolume(volumes.add()); final String volName = String.format("%s-%s", name, emptyDirVolumes.indexOf(path) + 1); diff --git a/src/main/java/com/openshift/internal/restclient/model/ImageStream.java b/src/main/java/com/openshift/internal/restclient/model/ImageStream.java index a39a354c..6676ff36 100644 --- a/src/main/java/com/openshift/internal/restclient/model/ImageStream.java +++ b/src/main/java/com/openshift/internal/restclient/model/ImageStream.java @@ -21,6 +21,8 @@ */ public class ImageStream extends KubernetesResource implements IImageStream { + private static final String IMAGESTREAM_DOCKER_IMAGE_REPO = "spec.dockerImageRepository"; + public ImageStream(){ this(new ModelNode(), null, null); } diff --git a/src/main/java/com/openshift/internal/restclient/model/KubernetesResource.java b/src/main/java/com/openshift/internal/restclient/model/KubernetesResource.java index f73b1597..2958f842 100644 --- a/src/main/java/com/openshift/internal/restclient/model/KubernetesResource.java +++ b/src/main/java/com/openshift/internal/restclient/model/KubernetesResource.java @@ -15,7 +15,6 @@ import java.util.Map; import java.util.Set; -import org.apache.commons.lang.StringUtils; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; @@ -41,10 +40,17 @@ public class KubernetesResource implements IResource, ResourcePropertyKeys { private Map propertyKeys; private IProject project; - public KubernetesResource(ModelNode node, IClient client, Map propertyKeys){ + /** + * + * @param node + * @param client + * @param overrideProperties the map of properties that override the defaults + */ + public KubernetesResource(ModelNode node, IClient client, Map overrideProperties){ + if(overrideProperties == null) overrideProperties = new HashMap(); this.node = node; this.client = client; - this.propertyKeys = propertyKeys; + this.propertyKeys = overrideProperties; initializeCapabilities(capabilities, this, client); } @@ -92,9 +98,7 @@ public Map getAnnotations() { @Override public String getAnnotation(String key) { - //TODO make efficient - Map annotations = getAnnotations(); - return annotations.get(key); + return getAnnotations().get(key); } @@ -144,11 +148,11 @@ public String getCreationTimeStamp(){ } @Override public String getName(){ - return asString(NAME); + return asString(METADATA_NAME); } public void setName(String name) { - set(NAME, name); + set(METADATA_NAME, name); } @Override @@ -233,11 +237,7 @@ protected void setEnvMap(String key, Map values) { } protected String[] getPath(String key) { - String [] property = propertyKeys.get(key); - if (property == null) { - throw new IllegalArgumentException(String.format("key %s is not known to the resource %s", key, getName().isEmpty()? getClass().getSimpleName() : getName())); - } - return property; + return JBossDmrExtentions.getPath(propertyKeys, key); } protected String asString(ModelNode node, String subKey) { diff --git a/src/main/java/com/openshift/internal/restclient/model/List.java b/src/main/java/com/openshift/internal/restclient/model/List.java index 69ede22a..6d4347f1 100644 --- a/src/main/java/com/openshift/internal/restclient/model/List.java +++ b/src/main/java/com/openshift/internal/restclient/model/List.java @@ -30,7 +30,7 @@ public List(ModelNode node, IClient client, Map propertyKeys) @Override public Collection getItems() { - Collection nodes = get(TEMPLATE_ITEMS).asList(); + Collection nodes = get(OBJECTS).asList(); java.util.List resources = new ArrayList(nodes.size()); IResourceFactory factory = getClient().getResourceFactory(); if(factory != null){ @@ -43,7 +43,7 @@ public Collection getItems() { @Override public void addAll(Collection items) { - ModelNode itemNode = get(TEMPLATE_ITEMS); + ModelNode itemNode = get(OBJECTS); for (IResource resource : items) { itemNode.add(ModelNode.fromJSONString(resource.toString())); } diff --git a/src/main/java/com/openshift/internal/restclient/model/Pod.java b/src/main/java/com/openshift/internal/restclient/model/Pod.java index d75a225a..8016cb48 100644 --- a/src/main/java/com/openshift/internal/restclient/model/Pod.java +++ b/src/main/java/com/openshift/internal/restclient/model/Pod.java @@ -29,6 +29,11 @@ */ public class Pod extends KubernetesResource implements IPod { + private static final String POD_IP = "status.podIP"; + private static final String POD_HOST = "status.hostIP"; + private static final String POD_STATUS = "status.phase"; + private static final String POD_CONTAINERS = "spec.containers"; + public Pod(ModelNode node, IClient client, Map propertyKeys) { super(node, client, propertyKeys); initializeCapabilities(getModifiableCapabilities(), this, client); diff --git a/src/main/java/com/openshift/internal/restclient/model/Project.java b/src/main/java/com/openshift/internal/restclient/model/Project.java index 65f5f117..7d28ae79 100644 --- a/src/main/java/com/openshift/internal/restclient/model/Project.java +++ b/src/main/java/com/openshift/internal/restclient/model/Project.java @@ -18,7 +18,6 @@ import org.jboss.dmr.ModelNode; import com.openshift.restclient.IClient; -import com.openshift.restclient.ResourceKind; import com.openshift.restclient.model.IProject; import com.openshift.restclient.model.IResource; diff --git a/src/main/java/com/openshift/internal/restclient/model/ReplicationController.java b/src/main/java/com/openshift/internal/restclient/model/ReplicationController.java index 789a25c2..9fd13643 100644 --- a/src/main/java/com/openshift/internal/restclient/model/ReplicationController.java +++ b/src/main/java/com/openshift/internal/restclient/model/ReplicationController.java @@ -23,6 +23,12 @@ */ public class ReplicationController extends KubernetesResource implements IReplicationController{ + private static final String REPLICATION_CONTROLLER_REPLICA_COUNT = "spec.replicas"; + private static final String REPLICATION_CONTROLLER_REPLICA_SELECTOR = "spec.selector"; + private static final String REPLICATION_CONTROLLER_CONTAINERS = "spec.template.spec.containers"; + private static final String REPLICATION_CONTROLLER_CURRENT_REPLICA_COUNT = "status.replicas"; + + public ReplicationController(ModelNode node, IClient client, Map propertyKeys) { super(node, client, propertyKeys); } diff --git a/src/main/java/com/openshift/internal/restclient/model/Route.java b/src/main/java/com/openshift/internal/restclient/model/Route.java index bae0a997..dac22780 100644 --- a/src/main/java/com/openshift/internal/restclient/model/Route.java +++ b/src/main/java/com/openshift/internal/restclient/model/Route.java @@ -21,6 +21,18 @@ * @author Jeff Cantrill */ public class Route extends KubernetesResource implements IRoute { + + private static final String ROUTE_HOST = "spec.host"; + private static final String ROUTE_PATH = "spec.path"; + private static final String ROUTE_KIND = "spec.to.kind"; + private static final String ROUTE_SERVICE_NAME = "spec.to.name"; + private static final String ROUTE_TLS = "spec.tls"; + private static final String ROUTE_TLS_TERMINATION_TYPE = "spec.tls.termination"; + private static final String ROUTE_TLS_CERTIFICATE = "spec.tls.certificate"; + private static final String ROUTE_TLS_KEY = "spec.tls.key"; + private static final String ROUTE_TLS_CACERT = "spec.tls.caCertificate"; + private static final String ROUTE_TLS_DESTINATION_CACERT = "spec.tls.destinationCACertificate"; + public Route(ModelNode node, IClient client, Map propertyKeys) { super(node, client, propertyKeys); diff --git a/src/main/java/com/openshift/internal/restclient/model/Secret.java b/src/main/java/com/openshift/internal/restclient/model/Secret.java index 63aad4c6..fb3a2c76 100644 --- a/src/main/java/com/openshift/internal/restclient/model/Secret.java +++ b/src/main/java/com/openshift/internal/restclient/model/Secret.java @@ -24,6 +24,10 @@ * @author Jiri Pechanec */ public class Secret extends KubernetesResource implements ISecret { + + private static final String SECRET_TYPE = "type"; + private static final String SECRET_DATA = "data"; + public Secret(ModelNode node, IClient client, Map propertyKeys) { super(node, client, propertyKeys); diff --git a/src/main/java/com/openshift/internal/restclient/model/Service.java b/src/main/java/com/openshift/internal/restclient/model/Service.java index bf1144e7..1973e161 100644 --- a/src/main/java/com/openshift/internal/restclient/model/Service.java +++ b/src/main/java/com/openshift/internal/restclient/model/Service.java @@ -31,6 +31,9 @@ public class Service extends KubernetesResource implements IService { + private static final String SERVICE_SELECTOR = "spec.selector"; + private static final String SERVICE_PORT = "spec.ports"; + public Service(ModelNode node, IClient client, Map propertyKeys) { super(node, client, propertyKeys); initializeCapabilities(getModifiableCapabilities(), this, getClient()); @@ -126,7 +129,7 @@ public int getTargetPort() { @Override public String getPortalIP() { - return asString(SERVICE_PORTALIP); + return asString("spec.portalIP"); } @Override diff --git a/src/main/java/com/openshift/internal/restclient/model/Status.java b/src/main/java/com/openshift/internal/restclient/model/Status.java index bd2ba257..15f0bf9e 100644 --- a/src/main/java/com/openshift/internal/restclient/model/Status.java +++ b/src/main/java/com/openshift/internal/restclient/model/Status.java @@ -19,6 +19,11 @@ * @author Jeff Cantrill */ public class Status extends KubernetesResource implements IStatus{ + + private static final String STATUS_MESSAGE = "message"; + private static final String STATUS_CODE = "code"; + private static final String STATUS_STATUS = "status"; + public Status(ModelNode node, IClient client, Map propertyKeys) { super(node, client, propertyKeys); diff --git a/src/main/java/com/openshift/internal/restclient/model/deploy/ImageChangeTrigger.java b/src/main/java/com/openshift/internal/restclient/model/deploy/ImageChangeTrigger.java index cd1a49b4..6a26ef4c 100644 --- a/src/main/java/com/openshift/internal/restclient/model/deploy/ImageChangeTrigger.java +++ b/src/main/java/com/openshift/internal/restclient/model/deploy/ImageChangeTrigger.java @@ -24,6 +24,10 @@ public class ImageChangeTrigger extends DeploymentTrigger implements IDeploymentImageChangeTrigger { + private static final String DEPLOYMENTCONFIG_TRIGGER_IMAGECHANGE_AUTO = "imageChangeParams.automatic"; + private static final String DEPLOYMENTCONFIG_TRIGGER_CONTAINERS = "imageChangeParams.containerNames"; + private static final String DEPLOYMENTCONFIG_TRIGGER_FROM = "imageChangeParams.from.name"; + private static final String DEPLOYMENTCONFIG_TRIGGER_FROM_KIND = "imageChangeParams.from.kind"; public ImageChangeTrigger(ModelNode node, Map propertyKeys) { super(node, propertyKeys); diff --git a/src/main/java/com/openshift/internal/restclient/model/project/OpenshiftProjectRequest.java b/src/main/java/com/openshift/internal/restclient/model/project/OpenshiftProjectRequest.java index 95ed310d..bb09814e 100644 --- a/src/main/java/com/openshift/internal/restclient/model/project/OpenshiftProjectRequest.java +++ b/src/main/java/com/openshift/internal/restclient/model/project/OpenshiftProjectRequest.java @@ -20,6 +20,9 @@ public class OpenshiftProjectRequest extends KubernetesResource implements IProjectRequest { + private static final String DISPLAYNAME = "displayName"; + private static final String DESCRIPTION = "description"; + public OpenshiftProjectRequest(ModelNode node, IClient client, Map propertyKeys) { super(node, client, propertyKeys); } diff --git a/src/main/java/com/openshift/internal/restclient/model/properties/BuildConfigPropertyKeys.java b/src/main/java/com/openshift/internal/restclient/model/properties/BuildConfigPropertyKeys.java deleted file mode 100644 index f8201add..00000000 --- a/src/main/java/com/openshift/internal/restclient/model/properties/BuildConfigPropertyKeys.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 Red Hat, Inc. Distributed under license by Red Hat, Inc. - * All rights reserved. This program is made available under the terms of the - * Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Red Hat, Inc. - ******************************************************************************/ -package com.openshift.internal.restclient.model.properties; - -/** - * @author Jeff Cantrill - */ -public interface BuildConfigPropertyKeys { - static final String BUILDCONFIG_SOURCE_CONTEXTDIR = "buildconfig.source.contextdir"; - static final String BUILDCONFIG_SOURCE_TYPE = "buildconfig.source.type"; - static final String BUILDCONFIG_SOURCE_REF = "buildconfig.source.ref"; - static final String BUILDCONFIG_SOURCE_URI = "buildconfig.sourceuri"; - static final String BUILDCONFIG_STRATEGY = "buildconfig.strategy"; - static final String BUILDCONFIG_TYPE = "buildconfig.strategy.type"; - - static final String BUILDCONFIG_CUSTOM_IMAGE = "buildconfig.custom.image"; - static final String BUILDCONFIG_CUSTOM_EXPOSEDOCKERSOCKET = "buildconfig.custom.exposesocket"; - static final String BUILDCONFIG_CUSTOM_ENV = "buildconfig.custom.env"; - - static final String BUILDCONFIG_DOCKER_CONTEXTDIR = "buildconfig.docker.context"; - static final String BUILDCONFIG_DOCKER_NOCACHE = "buildconfig.docker.nocache"; - static final String BUILDCONFIG_DOCKER_BASEIMAGE = "buildconfig.docker.baseimage"; - - static final String BUILDCONFIG_STI_IMAGE= "buildconfig.sti.image"; - static final String BUILDCONFIG_STI_SCRIPTS = "buildconfig.sti.scripts"; - static final String BUILDCONFIG_STI_CLEAN = "buildconfig.sti.clean"; - static final String BUILDCONFIG_STI_INCREMENTAL = "buildconfig.sti.incremental"; - static final String BUILDCONFIG_STI_ENV = "buildconfig.sti.env"; - - static final String BUILDCONFIG_OUTPUT_REPO = "buildconfig.outputrepo"; - - static final String BUILDCONFIG_TRIGGERS = "buildconfig.triggers"; - - static final String BUILD_CONFIG_WEBHOOK_GITHUB_SECRET = "buildconfig.webhook.github.secret"; - static final String BUILD_CONFIG_WEBHOOK_GENERIC_SECRET = "buildconfig.webhook.generic.secret"; - static final String BUILD_CONFIG_IMAGECHANGE_IMAGE = "buildconfig.imagechange.image"; - static final String BUILD_CONFIG_IMAGECHANGE_NAME = "buildconfig.imagechange.name"; - static final String BUILD_CONFIG_IMAGECHANGE_TAG = "buildconfig.imagechange.tag"; -} diff --git a/src/main/java/com/openshift/internal/restclient/model/properties/DeploymentConfigPropertyKeys.java b/src/main/java/com/openshift/internal/restclient/model/properties/DeploymentConfigPropertyKeys.java deleted file mode 100644 index c81f8149..00000000 --- a/src/main/java/com/openshift/internal/restclient/model/properties/DeploymentConfigPropertyKeys.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 Red Hat, Inc. - * Distributed under license by Red Hat, Inc. All rights reserved. - * This program is made available under the terms of the - * Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - ******************************************************************************/ -package com.openshift.internal.restclient.model.properties; - -/** - * Keys for deployment configs - * @author jeff.cantrill - * - */ -public interface DeploymentConfigPropertyKeys { - - static final String DEPLOYMENTCONFIG_CONTAINERS = "deploymentconfig.containers"; - static final String DEPLOYMENTCONFIG_REPLICAS = "deploymentconfig.replicas"; - static final String DEPLOYMENTCONFIG_REPLICA_SELECTOR = "deploymentconfig.replica.selector"; - static final String DEPLOYMENTCONFIG_TRIGGERS = "deploymentconfig.triggers"; - static final String DEPLOYMENTCONFIG_STRATEGY = "deploymentconfig.strategy"; - static final String DEPLOYMENTCONFIG_TEMPLATE_LABELS = "deploymentconfig.template.labels"; - static final String DEPLOYMENTCONFIG_VOLUMES = "deploymentconfig.volumes"; - - static final String DEPLOYMENTCONFIG_TRIGGER_CONTAINERS = "deploymentconfig.triggers.imagechange.containers"; - static final String DEPLOYMENTCONFIG_TRIGGER_IMAGECHANGE_AUTO = "deploymentconfig.triggers.imagechange.automatic"; - static final String DEPLOYMENTCONFIG_TRIGGER_FROM = "deploymentconfig.triggers.imagechange.from"; - static final String DEPLOYMENTCONFIG_TRIGGER_FROM_KIND = "deploymentconfig.triggers.imagechange.from.kind"; - -} diff --git a/src/main/java/com/openshift/internal/restclient/model/properties/KubernetesApiModelProperties.java b/src/main/java/com/openshift/internal/restclient/model/properties/KubernetesApiModelProperties.java deleted file mode 100644 index 39161fec..00000000 --- a/src/main/java/com/openshift/internal/restclient/model/properties/KubernetesApiModelProperties.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 Red Hat, Inc. - * Distributed under license by Red Hat, Inc. All rights reserved. - * This program is made available under the terms of the - * Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - ******************************************************************************/ -package com.openshift.internal.restclient.model.properties; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author jeff.cantrill - */ -public interface KubernetesApiModelProperties extends ResourcePropertyKeys{ - - @SuppressWarnings("serial") - static final Map V1_KUBERNETES_MAP = new HashMap(){{ - put(ANNOTATIONS, new String [] {"metadata", "annotations"}); - put(APIVERSION, new String [] {"apiVersion"}); - put(CREATION_TIMESTAMP, new String [] {"metadata","creationTimestamp"}); - put(KIND, new String[] { "kind" }); - put(LABELS, new String [] {"metadata","labels"}); - put(NAME , new String [] {"metadata","name"}); - put(NAMESPACE, new String [] {"metadata","namespace"}); - put(PORTS, new String [] {"ports"}); - - put(PORTS_CONTAINER_PORT, new String [] {"containerPort"}); - put(PORTS_PROTOCOL, new String [] {"protocol"}); - put(PORTS_NAME, new String [] {"name"}); - - - put(POD_IP, new String[]{"status","podIP"}); - put(POD_HOST, new String[]{"status","hostIP"}); - put(POD_STATUS, new String[]{"status","phase"}); - put(POD_CONTAINERS, new String[]{"spec","containers"}); - - put(PVC_ACCESS_MODES, new String[]{"spec","accessModes"}); - put(PVC_REQUESTED_STORAGE, new String[]{"spec","resources", "requests", "storage"}); - - put(REPLICATION_CONTROLLER_REPLICA_COUNT, new String [] {"spec", "replicas"}); - put(REPLICATION_CONTROLLER_REPLICA_SELECTOR, new String [] {"spec", "selector"}); - put(REPLICATION_CONTROLLER_CONTAINERS, new String [] {"spec", "template","spec","containers"}); - put(REPLICATION_CONTROLLER_CURRENT_REPLICA_COUNT, new String [] {"status", "replicas"}); - - put(SERVICE_CONTAINER_PORT, new String [] {"containerPort"}); - put(SERVICE_PORT, new String [] {"spec","ports"}); - put(SERVICE_SELECTOR, new String [] {"spec","selector"}); - put(SERVICE_PORTALIP, new String [] {"spec","portalIP"}); - put(STATUS_MESSAGE, new String [] {"message"}); - put(STATUS_CODE, new String [] {"code"}); - put(STATUS_STATUS, new String [] {"status"}); - - put(STATUS_MESSAGE, new String [] {"message"}); - put(STATUS_CODE, new String [] {"code"}); - put(STATUS_STATUS, new String [] {"status"}); - put(STATUS_PHASE, new String [] {"status", "phase"}); - }}; - - @SuppressWarnings("serial") - static final Map V1BETA3_KUBERNETES_MAP = new HashMap(){{ - put(ANNOTATIONS, new String [] {"metadata", "annotations"}); - put(APIVERSION, new String [] {"apiVersion"}); - put(CREATION_TIMESTAMP, new String [] {"metadata","creationTimestamp"}); - put(KIND, new String[] { "kind" }); - put(LABELS, new String [] {"metadata","labels"}); - put(NAME , new String [] {"metadata","name"}); - put(NAMESPACE, new String [] {"metadata","namespace"}); - put(PORTS, new String [] {"ports"}); - - put(PORTS_CONTAINER_PORT, new String [] {"containerPort"}); - put(PORTS_PROTOCOL, new String [] {"protocol"}); - put(PORTS_NAME, new String [] {"name"}); - - put(POD_IP, new String[]{"status","podIP"}); - put(POD_HOST, new String[]{"status","hostIP"}); - put(POD_STATUS, new String[]{"status","phase"}); - put(POD_CONTAINERS, new String[]{"spec","containers"}); - - put(PVC_ACCESS_MODES, new String[]{"spec","accessModes"}); - put(PVC_REQUESTED_STORAGE, new String[]{"spec","resources", "requests", "storage"}); - - put(REPLICATION_CONTROLLER_REPLICA_COUNT, new String [] {"spec", "replicas"}); - put(REPLICATION_CONTROLLER_REPLICA_SELECTOR, new String [] {"spec", "selector"}); - put(REPLICATION_CONTROLLER_CONTAINERS, new String [] {"spec", "template","spec","containers"}); - put(REPLICATION_CONTROLLER_CURRENT_REPLICA_COUNT, new String [] {"status", "replicas"}); - - put(SERVICE_CONTAINER_PORT, new String [] {"containerPort"}); - put(SERVICE_PORT, new String [] {"spec","ports"}); - put(SERVICE_SELECTOR, new String [] {"spec","selector"}); - put(SERVICE_PORTALIP, new String [] {"spec","portalIP"}); - put(STATUS_MESSAGE, new String [] {"message"}); - put(STATUS_CODE, new String [] {"code"}); - put(STATUS_STATUS, new String [] {"status"}); - - put(STATUS_MESSAGE, new String [] {"message"}); - put(STATUS_CODE, new String [] {"code"}); - put(STATUS_STATUS, new String [] {"status"}); - put(STATUS_PHASE, new String [] {"status", "phase"}); - - }}; - -} diff --git a/src/main/java/com/openshift/internal/restclient/model/properties/OpenShiftApiModelProperties.java b/src/main/java/com/openshift/internal/restclient/model/properties/OpenShiftApiModelProperties.java deleted file mode 100644 index 889d30bd..00000000 --- a/src/main/java/com/openshift/internal/restclient/model/properties/OpenShiftApiModelProperties.java +++ /dev/null @@ -1,193 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 Red Hat, Inc. - * Distributed under license by Red Hat, Inc. All rights reserved. - * This program is made available under the terms of the - * Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - ******************************************************************************/ -package com.openshift.internal.restclient.model.properties; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author jeff.cantrill - */ -public interface OpenShiftApiModelProperties extends ResourcePropertyKeys{ - - @SuppressWarnings("serial") - static final Map V1BETA3_OPENSHIFT_MAP = new HashMap(){{ - //common properties - put(ANNOTATIONS, new String [] {"metadata", "annotations"}); - put(APIVERSION, new String [] {"apiVersion"}); - put(CREATION_TIMESTAMP, new String [] {"metadata", "creationTimestamp"}); - put(DESCRIPTION, new String [] { "description"}); - put(IMAGE, new String [] { "image"}); - put(PORTS, new String [] { "ports"}); - put(ENV, new String [] { "env"}); - put(CONTAINER_PORT, new String [] { "containerPort"}); - put(PROTOCOL, new String [] { "protocol"}); - put(VALUE, new String [] { "value"}); - put(DISPLAYNAME, new String [] { "displayName"}); - put(LABELS, new String [] { "metadata","labels"}); - put(LABELS, new String [] { "metadata","labels"}); - put(NAME , new String [] {"metadata", "name"}); - put(NAMESPACE, new String [] {"metadata", "namespace"}); - - put(BUILD_MESSAGE, new String[]{"status","message"}); - put(BUILD_PODNAME, new String[]{"podName"}); - put(BUILD_STATUS, new String[]{"status","phase"}); - - put(BUILDCONFIG_SOURCE_CONTEXTDIR, new String[]{"spec","source","contextDir"}); - put(BUILDCONFIG_SOURCE_TYPE, new String[]{"spec","source","type"}); - put(BUILDCONFIG_SOURCE_URI, new String[]{"spec","source","git","uri"}); - put(BUILDCONFIG_SOURCE_REF, new String[]{"spec","source","git","ref"}); - put(BUILDCONFIG_STRATEGY, new String[]{"spec","strategy"}); - put(BUILDCONFIG_TYPE, new String[]{"spec","strategy", "type"}); - put(BUILDCONFIG_CUSTOM_IMAGE, new String[]{"spec","strategy", "customStrategy", "image"}); - put(BUILDCONFIG_CUSTOM_EXPOSEDOCKERSOCKET, new String[]{"spec","strategy", "customStrategy", "exposeDockerSocket"}); - put(BUILDCONFIG_CUSTOM_ENV, new String[]{"spec","strategy", "customStrategy", "env"}); - put(BUILDCONFIG_DOCKER_CONTEXTDIR, new String[]{"spec","strategy", "dockerStrategy", "contextDir"}); - put(BUILDCONFIG_DOCKER_NOCACHE, new String[]{"spec","strategy", "dockerStrategy", "noCache"}); - put(BUILDCONFIG_DOCKER_BASEIMAGE, new String[]{"spec","strategy", "dockerStrategy","baseImage"}); - put(BUILDCONFIG_OUTPUT_REPO, new String[]{"spec","output", "to","name"}); - put(BUILDCONFIG_STI_IMAGE, new String[]{"spec","strategy", "sourceStrategy", "from","name"}); - put(BUILDCONFIG_STI_SCRIPTS, new String[]{"spec","strategy", "sourceStrategy", "scripts"}); - put(BUILDCONFIG_STI_INCREMENTAL, new String[]{"spec","strategy", "sourceStrategy", "incremental"}); - put(BUILDCONFIG_STI_ENV, new String[]{"spec","strategy", "sourceStrategy", "env"}); - put(BUILDCONFIG_TRIGGERS, new String[]{"spec","triggers"}); - put(BUILD_CONFIG_WEBHOOK_GITHUB_SECRET, new String[]{"github","secret"}); - put(BUILD_CONFIG_WEBHOOK_GENERIC_SECRET, new String[]{"generic","secret"}); - put(BUILD_CONFIG_IMAGECHANGE_IMAGE, new String[]{"imageChange","image"}); - put(BUILD_CONFIG_IMAGECHANGE_NAME, new String[]{"imageChange", "from","name"}); - put(BUILD_CONFIG_IMAGECHANGE_TAG, new String[]{"imageChange","tag"}); - - put(DEPLOYMENTCONFIG_CONTAINERS, new String[]{"spec","template","spec","containers"}); - put(DEPLOYMENTCONFIG_VOLUMES, new String[]{"spec","template","spec","volumes"}); - put(DEPLOYMENTCONFIG_REPLICAS, new String[]{"spec","replicas"}); - put(DEPLOYMENTCONFIG_REPLICA_SELECTOR, new String[]{"spec","selector"}); - put(DEPLOYMENTCONFIG_TEMPLATE_LABELS, new String[]{"spec","template","metadata","labels"}); - put(DEPLOYMENTCONFIG_TRIGGERS, new String[]{"spec","triggers"}); - put(DEPLOYMENTCONFIG_STRATEGY, new String[]{"spec","strategy","type"}); - put(DEPLOYMENTCONFIG_TRIGGER_IMAGECHANGE_AUTO, new String[]{"imageChangeParams","automatic"}); - put(DEPLOYMENTCONFIG_TRIGGER_CONTAINERS, new String[]{"imageChangeParams","containerNames"}); - put(DEPLOYMENTCONFIG_TRIGGER_FROM, new String[]{"imageChangeParams","from","name"}); - put(DEPLOYMENTCONFIG_TRIGGER_FROM_KIND, new String[]{"imageChangeParams","from","kind"}); - - put(KIND, new String[]{"kind"}); - - put(IMAGESTREAM_DOCKER_IMAGE_REPO, new String[]{"spec","dockerImageRepository"}); - - put(PROJECT_DISPLAY_NAME, new String[]{"metadata","annotations","displayName"}); - - put(ROUTE_HOST, new String[] {"spec", "host" }); - put(ROUTE_PATH, new String[] { "spec", "path" }); - put(ROUTE_KIND, new String[] {"spec", "to", "kind" }); - put(ROUTE_SERVICE_NAME, new String[] {"spec", "to", "name" }); - put(ROUTE_TLS, new String[]{ "spec", "tls" }); - put(ROUTE_TLS_TERMINATION_TYPE, new String[]{"spec", "tls", "termination" }); - put(ROUTE_TLS_CERTIFICATE, new String[]{"spec", "tls", "certificate" }); - put(ROUTE_TLS_KEY, new String[]{ "spec", "tls", "key" }); - put(ROUTE_TLS_CACERT, new String[]{"spec", "tls","caCertificate"}); - put(ROUTE_TLS_DESTINATION_CACERT, new String[]{"spec", "tls","destinationCACertificate"}); - - put(TEMPLATE_PARAMETERS, new String[]{"parameters"}); - put(TEMPLATE_ITEMS, new String[]{"objects"}); - put(TEMPLATE_OBJECT_LABELS, new String[]{"labels"}); - - put(TYPE, new String[]{"type"}); - - put(USER_FULLNAME, new String[]{"fullName"}); - put(SECRET_TYPE, new String[]{"type"}); - put(SECRET_DATA, new String[]{"data"}); - }}; - - @SuppressWarnings("serial") - static final Map V1_OPENSHIFT_MAP = new HashMap(){{ - //common properties - put(ANNOTATIONS, new String [] {"metadata", "annotations"}); - put(APIVERSION, new String [] {"apiVersion"}); - put(CREATION_TIMESTAMP, new String [] {"metadata", "creationTimestamp"}); - put(DESCRIPTION, new String [] { "description"}); - put(IMAGE, new String [] { "image"}); - put(PORTS, new String [] { "ports"}); - put(ENV, new String [] { "env"}); - put(CONTAINER_PORT, new String [] { "containerPort"}); - put(PROTOCOL, new String [] { "protocol"}); - put(VALUE, new String [] { "value"}); - put(DISPLAYNAME, new String [] { "displayName"}); - put(LABELS, new String [] { "metadata","labels"}); - put(NAME , new String [] {"metadata", "name"}); - put(NAMESPACE, new String [] {"metadata", "namespace"}); - - put(BUILD_MESSAGE, new String[]{"status","message"}); - put(BUILD_PODNAME, new String[]{"podName"}); - put(BUILD_STATUS, new String[]{"status","phase"}); - - put(BUILDCONFIG_SOURCE_CONTEXTDIR, new String[]{"spec","source","contextDir"}); - put(BUILDCONFIG_SOURCE_TYPE, new String[]{"spec","source","type"}); - put(BUILDCONFIG_SOURCE_URI, new String[]{"spec","source","git","uri"}); - put(BUILDCONFIG_SOURCE_REF, new String[]{"spec","source","git","ref"}); - put(BUILDCONFIG_STRATEGY, new String[]{"spec","strategy"}); - put(BUILDCONFIG_TYPE, new String[]{"spec","strategy", "type"}); - put(BUILDCONFIG_CUSTOM_IMAGE, new String[]{"spec","strategy", "customStrategy", "image"}); - put(BUILDCONFIG_CUSTOM_EXPOSEDOCKERSOCKET, new String[]{"spec","strategy", "customStrategy", "exposeDockerSocket"}); - put(BUILDCONFIG_CUSTOM_ENV, new String[]{"spec","strategy", "customStrategy", "env"}); - put(BUILDCONFIG_DOCKER_CONTEXTDIR, new String[]{"spec","strategy", "dockerStrategy", "contextDir"}); - put(BUILDCONFIG_DOCKER_NOCACHE, new String[]{"spec","strategy", "dockerStrategy", "noCache"}); - put(BUILDCONFIG_DOCKER_BASEIMAGE, new String[]{"spec","strategy", "dockerStrategy","baseImage"}); - put(BUILDCONFIG_OUTPUT_REPO, new String[]{"spec","output", "to","name"}); - put(BUILDCONFIG_STI_IMAGE, new String[]{"spec","strategy", "sourceStrategy", "from","name"}); - put(BUILDCONFIG_STI_SCRIPTS, new String[]{"spec","strategy", "sourceStrategy", "scripts"}); - put(BUILDCONFIG_STI_INCREMENTAL, new String[]{"spec","strategy", "sourceStrategy", "incremental"}); - put(BUILDCONFIG_STI_ENV, new String[]{"spec","strategy", "sourceStrategy", "env"}); - put(BUILDCONFIG_TRIGGERS, new String[]{"spec","triggers"}); - put(BUILD_CONFIG_WEBHOOK_GITHUB_SECRET, new String[]{"github","secret"}); - put(BUILD_CONFIG_WEBHOOK_GENERIC_SECRET, new String[]{"generic","secret"}); - put(BUILD_CONFIG_IMAGECHANGE_IMAGE, new String[]{"imageChange","image"}); - put(BUILD_CONFIG_IMAGECHANGE_NAME, new String[]{"imageChange", "from","name"}); - put(BUILD_CONFIG_IMAGECHANGE_TAG, new String[]{"imageChange","tag"}); - - put(DEPLOYMENTCONFIG_CONTAINERS, new String[]{"spec","template","spec","containers"}); - put(DEPLOYMENTCONFIG_VOLUMES, new String[]{"spec","template","spec","volumes"}); - put(DEPLOYMENTCONFIG_REPLICAS, new String[]{"spec","replicas"}); - put(DEPLOYMENTCONFIG_REPLICA_SELECTOR, new String[]{"spec","selector"}); - put(DEPLOYMENTCONFIG_TEMPLATE_LABELS, new String[]{"spec","template","metadata","labels"}); - put(DEPLOYMENTCONFIG_TRIGGERS, new String[]{"spec","triggers"}); - put(DEPLOYMENTCONFIG_STRATEGY, new String[]{"spec","strategy","type"}); - put(DEPLOYMENTCONFIG_TRIGGER_IMAGECHANGE_AUTO, new String[]{"imageChangeParams","automatic"}); - put(DEPLOYMENTCONFIG_TRIGGER_CONTAINERS, new String[]{"imageChangeParams","containerNames"}); - put(DEPLOYMENTCONFIG_TRIGGER_FROM, new String[]{"imageChangeParams","from","name"}); - put(DEPLOYMENTCONFIG_TRIGGER_FROM_KIND, new String[]{"imageChangeParams","from","kind"}); - - put(KIND, new String[]{"kind"}); - - put(IMAGESTREAM_DOCKER_IMAGE_REPO, new String[]{"spec","dockerImageRepository"}); - - put(PROJECT_DISPLAY_NAME, new String[]{"displayName"}); - - put(ROUTE_HOST, new String[] {"spec", "host" }); - put(ROUTE_PATH, new String[] { "spec", "path" }); - put(ROUTE_KIND, new String[] {"spec", "to", "kind" }); - put(ROUTE_SERVICE_NAME, new String[] {"spec", "to", "name" }); - put(ROUTE_TLS, new String[]{ "spec", "tls" }); - put(ROUTE_TLS_TERMINATION_TYPE, new String[]{"spec", "tls", "termination" }); - put(ROUTE_TLS_CERTIFICATE, new String[]{"spec", "tls", "certificate" }); - put(ROUTE_TLS_KEY, new String[]{ "spec", "tls", "key" }); - put(ROUTE_TLS_CACERT, new String[]{"spec", "tls","caCertificate"}); - put(ROUTE_TLS_DESTINATION_CACERT, new String[]{"spec", "tls","destinationCACertificate"}); - - put(TEMPLATE_PARAMETERS, new String[]{"parameters"}); - put(TEMPLATE_ITEMS, new String[]{"objects"}); - put(TEMPLATE_OBJECT_LABELS, new String[]{"labels"}); - - put(TYPE, new String[]{"type"}); - - put(USER_FULLNAME, new String[]{"fullName"}); - put(SECRET_TYPE, new String[]{"type"}); - put(SECRET_DATA, new String[]{"data"}); - }}; -} diff --git a/src/main/java/com/openshift/internal/restclient/model/properties/ResourcePropertiesRegistry.java b/src/main/java/com/openshift/internal/restclient/model/properties/ResourcePropertiesRegistry.java index 3197d888..ed242131 100644 --- a/src/main/java/com/openshift/internal/restclient/model/properties/ResourcePropertiesRegistry.java +++ b/src/main/java/com/openshift/internal/restclient/model/properties/ResourcePropertiesRegistry.java @@ -8,30 +8,19 @@ ******************************************************************************/ package com.openshift.internal.restclient.model.properties; -import static com.openshift.internal.restclient.model.properties.KubernetesApiModelProperties.V1BETA3_KUBERNETES_MAP; -import static com.openshift.internal.restclient.model.properties.KubernetesApiModelProperties.V1_KUBERNETES_MAP; -import static com.openshift.internal.restclient.model.properties.OpenShiftApiModelProperties.V1BETA3_OPENSHIFT_MAP; -import static com.openshift.internal.restclient.model.properties.OpenShiftApiModelProperties.V1_OPENSHIFT_MAP; - -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.commons.lang.StringUtils; - import com.openshift.internal.restclient.APIModelVersion; import com.openshift.internal.restclient.KubernetesAPIVersion; import com.openshift.internal.restclient.OpenShiftAPIVersion; import com.openshift.restclient.IncompatibleApiVersionsException; -import com.openshift.restclient.ResourceKind; -import com.openshift.restclient.UnsupportedVersionException; /** - * Registry of keys to property paths by version for each API resource type + * Registry of paths that override a default * * @author Jeff Cantrill */ @@ -41,81 +30,7 @@ public class ResourcePropertiesRegistry implements ResourcePropertyKeys { private final Map> versionPropertyMap = new HashMap>(); - @SuppressWarnings("serial") - static final Map UNREGISTERED_MAP = new HashMap(){{ - //common properties - put(ANNOTATIONS, new String [] {"metadata", "annotations"}); - put(APIVERSION, new String [] {"apiVersion"}); - put(CREATION_TIMESTAMP, new String [] {"metadata", "creationTimestamp"}); - put(KIND, new String[]{"kind"}); - put(LABELS, new String [] { "metadata","labels"}); - put(NAME , new String [] {"metadata", "name"}); - put(NAMESPACE, new String [] {"metadata", "namespace"}); - }}; - - @SuppressWarnings("deprecation") private ResourcePropertiesRegistry(){ - //v1beta3 - versionPropertyMap.put(new VersionKey(KubernetesAPIVersion.v1beta3, ResourceKind.EVENT), V1BETA3_KUBERNETES_MAP); - versionPropertyMap.put(new VersionKey(KubernetesAPIVersion.v1beta3, ResourceKind.LIMIT_RANGE), V1BETA3_KUBERNETES_MAP); - versionPropertyMap.put(new VersionKey(KubernetesAPIVersion.v1beta3, ResourceKind.POD), V1BETA3_KUBERNETES_MAP); - versionPropertyMap.put(new VersionKey(KubernetesAPIVersion.v1beta3, ResourceKind.PVC), V1BETA3_KUBERNETES_MAP); - versionPropertyMap.put(new VersionKey(KubernetesAPIVersion.v1beta3, ResourceKind.REPLICATION_CONTROLLER), V1BETA3_KUBERNETES_MAP); - versionPropertyMap.put(new VersionKey(KubernetesAPIVersion.v1beta3, ResourceKind.RESOURCE_QUOTA), V1BETA3_KUBERNETES_MAP); - versionPropertyMap.put(new VersionKey(KubernetesAPIVersion.v1beta3, ResourceKind.SERVICE), V1BETA3_KUBERNETES_MAP); - versionPropertyMap.put(new VersionKey(KubernetesAPIVersion.v1beta3, ResourceKind.STATUS), V1BETA3_KUBERNETES_MAP); - - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta3, ResourceKind.BUILD), V1BETA3_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta3, ResourceKind.BUILD_CONFIG), V1BETA3_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta3, ResourceKind.BUILD_REQUEST), V1BETA3_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta3, ResourceKind.LIST), V1BETA3_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta3, ResourceKind.DEPLOYMENT_CONFIG), V1BETA3_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta3, ResourceKind.IMAGE_STREAM), V1BETA3_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta3, ResourceKind.OAUTH_ACCESS_TOKEN), V1BETA3_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta3, ResourceKind.OAUTH_AUTHORIZE_TOKEN), V1BETA3_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta3, ResourceKind.OAUTH_CLIENT), V1BETA3_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta3, ResourceKind.OAUTH_CLIENT_AUTHORIZATION), V1BETA3_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta3, ResourceKind.POLICY), V1BETA3_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta3, ResourceKind.POLICY_BINDING), V1BETA3_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta3, ResourceKind.PROJECT), V1BETA3_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta3, ResourceKind.PROJECT_REQUEST), V1BETA3_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta3, ResourceKind.ROLE), V1BETA3_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta3, ResourceKind.ROLE_BINDING), V1BETA3_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta3, ResourceKind.ROUTE), V1BETA3_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta3, ResourceKind.TEMPLATE), V1BETA3_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta3, ResourceKind.USER), V1BETA3_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta3, ResourceKind.SECRET), V1BETA3_OPENSHIFT_MAP); - - //v1 - versionPropertyMap.put(new VersionKey(KubernetesAPIVersion.v1, ResourceKind.EVENT), V1_KUBERNETES_MAP); - versionPropertyMap.put(new VersionKey(KubernetesAPIVersion.v1, ResourceKind.LIMIT_RANGE), V1_KUBERNETES_MAP); - versionPropertyMap.put(new VersionKey(KubernetesAPIVersion.v1, ResourceKind.POD), V1_KUBERNETES_MAP); - versionPropertyMap.put(new VersionKey(KubernetesAPIVersion.v1, ResourceKind.PVC), V1_KUBERNETES_MAP); - versionPropertyMap.put(new VersionKey(KubernetesAPIVersion.v1, ResourceKind.REPLICATION_CONTROLLER), V1_KUBERNETES_MAP); - versionPropertyMap.put(new VersionKey(KubernetesAPIVersion.v1, ResourceKind.RESOURCE_QUOTA), V1_KUBERNETES_MAP); - versionPropertyMap.put(new VersionKey(KubernetesAPIVersion.v1, ResourceKind.SERVICE), V1_KUBERNETES_MAP); - versionPropertyMap.put(new VersionKey(KubernetesAPIVersion.v1, ResourceKind.STATUS), V1_KUBERNETES_MAP); - - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1, ResourceKind.BUILD), V1_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1, ResourceKind.BUILD_CONFIG), V1_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1, ResourceKind.BUILD_REQUEST), V1_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1, ResourceKind.LIST), V1_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1, ResourceKind.DEPLOYMENT_CONFIG), V1_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1, ResourceKind.IMAGE_STREAM), V1_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1, ResourceKind.OAUTH_ACCESS_TOKEN), V1_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1, ResourceKind.OAUTH_AUTHORIZE_TOKEN), V1_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1, ResourceKind.OAUTH_CLIENT), V1_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1, ResourceKind.OAUTH_CLIENT_AUTHORIZATION), V1_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1, ResourceKind.POLICY), V1_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1, ResourceKind.POLICY_BINDING), V1_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1, ResourceKind.PROJECT), V1_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1, ResourceKind.PROJECT_REQUEST), V1_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1, ResourceKind.ROLE), V1_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1, ResourceKind.ROLE_BINDING), V1_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1, ResourceKind.ROUTE), V1_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1, ResourceKind.TEMPLATE), V1_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1, ResourceKind.USER), V1_OPENSHIFT_MAP); - versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1, ResourceKind.SECRET), V1_OPENSHIFT_MAP); } public static final ResourcePropertiesRegistry getInstance(){ @@ -125,29 +40,17 @@ public static final ResourcePropertiesRegistry getInstance(){ return instance; } - public Map get(final String apiVersion, final String kind) { - return get(apiVersion, kind, false); - } /** * Retrieve a given resource property map for a given version * @param apiVersion * @param kind - * @param strict true if it should throw an error when properties are not found; false otherwise * * @return The set of paths for the properties of the resource */ - public Map get(final String apiVersion, final String kind, boolean strict) { + public Map get(final String apiVersion, final String kind) { final VersionKey key = new VersionKey(apiVersion, kind); if(!versionPropertyMap.containsKey(key)){ - if(!strict) return UNREGISTERED_MAP; - Collection versions = new ArrayList(); - for (VersionKey version : versionPropertyMap.keySet()) { - if(version.kind.equals(kind)) { - versions.add(version.version); - } - } - String kindVersions = StringUtils.join(versions, ","); - throw new UnsupportedVersionException("Version '%s' not supported for kind '%s'. Supported Versions are: %s", apiVersion, kind, kindVersions); + return new HashMap(); } return versionPropertyMap.get(key); } diff --git a/src/main/java/com/openshift/internal/restclient/model/properties/ResourcePropertyKeys.java b/src/main/java/com/openshift/internal/restclient/model/properties/ResourcePropertyKeys.java index 2f52c8ae..7589149d 100644 --- a/src/main/java/com/openshift/internal/restclient/model/properties/ResourcePropertyKeys.java +++ b/src/main/java/com/openshift/internal/restclient/model/properties/ResourcePropertyKeys.java @@ -13,76 +13,21 @@ * * @author Jeff Cantrill */ -public interface ResourcePropertyKeys extends BuildConfigPropertyKeys, DeploymentConfigPropertyKeys{ - static final String ANNOTATIONS = "annotations"; - static final String APIVERSION = "apiversion"; - static final String CREATION_TIMESTAMP = "creationTimestamp"; - static final String CONTAINER_PORT = "containerPort"; - static final String DISPLAYNAME = "displayName"; - static final String DESCRIPTION = "description"; - static final String IMAGE = "image"; - static final String ENV = "env"; +public interface ResourcePropertyKeys { + + static final String APIVERSION = "apiVersion"; static final String KIND = "kind"; - static final String LABELS = "labels"; + + static final String ANNOTATIONS = "metadata.annotations"; + static final String CREATION_TIMESTAMP = "metadata.creationTimestamp"; + static final String LABELS = "metadata.labels"; + static final String METADATA_NAME = "metadata.name"; + static final String NAMESPACE = "metadata.namespace"; + static final String NAME = "name"; - static final String NAMESPACE = "namespace"; + static final String OBJECTS = "objects"; static final String PORTS = "ports"; static final String PROTOCOL = "protocol"; static final String VALUE = "value"; static final String TYPE = "type"; - - static final String REPLICATION_CONTROLLER_CONTAINERS = "replicationcontroller.containers"; - static final String REPLICATION_CONTROLLER_REPLICA_COUNT = "replicationcontroller.replicacount"; - static final String REPLICATION_CONTROLLER_CURRENT_REPLICA_COUNT = "replicationcontroller.replicacount.current"; - static final String REPLICATION_CONTROLLER_REPLICA_SELECTOR = "replicationcontroller.selector"; - - static final String SERVICE_CONTAINER_PORT = "service.containerport"; - static final String SERVICE_PORT = "service.port"; - static final String SERVICE_SELECTOR = "service.selector"; - static final String SERVICE_PORTALIP = "service.portalIP"; - - static final String STATUS_MESSAGE = "status.message"; - static final String STATUS_CODE = "status.code"; - static final String STATUS_STATUS = "status.status"; - static final String STATUS_PHASE = "status.phase"; - - static final String BUILD_STATUS = "build.status"; - static final String BUILD_MESSAGE = "build.message"; - static final String BUILD_PODNAME = "build.podname"; - - static final String IMAGESTREAM_DOCKER_IMAGE_REPO = "imagerepo.dockerimagerepo"; - - @Deprecated - static final String PROJECT_DISPLAY_NAME = "project.displayname"; - static final String ROUTE_HOST = "route.host"; - static final String ROUTE_PATH = "route.path"; - static final String ROUTE_KIND = "route.kind"; - static final String ROUTE_SERVICE_NAME = "route.serviceName"; - static final String ROUTE_TLS = "route.tls"; - static final String ROUTE_TLS_TERMINATION_TYPE = "route.tls.termination"; - static final String ROUTE_TLS_CERTIFICATE = "route.tls.certificate"; - static final String ROUTE_TLS_KEY = "route.tls.key"; - static final String ROUTE_TLS_CACERT = "route.tls.caCertificate"; - static final String ROUTE_TLS_DESTINATION_CACERT = "route.tls.destinationCaCertificate"; - - static final String POD_CONTAINERS = "pod.containers"; - static final String POD_HOST = "pod.host"; - static final String POD_IP = "pod.ip"; - static final String POD_STATUS = "pod.status"; - - static final String PORTS_CONTAINER_PORT = "ports.containerport"; - static final String PORTS_PROTOCOL = "ports.protocol"; - static final String PORTS_NAME = "ports.name"; - - static final String PVC_ACCESS_MODES = "pvc.accessmodes"; - static final String PVC_REQUESTED_STORAGE = "pvc.requested.storage"; - - static final String TEMPLATE_PARAMETERS = "template.parameters"; - static final String TEMPLATE_ITEMS = "template.items"; - static final String TEMPLATE_OBJECT_LABELS = "template.object.labels"; - - static final String USER_FULLNAME= "user.fullname"; - - static final String SECRET_TYPE = "secret.type"; - static final String SECRET_DATA = "secret.data"; } diff --git a/src/main/java/com/openshift/internal/restclient/model/template/Template.java b/src/main/java/com/openshift/internal/restclient/model/template/Template.java index 29e45c77..e2ac21e2 100644 --- a/src/main/java/com/openshift/internal/restclient/model/template/Template.java +++ b/src/main/java/com/openshift/internal/restclient/model/template/Template.java @@ -31,9 +31,13 @@ * @author Jeff Cantrill */ public class Template extends KubernetesResource implements ITemplate{ + + private static final String TEMPLATE_PARAMETERS = "parameters"; + private static final String TEMPLATE_OBJECT_LABELS = "labels"; + - public Template(ModelNode node, IClient client, Map propertyKeys) { - super(node, client, propertyKeys); + public Template(ModelNode node, IClient client, Map overrideProperties) { + super(node, client, overrideProperties); } @Override @@ -63,7 +67,7 @@ public Map getParameters() { @Override public Collection getItems() { - Collection nodes = get(TEMPLATE_ITEMS).asList(); + Collection nodes = get(OBJECTS).asList(); List resources = new ArrayList(nodes.size()); IResourceFactory factory = getClient().getResourceFactory(); if(factory != null){ diff --git a/src/main/java/com/openshift/internal/restclient/model/user/OpenShiftUser.java b/src/main/java/com/openshift/internal/restclient/model/user/OpenShiftUser.java index f059be49..172adddd 100644 --- a/src/main/java/com/openshift/internal/restclient/model/user/OpenShiftUser.java +++ b/src/main/java/com/openshift/internal/restclient/model/user/OpenShiftUser.java @@ -20,6 +20,8 @@ public class OpenShiftUser extends KubernetesResource implements IUser { + private static final String USER_FULLNAME = "fullName"; + public OpenShiftUser(ModelNode node, IClient client, Map propertyKeys) { super(node, client, propertyKeys); } diff --git a/src/main/java/com/openshift/internal/restclient/model/volume/AbstractVolume.java b/src/main/java/com/openshift/internal/restclient/model/volume/AbstractVolume.java index d4b0ae13..36a783a8 100644 --- a/src/main/java/com/openshift/internal/restclient/model/volume/AbstractVolume.java +++ b/src/main/java/com/openshift/internal/restclient/model/volume/AbstractVolume.java @@ -31,7 +31,6 @@ public abstract class AbstractVolume public AbstractVolume(ModelNode node) { super(node, new HashMap()); - getPropertyKeys().put(NAME, new String [] {"name"}); } @Override @@ -41,7 +40,7 @@ public String getName() { @Override public void setName(String name) { - set(getNode(), getPropertyKeys(),NAME, name); + set(getNode(), getPropertyKeys(), NAME, name); } diff --git a/src/main/java/com/openshift/internal/restclient/model/volume/PersistentVolumeClaim.java b/src/main/java/com/openshift/internal/restclient/model/volume/PersistentVolumeClaim.java index 0e69c293..42757ab9 100644 --- a/src/main/java/com/openshift/internal/restclient/model/volume/PersistentVolumeClaim.java +++ b/src/main/java/com/openshift/internal/restclient/model/volume/PersistentVolumeClaim.java @@ -28,6 +28,10 @@ */ public class PersistentVolumeClaim extends KubernetesResource implements IPersistentVolumeClaim { + private static final String PVC_ACCESS_MODES = "spec.accessModes"; + private static final String PVC_REQUESTED_STORAGE = "spec.resources.requests.storage"; + private static final String STATUS_PHASE = "status.phase"; + public PersistentVolumeClaim(ModelNode node, IClient client, Map propertyKeys) { super(node, client, propertyKeys); } diff --git a/src/main/java/com/openshift/internal/util/JBossDmrExtentions.java b/src/main/java/com/openshift/internal/util/JBossDmrExtentions.java index 22ea07b8..f656993d 100644 --- a/src/main/java/com/openshift/internal/util/JBossDmrExtentions.java +++ b/src/main/java/com/openshift/internal/util/JBossDmrExtentions.java @@ -8,6 +8,7 @@ ******************************************************************************/ package com.openshift.internal.util; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -28,17 +29,13 @@ private JBossDmrExtentions (){ public static void set(ModelNode node, Map propertyKeys, String key, boolean value){ if(propertyKeys == null) return; - String [] path = propertyKeys.get(key); - if(path == null) throw new UnregisteredPropertyException(key); - ModelNode modelNode = node.get(path); + ModelNode modelNode = node.get(getPath(propertyKeys, key)); modelNode.set(value); } public static void set(ModelNode node, Map propertyKeys, String key, String value){ if(propertyKeys == null) return; - String [] path = propertyKeys.get(key); - if(path == null) throw new UnregisteredPropertyException(key); - set(node, path, value); + set(node, getPath(propertyKeys, key), value); } public static void set(ModelNode node, String [] path, String value){ @@ -49,17 +46,13 @@ public static void set(ModelNode node, String [] path, String value){ public static void set(ModelNode node, Map propertyKeys, String key, int value) { if(propertyKeys == null) return; - String [] path = propertyKeys.get(key); - if(path == null) throw new UnregisteredPropertyException(key); - ModelNode modelNode = node.get(path); + ModelNode modelNode = node.get(getPath(propertyKeys, key)); modelNode.set(value); } public static void set(ModelNode node, Map propertyKeys, String key, Map values) { if(propertyKeys == null) return; - String [] path = propertyKeys.get(key); - if(path == null) throw new UnregisteredPropertyException(key); - ModelNode modelNode = node.get(path); + ModelNode modelNode = node.get(getPath(propertyKeys, key)); for (Entry entry : values.entrySet()) { modelNode.get(entry.getKey()).set(entry.getValue()); } @@ -76,8 +69,7 @@ public static void set(ModelNode node, Map propertyKeys, Stri public static Map asMap(ModelNode root, Map propertyKeys, String key){ HashMap map = new HashMap(); if(propertyKeys != null){ - String [] path = propertyKeys.get(key); - if(path == null) throw new UnregisteredPropertyException(key); + String [] path = getPath(propertyKeys, key); ModelNode node = root.get(path); if( !node.isDefined()) return map; @@ -97,8 +89,7 @@ public static Map asMap(ModelNode root, Map p * @throws UnregisteredPropertyException if the property is not found in the property map */ public static int asInt(ModelNode node, Map propertyKeys, String key){ - String [] path = propertyKeys.get(key); - if(path == null) throw new UnregisteredPropertyException(key); + String [] path = getPath(propertyKeys, key); ModelNode modelNode = node.get(path); if( !modelNode.isDefined()){ return 0; @@ -115,9 +106,7 @@ public static int asInt(ModelNode node, Map propertyKeys, Str * @throws UnregisteredPropertyException if the property is not found in the property map */ public static String asString(ModelNode node, Map propertyKeys, String key){ - String [] path = propertyKeys.get(key); - if(path == null) throw new UnregisteredPropertyException(key); - ModelNode modelNode = node.get(path); + ModelNode modelNode = node.get(getPath(propertyKeys, key)); if( !modelNode.isDefined()){ return ""; } @@ -133,8 +122,7 @@ public static String asString(ModelNode node, Map propertyKey * @throws UnregisteredPropertyException if the property is not found in the property map */ public static boolean asBoolean(ModelNode node, Map propertyKeys, String key) { - String [] path = propertyKeys.get(key); - if(path == null) throw new UnregisteredPropertyException(key); + String [] path = getPath(propertyKeys, key); ModelNode modelNode = node.get(path); if( !modelNode.isDefined()){ return false; @@ -147,10 +135,14 @@ public static ModelNode get(ModelNode node, Map propertyKeys, } public static String[] getPath(Map propertyKeys, String key) { - String [] property = propertyKeys.get(key); - if (property == null) { - throw new UnregisteredPropertyException(key); + if(propertyKeys.containsKey(key)) { + return propertyKeys.get(key); //allow override } - return property; + return key.split("\\."); + } + + @SuppressWarnings("unchecked") + public static String[] getPath(String key) { + return getPath(Collections.EMPTY_MAP, key); } } diff --git a/src/test/java/com/openshift/internal/restclient/capability/resources/TemplateTraceabilityTest.java b/src/test/java/com/openshift/internal/restclient/capability/resources/TemplateTraceabilityTest.java index 4ad16cf7..b18373d3 100644 --- a/src/test/java/com/openshift/internal/restclient/capability/resources/TemplateTraceabilityTest.java +++ b/src/test/java/com/openshift/internal/restclient/capability/resources/TemplateTraceabilityTest.java @@ -19,6 +19,7 @@ import com.openshift.internal.restclient.capability.resources.TemplateTraceability; import com.openshift.restclient.IClient; +import com.openshift.restclient.ResourceKind; import com.openshift.restclient.model.IResource; /** @@ -35,6 +36,7 @@ public class TemplateTraceabilityTest { public void setUp(){ capability = new TemplateTraceability(resource); when(resource.getNamespace()).thenReturn("mynamespace"); + when(resource.getKind()).thenReturn(ResourceKind.TEMPLATE); } @Test diff --git a/src/test/java/com/openshift/internal/restclient/capability/server/ServerTemplateProcessingIntegrationTest.java b/src/test/java/com/openshift/internal/restclient/capability/server/ServerTemplateProcessingIntegrationTest.java index ad1da682..5dbfe1eb 100644 --- a/src/test/java/com/openshift/internal/restclient/capability/server/ServerTemplateProcessingIntegrationTest.java +++ b/src/test/java/com/openshift/internal/restclient/capability/server/ServerTemplateProcessingIntegrationTest.java @@ -51,7 +51,7 @@ public void setup () throws MalformedURLException{ public void testProcessAndApplyTemplate() throws Exception{ final Collection results = new ArrayList(); ModelNode node = ModelNode.fromJSONString(Samples.V1BETA3_TEMPLATE.getContentAsString()); - final Template template = new Template(node, client, ResourcePropertiesRegistry.getInstance().get(VERSION, ResourceKind.TEMPLATE)); + final Template template = new Template(node, client, null); template.setNamespace(COMMON); try { client.accept(new CapabilityVisitor() { diff --git a/src/test/java/com/openshift/internal/restclient/model/KubernetesResourceTest.java b/src/test/java/com/openshift/internal/restclient/model/KubernetesResourceTest.java index ac0b5aba..eb91dd2e 100644 --- a/src/test/java/com/openshift/internal/restclient/model/KubernetesResourceTest.java +++ b/src/test/java/com/openshift/internal/restclient/model/KubernetesResourceTest.java @@ -13,6 +13,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static com.openshift.internal.util.JBossDmrExtentions.*; import java.util.ArrayList; import java.util.List; @@ -46,14 +47,13 @@ public void setup(){ private ModelNode createModelNode() { node = new ModelNode(); node.get(ResourcePropertyKeys.KIND).set(ResourceKind.LIST.toString()); - ModelNode meta = node.get("metadata"); - ModelNode annotations = meta.get(ResourcePropertyKeys.ANNOTATIONS); + ModelNode annotations = node.get(getPath(KubernetesResource.ANNOTATIONS)); annotations.get("foo").set("bar"); annotations.get("template").set("foobar"); - meta.get(ResourcePropertyKeys.NAME).set("bartender"); - meta.get(ResourcePropertyKeys.NAMESPACE).set("foofighters"); + node.get(KubernetesResource.METADATA_NAME).set("bartender"); + node.get(KubernetesResource.NAMESPACE).set("foofighters"); return node; } @@ -134,7 +134,7 @@ public void shouldDifferentHashCodeOnDifferentName() { int hashCodeBeforeChange = resource.hashCode(); // operation - resource.set(ResourcePropertyKeys.NAME, "brucefoolee"); + resource.set(KubernetesResource.METADATA_NAME, "brucefoolee"); // verification int hashCodeAfterChange = resource.hashCode(); @@ -187,7 +187,7 @@ public void shouldNotEqualsOnDifferentName() { assertEquals(resource, otherResource); // operation - otherResource.set(ResourcePropertyKeys.NAME, "kungfoo"); + otherResource.set(KubernetesResource.METADATA_NAME, "kungfoo"); // verification assertThat(resource).isNotEqualTo(otherResource); @@ -200,7 +200,7 @@ public void shouldNotEqualsOnDifferentNamespace() { assertEquals(resource, otherResource); // operation - otherResource.set(ResourcePropertyKeys.NAMESPACE, "karate"); + otherResource.set(KubernetesResource.NAMESPACE, "karate"); // verification assertThat(resource).isNotEqualTo(otherResource); diff --git a/src/test/java/com/openshift/internal/restclient/model/RouteTest.java b/src/test/java/com/openshift/internal/restclient/model/RouteTest.java index da57bd7e..3a9e3e0b 100644 --- a/src/test/java/com/openshift/internal/restclient/model/RouteTest.java +++ b/src/test/java/com/openshift/internal/restclient/model/RouteTest.java @@ -12,9 +12,13 @@ import static org.junit.Assert.*; import static org.mockito.Mockito.*; +import org.jboss.dmr.ModelNode; import org.junit.Before; import org.junit.Test; +import com.openshift.internal.restclient.model.properties.ResourcePropertyKeys; +import com.openshift.internal.util.JBossDmrExtentions; +import com.openshift.restclient.ResourceKind; import com.openshift.restclient.model.route.ITLSConfig; /** @@ -30,7 +34,9 @@ public class RouteTest { @Before public void setUp() throws Exception { - route = spy(new Route(null, null, null)); + ModelNode root = new ModelNode(); + JBossDmrExtentions.set(root, JBossDmrExtentions.getPath(ResourcePropertyKeys.KIND), ResourceKind.ROUTE); + route = spy(new Route(root, null, null)); doReturn("www.host.com").when(route).getHost(); doReturn("/abc").when(route).getPath(); } diff --git a/src/test/java/com/openshift/internal/restclient/model/StatusTest.java b/src/test/java/com/openshift/internal/restclient/model/StatusTest.java index 962eeb60..73a4c5cc 100644 --- a/src/test/java/com/openshift/internal/restclient/model/StatusTest.java +++ b/src/test/java/com/openshift/internal/restclient/model/StatusTest.java @@ -11,9 +11,14 @@ import static org.junit.Assert.*; import static org.mockito.Mockito.*; +import org.jboss.dmr.ModelNode; import org.junit.Before; import org.junit.Test; +import com.openshift.internal.restclient.model.properties.ResourcePropertyKeys; +import com.openshift.internal.util.JBossDmrExtentions; +import com.openshift.restclient.ResourceKind; + /** * Tests that have logic and not specific to a particular api version * @author jeff.cantrill @@ -25,7 +30,9 @@ public class StatusTest { @Before public void setup() { - status = spy(new Status(null,null,null)); + ModelNode root = new ModelNode(); + JBossDmrExtentions.set(root, JBossDmrExtentions.getPath(ResourcePropertyKeys.KIND), ResourceKind.STATUS); + status = spy(new Status(root,null,null)); } @Test diff --git a/src/test/java/com/openshift/internal/restclient/model/build/BuildConfigTest.java b/src/test/java/com/openshift/internal/restclient/model/build/BuildConfigTest.java index 10d4a4b2..3c476702 100644 --- a/src/test/java/com/openshift/internal/restclient/model/build/BuildConfigTest.java +++ b/src/test/java/com/openshift/internal/restclient/model/build/BuildConfigTest.java @@ -9,6 +9,7 @@ package com.openshift.internal.restclient.model.build; import static org.junit.Assert.*; +import static com.openshift.internal.util.JBossDmrExtentions.*; import org.jboss.dmr.ModelNode; import org.junit.Before; @@ -16,9 +17,6 @@ import org.mockito.Mock; import com.openshift.internal.restclient.model.BuildConfig; -import com.openshift.internal.restclient.model.properties.BuildConfigPropertyKeys; -import com.openshift.internal.restclient.model.properties.ResourcePropertiesRegistry; -import com.openshift.internal.restclient.model.properties.OpenShiftApiModelProperties; import com.openshift.restclient.IClient; import com.openshift.restclient.images.DockerImageURI; import com.openshift.restclient.model.build.BuildStrategyType; @@ -29,14 +27,14 @@ /** * @author Jeff Cantrill */ -public class BuildConfigTest implements BuildConfigPropertyKeys { +public class BuildConfigTest { @Mock private IClient client; private BuildConfig config; private ModelNode node = new ModelNode(); @Before public void setup(){ - config = new BuildConfig(node, client, OpenShiftApiModelProperties.V1_OPENSHIFT_MAP); + config = new BuildConfig(node, client, null); } @Test @@ -62,10 +60,10 @@ public void testGetCustomBuildStrategy(){ @Test public void testGetDockerBuildStrategy() { - node.get(OpenShiftApiModelProperties.V1_OPENSHIFT_MAP.get(BUILDCONFIG_TYPE)).set("Docker"); - node.get(OpenShiftApiModelProperties.V1_OPENSHIFT_MAP.get(BUILDCONFIG_DOCKER_CONTEXTDIR)).set("aContextDir"); - node.get(OpenShiftApiModelProperties.V1_OPENSHIFT_MAP.get(BUILDCONFIG_DOCKER_NOCACHE)).set(true); - node.get(OpenShiftApiModelProperties.V1_OPENSHIFT_MAP.get(BUILDCONFIG_DOCKER_BASEIMAGE)).set("thebaseImage"); + node.get(getPath(BuildConfig.BUILDCONFIG_TYPE)).set("Docker"); + node.get(getPath(BuildConfig.BUILDCONFIG_DOCKER_CONTEXTDIR)).set("aContextDir"); + node.get(getPath(BuildConfig.BUILDCONFIG_DOCKER_NOCACHE)).set(true); + node.get(getPath(BuildConfig.BUILDCONFIG_DOCKER_BASEIMAGE)).set("thebaseImage"); IBuildStrategy strategy = config.getBuildStrategy(); assertEquals(BuildStrategyType.DOCKER, strategy.getType()); diff --git a/src/test/java/com/openshift/internal/restclient/model/template/TemplateTest.java b/src/test/java/com/openshift/internal/restclient/model/template/TemplateTest.java index ba6656c7..fbb3d7c9 100644 --- a/src/test/java/com/openshift/internal/restclient/model/template/TemplateTest.java +++ b/src/test/java/com/openshift/internal/restclient/model/template/TemplateTest.java @@ -21,7 +21,6 @@ import org.junit.Test; import org.mockito.Mock; -import com.openshift.internal.restclient.model.properties.OpenShiftApiModelProperties; import com.openshift.restclient.IClient; import com.openshift.restclient.model.template.IParameter; import com.openshift.restclient.model.template.ITemplate; @@ -36,12 +35,12 @@ public void setUp() throws Exception { params.add(param("foo","bar")); params.add(param("abc","xyz")); params.add(param("123","456")); - template = new Template(node, client, OpenShiftApiModelProperties.V1BETA3_OPENSHIFT_MAP); + template = new Template(node, client, null); } @Test public void testGetParametersWhenNotDefined() { - template = new Template(new ModelNode(), client, OpenShiftApiModelProperties.V1_OPENSHIFT_MAP); + template = new Template(new ModelNode(), client, null); assertNotNull(template.getParameters()); } diff --git a/src/test/java/com/openshift/internal/restclient/model/v1/BuildConfigTest.java b/src/test/java/com/openshift/internal/restclient/model/v1/BuildConfigTest.java index 7631a90c..2c66eab4 100644 --- a/src/test/java/com/openshift/internal/restclient/model/v1/BuildConfigTest.java +++ b/src/test/java/com/openshift/internal/restclient/model/v1/BuildConfigTest.java @@ -28,7 +28,6 @@ import com.openshift.internal.restclient.model.build.ImageChangeTrigger; import com.openshift.internal.restclient.model.build.SourceBuildStrategy; import com.openshift.internal.restclient.model.build.WebhookTrigger; -import com.openshift.internal.restclient.model.properties.ResourcePropertiesRegistry; import com.openshift.restclient.IClient; import com.openshift.restclient.ResourceKind; import com.openshift.restclient.images.DockerImageURI; @@ -58,13 +57,9 @@ public static void setup() throws Exception{ when(client.getBaseURL()).thenReturn(new URL("https://localhost:8443")); when(client.getOpenShiftAPIVersion()).thenReturn(VERSION); ModelNode node = ModelNode.fromJSONString(Samples.V1_BUILD_CONFIG.getContentAsString()); - config = new BuildConfig(node, client, getPropertyKeys()); + config = new BuildConfig(node, client, null); } - private static Map getPropertyKeys() { - return ResourcePropertiesRegistry.getInstance().get(VERSION, ResourceKind.BUILD_CONFIG); - } - @Test public void getBuildTriggers(){ assertBuildTriggers(config.getBuildTriggers().toArray(new IBuildTrigger[]{})); @@ -158,6 +153,6 @@ private void assertSourceBuildStrategy(IBuildStrategy strategy) { } private BuildConfig reCreateBuildConfig(BuildConfig config) { - return new BuildConfig(config.getNode(), client, getPropertyKeys()); + return new BuildConfig(config.getNode(), client, null); } } diff --git a/src/test/java/com/openshift/internal/restclient/model/v1/DeploymentConfigTest.java b/src/test/java/com/openshift/internal/restclient/model/v1/DeploymentConfigTest.java index bbb07168..b3465aec 100644 --- a/src/test/java/com/openshift/internal/restclient/model/v1/DeploymentConfigTest.java +++ b/src/test/java/com/openshift/internal/restclient/model/v1/DeploymentConfigTest.java @@ -11,6 +11,7 @@ import static org.junit.Assert.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static com.openshift.internal.util.JBossDmrExtentions.*; import java.util.HashMap; import java.util.HashSet; @@ -19,13 +20,11 @@ import java.util.Set; import org.jboss.dmr.ModelNode; -import org.jboss.dmr.ModelType; import org.junit.Before; import org.junit.Test; import com.openshift.internal.restclient.model.DeploymentConfig; import com.openshift.internal.restclient.model.properties.ResourcePropertiesRegistry; -import com.openshift.internal.restclient.model.properties.ResourcePropertyKeys; import com.openshift.restclient.IClient; import com.openshift.restclient.ResourceKind; import com.openshift.restclient.images.DockerImageURI; @@ -97,7 +96,7 @@ public void testGetDeploymentStrategyTypes() { @Test public void testAddContainer() { //remove containers hack - String[] path = propertyKeys.get(ResourcePropertyKeys.DEPLOYMENTCONFIG_CONTAINERS); + String[] path = getPath(DeploymentConfig.DEPLOYMENTCONFIG_CONTAINERS); node.get(path).clear(); //setup diff --git a/src/test/java/com/openshift/internal/restclient/model/v1/TemplateTest.java b/src/test/java/com/openshift/internal/restclient/model/v1/TemplateTest.java index c291d862..6e9581cc 100644 --- a/src/test/java/com/openshift/internal/restclient/model/v1/TemplateTest.java +++ b/src/test/java/com/openshift/internal/restclient/model/v1/TemplateTest.java @@ -18,10 +18,8 @@ import org.junit.Test; import com.openshift.internal.restclient.ResourceFactory; -import com.openshift.internal.restclient.model.properties.ResourcePropertiesRegistry; import com.openshift.internal.restclient.model.template.Template; import com.openshift.restclient.IClient; -import com.openshift.restclient.ResourceKind; import com.openshift.restclient.model.template.IParameter; import com.openshift.restclient.model.template.ITemplate; import com.openshift.restclient.utils.Samples; @@ -41,7 +39,7 @@ public void setUp(){ IClient client = mock(IClient.class); when(client.getResourceFactory()).thenReturn(new ResourceFactory(client){}); ModelNode node = ModelNode.fromJSONString(Samples.V1_TEMPLATE.getContentAsString()); - template = new Template(node, client, ResourcePropertiesRegistry.getInstance().get(VERSION, ResourceKind.TEMPLATE)); + template = new Template(node, client, null); } @Test public void testGetApiVersion() { diff --git a/src/test/java/com/openshift/internal/restclient/model/v1beta3/BuildConfigTest.java b/src/test/java/com/openshift/internal/restclient/model/v1beta3/BuildConfigTest.java index 91dc1902..e7c5d78d 100644 --- a/src/test/java/com/openshift/internal/restclient/model/v1beta3/BuildConfigTest.java +++ b/src/test/java/com/openshift/internal/restclient/model/v1beta3/BuildConfigTest.java @@ -58,7 +58,7 @@ public static void setup() throws Exception{ when(client.getBaseURL()).thenReturn(new URL("https://localhost:8443")); when(client.getOpenShiftAPIVersion()).thenReturn("v1beta3"); ModelNode node = ModelNode.fromJSONString(Samples.V1BETA3_BUILD_CONFIG.getContentAsString()); - config = new BuildConfig(node, client, getPropertyKeys()); + config = new BuildConfig(node, client, null); } private static Map getPropertyKeys() { @@ -158,6 +158,6 @@ private void assertSourceBuildStrategy(IBuildStrategy strategy) { } private BuildConfig reCreateBuildConfig(BuildConfig config) { - return new BuildConfig(config.getNode(), client, getPropertyKeys()); + return new BuildConfig(config.getNode(), client, null); } } diff --git a/src/test/java/com/openshift/internal/restclient/model/v1beta3/DeploymentConfigTest.java b/src/test/java/com/openshift/internal/restclient/model/v1beta3/DeploymentConfigTest.java index 2c2cf737..a32ecdf2 100644 --- a/src/test/java/com/openshift/internal/restclient/model/v1beta3/DeploymentConfigTest.java +++ b/src/test/java/com/openshift/internal/restclient/model/v1beta3/DeploymentConfigTest.java @@ -11,6 +11,7 @@ import static org.junit.Assert.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static com.openshift.internal.util.JBossDmrExtentions.*; import java.util.HashMap; import java.util.HashSet; @@ -24,7 +25,6 @@ import com.openshift.internal.restclient.model.DeploymentConfig; import com.openshift.internal.restclient.model.properties.ResourcePropertiesRegistry; -import com.openshift.internal.restclient.model.properties.ResourcePropertyKeys; import com.openshift.restclient.IClient; import com.openshift.restclient.ResourceKind; import com.openshift.restclient.images.DockerImageURI; @@ -96,7 +96,7 @@ public void testGetDeploymentStrategyTypes() { @Test public void testAddContainer() { //remove containers hack - String[] path = propertyKeys.get(ResourcePropertyKeys.DEPLOYMENTCONFIG_CONTAINERS); + String[] path = getPath(DeploymentConfig.DEPLOYMENTCONFIG_CONTAINERS); node.get(path).clear(); //setup diff --git a/src/test/java/com/openshift/internal/restclient/model/v1beta3/PVCTest.java b/src/test/java/com/openshift/internal/restclient/model/v1beta3/PVCTest.java index bcbc4568..bf522feb 100644 --- a/src/test/java/com/openshift/internal/restclient/model/v1beta3/PVCTest.java +++ b/src/test/java/com/openshift/internal/restclient/model/v1beta3/PVCTest.java @@ -25,14 +25,14 @@ */ public class PVCTest { - private static final String V1 = "v1beta3"; + private static final String VERSION = "v1beta3"; private IPersistentVolumeClaim claim; @Before public void setup(){ IClient client = mock(IClient.class); claim = new ResourceFactory(client).create(Samples.V1BETA3_PVC.getContentAsString()); - assertEquals(V1, claim.getApiVersion()); + assertEquals(VERSION, claim.getApiVersion()); } @Test diff --git a/src/test/java/com/openshift/internal/restclient/model/v1beta3/TemplateTest.java b/src/test/java/com/openshift/internal/restclient/model/v1beta3/TemplateTest.java index 9746f74b..f28dfac9 100644 --- a/src/test/java/com/openshift/internal/restclient/model/v1beta3/TemplateTest.java +++ b/src/test/java/com/openshift/internal/restclient/model/v1beta3/TemplateTest.java @@ -18,10 +18,8 @@ import org.junit.Test; import com.openshift.internal.restclient.ResourceFactory; -import com.openshift.internal.restclient.model.properties.ResourcePropertiesRegistry; import com.openshift.internal.restclient.model.template.Template; import com.openshift.restclient.IClient; -import com.openshift.restclient.ResourceKind; import com.openshift.restclient.model.template.IParameter; import com.openshift.restclient.model.template.ITemplate; import com.openshift.restclient.utils.Samples; @@ -41,7 +39,7 @@ public void setUp(){ IClient client = mock(IClient.class); when(client.getResourceFactory()).thenReturn(new ResourceFactory(client){}); ModelNode node = ModelNode.fromJSONString(Samples.V1BETA3_TEMPLATE.getContentAsString()); - template = new Template(node, client, ResourcePropertiesRegistry.getInstance().get(VERSION, ResourceKind.TEMPLATE)); + template = new Template(node, client, null); } @Test public void testGetApiVersion() {