Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.openshift.internal.restclient.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

Expand All @@ -24,6 +25,7 @@ public Map<String, String> getReplicaSelector(){
return asMap(DEPLOYMENTCONFIG_REPLICA_SELECTOR);
}

@Override
public List<String> getTriggerTypes(){
List<String> types = new ArrayList<String>();
ModelNode triggers = get(DEPLOYMENTCONFIG_TRIGGERS);
Expand Down Expand Up @@ -85,4 +87,9 @@ private void buildTemplate(DockerImageURI imageTag, int containerPort) {
controllerTemplate.get(new String[]{"podTemplate","desiredState","manifest","containers"}).add(container);
controllerTemplate.get(new String[]{"podTemplate","labels","name"}).set(imageTag.getName());
}

@Override
public String getDeploymentStrategyType() {
return asString(DEPLOYMENTCONFIG_STRATEGY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public final class ResourcePropertiesRegistry implements ResourcePropertyKeys {
//common properties
put(ANNOTATIONS, new String [] {"metadata", "annotations"});
put(CREATION_TIMESTAMP, new String [] {"metadata", "creationTimestamp"});
put(LABELS, new String [] { "labels"});
put(LABELS, new String [] { "metadata","labels"});
put(NAME , new String [] {"metadata", "name"});
put(NAMESPACE, new String [] {"metadata", "namespace"});

Expand Down Expand Up @@ -94,6 +94,7 @@ public final class ResourcePropertiesRegistry implements ResourcePropertyKeys {
put(DEPLOYMENTCONFIG_REPLICAS, new String[]{"template","controllerTemplate","replicas"});
put(DEPLOYMENTCONFIG_REPLICA_SELECTOR, new String[]{"template","controllerTemplate","replicaSelector"});
put(DEPLOYMENTCONFIG_TRIGGERS, new String[]{"triggers"});
put(DEPLOYMENTCONFIG_STRATEGY, new String[]{"template","strategy","type"});

put(IMAGESTREAM_DOCKER_IMAGE_REPO, new String[]{"status","dockerImageRepository"});

Expand All @@ -117,6 +118,7 @@ private ResourcePropertiesRegistry(){
versionPropertyMap.put(new VersionKey(KubernetesAPIVersion.v1beta1, ResourceKind.ReplicationController), V1BETA1_KUBERNETES_MAP);
versionPropertyMap.put(new VersionKey(KubernetesAPIVersion.v1beta1, ResourceKind.Service), V1BETA1_KUBERNETES_MAP);
versionPropertyMap.put(new VersionKey(KubernetesAPIVersion.v1beta1, ResourceKind.Status), V1BETA1_KUBERNETES_MAP);


versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta1, ResourceKind.Build), V1BETA1_OPENSHIFT_MAP);
versionPropertyMap.put(new VersionKey(OpenShiftAPIVersion.v1beta1, ResourceKind.BuildConfig), V1BETA1_OPENSHIFT_MAP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public interface ResourcePropertyKeys extends BuildConfigPropertyKeys{
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 IMAGESTREAM_DOCKER_IMAGE_REPO = "imagerepo.dockerimagerepo";
static final String PROJECT_DISPLAY_NAME = "project.displayname";
static final String ROUTE_HOST = "route.host";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

import org.jboss.dmr.ModelNode;

import com.openshift.internal.restclient.KubernetesAPIVersion;
import com.openshift.internal.restclient.model.KubernetesResource;
import com.openshift.internal.restclient.model.properties.ResourcePropertiesRegistry;
import com.openshift.internal.util.JBossDmrExtentions;
import com.openshift.restclient.IClient;
import com.openshift.restclient.IResourceFactory;
import com.openshift.restclient.model.IResource;
Expand All @@ -32,6 +35,21 @@ public Template(ModelNode node, IClient client, Map<String, String []> propertyK
super(node, client, propertyKeys);
}

/**
* Template is an OS kind that compiles to kubernetes v1beta1 structure
* for labels.
* TODO: remove method when we move to v1beta3
*/
@Override
public Map<String, String> getLabels() {
final String version = getNode().get("apiVersion").asString();
if(KubernetesAPIVersion.valueOf(version).equals(KubernetesAPIVersion.v1beta1)) {
return JBossDmrExtentions.asMap(getNode(), ResourcePropertiesRegistry.V1BETA1_KUBERNETES_MAP, LABELS);
}
return super.getLabels();
}


@Override
public Map<String, IParameter> getParameters() {
Collection<ModelNode> nodes = get(TEMPLATE_PARAMETERS).asList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
******************************************************************************/
package com.openshift.restclient.model;

import java.util.Collection;
import java.util.Map;

/**
Expand All @@ -29,4 +30,17 @@ public interface IDeploymentConfig extends IResource {
* @return java.util.Map<String, String>
*/
Map<String, String> getReplicaSelector();

/**
* Get the list of deployment triggers
* @return a collection of trigger types
*/
Collection<String> getTriggerTypes();

/**
* Convenience method to get the deployment
* strategy type
* @return the type as a string
*/
String getDeploymentStrategyType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ public class V1Beta1DeploymentConfigTest {
@BeforeClass
public static void setup(){
IClient client = mock(IClient.class);
ModelNode node = ModelNode.fromJSONString(Samples.DEPLOYMENT_CONFIG_MINIMAL.getContentAsString());
ModelNode node = ModelNode.fromJSONString(Samples.V1BETA1_DEPLOYMENT_CONIFIG.getContentAsString());
config = new DeploymentConfig(node, client, ResourcePropertiesRegistry.getInstance().get("v1beta1", ResourceKind.DeploymentConfig));
}

@Test
public void getLabels() {
assertArrayEquals(new String[] {"template"},config.getLabels().keySet().toArray(new String[] {}));
}
@Test
public void getReplicas(){
assertEquals(1, config.getReplicas());
Expand All @@ -47,8 +51,18 @@ public void getReplicas(){
@Test
public void getReplicaSelector() {
Map<String, String> exp = new HashMap<String, String>();
exp.put("name", "javaparks");
exp.put("name", "database");
assertEquals(exp, config.getReplicaSelector());
}

@Test
public void getTriggerTypes() {
assertArrayEquals(new String[] {"ConfigChange"}, config.getTriggerTypes().toArray(new String[] {}));
}

@Test
public void testGetDeploymentStrategyTypes() {
assertEquals("Recreate", config.getDeploymentStrategyType());
}

}
2 changes: 1 addition & 1 deletion src/test/java/com/openshift/restclient/utils/Samples.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public enum Samples {

//kubernetes samples
BUILD_CONFIG_MINIMAL("openshift3/build_config_v1beta1_minimal.json"),
DEPLOYMENT_CONFIG_MINIMAL("openshift3/deployment_config_v1beta1_minimal.json"),
V1BETA1_DEPLOYMENT_CONIFIG("openshift3/v1beta1_deployment_config.json"),
V1BETA1_IMAGE_STREAM("openshift3/v1beta1_image_stream.json"),
V1BETA1_BUILD("openshift3/v1beta1_build.json"),
V1BETA1_POD("openshift3/v1beta1_pod.json"),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"kind": "DeploymentConfig",
"apiVersion": "v1beta1",
"metadata": {
"name": "database",
"namespace": "test",
"selfLink": "/osapi/v1beta1/deploymentConfigs/database?namespace=test",
"uid": "49c03f35-ef73-11e4-8391-080027893417",
"resourceVersion": "126",
"creationTimestamp": "2015-04-30T19:58:36Z",
"labels": {
"template": "application-template-stibuild"
}
},
"triggers": [
{
"type": "ConfigChange"
}
],
"template": {
"strategy": {
"type": "Recreate"
},
"controllerTemplate": {
"replicas": 1,
"replicaSelector": {
"name": "database"
},
"podTemplate": {
"desiredState": {
"manifest": {
"version": "v1beta2",
"id": "",
"volumes": null,
"containers": [
{
"name": "ruby-helloworld-database",
"image": "openshift/mysql-55-centos7",
"ports": [
{
"containerPort": 3306,
"protocol": "TCP"
}
],
"env": [
{
"name": "MYSQL_USER",
"key": "MYSQL_USER",
"value": "userLV1"
},
{
"name": "MYSQL_PASSWORD",
"key": "MYSQL_PASSWORD",
"value": "AuAwTB5k"
},
{
"name": "MYSQL_DATABASE",
"key": "MYSQL_DATABASE",
"value": "root"
}
],
"resources": {},
"terminationMessagePath": "/dev/termination-log",
"imagePullPolicy": "PullIfNotPresent",
"capabilities": {}
}
],
"restartPolicy": {
"always": {}
},
"dnsPolicy": "ClusterFirst"
}
},
"labels": {
"name": "database",
"template": "application-template-stibuild"
}
}
}
},
"latestVersion": 1,
"details": {
"causes": [
{
"type": "ConfigChange"
}
]
}
}