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
Expand Up @@ -26,6 +26,7 @@
import com.openshift.restclient.IClient;
import com.openshift.restclient.images.DockerImageURI;
import com.openshift.restclient.model.IBuildConfig;
import com.openshift.restclient.model.IObjectReference;
import com.openshift.restclient.model.build.BuildSourceType;
import com.openshift.restclient.model.build.BuildStrategyType;
import com.openshift.restclient.model.build.BuildTriggerType;
Expand Down Expand Up @@ -73,6 +74,15 @@ public BuildConfig(ModelNode node, IClient client, Map<String, String []> overri
CapabilityInitializer.initializeCapabilities(getModifiableCapabilities(), this, client);
}


@Override
public IObjectReference getBuildOutputReference() {
ModelNode node = get("spec.output.to");
if(!node.isDefined()) return null;
return new ObjectReference(node);
}


@Override
public List<IBuildTrigger> getBuildTriggers() {
List<IBuildTrigger> triggers = new ArrayList<IBuildTrigger>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,71 @@
******************************************************************************/
package com.openshift.internal.restclient.model;

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

import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;

import com.openshift.internal.restclient.model.image.TagReference;
import com.openshift.restclient.IClient;
import com.openshift.restclient.images.DockerImageURI;
import com.openshift.restclient.model.IImageStream;
import com.openshift.restclient.model.image.ITagReference;

/**
* @author Jeff Cantrill
*/
public class ImageStream extends KubernetesResource implements IImageStream {

private static final String IMAGESTREAM_DOCKER_IMAGE_REPO = "spec.dockerImageRepository";
private static final String IMAGESTREAM_SPEC_TAGS = "spec.tags";
private static final String IMAGESTREAM_STATUS_TAGS = "status.tags";
private static final String DOCKER_IMAGE_REPO = "status.dockerImageRepository";
private static final String SPEC_TAGS = "spec.tags";
private static final String STATUS_TAGS = "status.tags";
private static final String TAG = "tag";
private static final String ITEMS = "items";
private static final String IMAGE = "image";
private Map<String, String[]> propertyKeys;

public ImageStream(){
this(new ModelNode(), null, null);
}

public ImageStream(ModelNode node, IClient client, Map<String, String []> propertyKeys) {
super(node, client, propertyKeys);
this.propertyKeys = propertyKeys;
}

@Override
public void setDockerImageRepository(DockerImageURI uri) {
set(IMAGESTREAM_DOCKER_IMAGE_REPO, uri.getAbsoluteUri());
set(DOCKER_IMAGE_REPO, uri.getAbsoluteUri());
}

@Override
public DockerImageURI getDockerImageRepository() {
return new DockerImageURI(asString(IMAGESTREAM_DOCKER_IMAGE_REPO));
return new DockerImageURI(asString(DOCKER_IMAGE_REPO));
}


@Override
public Collection<String> getTagNames() {
ModelNode node = get(STATUS_TAGS);
if(!node.isDefined()) return new ArrayList<>();
return node.asList().stream().map(n->asString(n,TAG)).collect(Collectors.toList());
}

@Override
public Collection<ITagReference> getTags() {
ModelNode node = get(SPEC_TAGS);
if(!node.isDefined()) return new ArrayList<>();
return node.asList().stream().map(n->new TagReference(n, propertyKeys)).collect(Collectors.toList());
}

@Override
public void setTag(String newTag, String fromTag) {
ModelNode tags = get(IMAGESTREAM_SPEC_TAGS);
ModelNode tags = get(SPEC_TAGS);
ModelNode tag = new ModelNode();
tag.get("name").set(newTag);
ModelNode from = new ModelNode();
Expand All @@ -73,7 +95,7 @@ protected String getImageId(List<ModelNode> itemWrappers) {
@Override
public String getImageId(String tagName) {
String imageId = null;
ModelNode tags = get(IMAGESTREAM_STATUS_TAGS);
ModelNode tags = get(STATUS_TAGS);
if (tags.getType() != ModelType.LIST || tagName == null)
return null;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*******************************************************************************
* Copyright (c) 2016 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.image;

import static com.openshift.internal.util.JBossDmrExtentions.*;
import java.util.Map;

import org.jboss.dmr.ModelNode;

import com.openshift.internal.restclient.model.ModelNodeAdapter;
import com.openshift.internal.restclient.model.ObjectReference;
import com.openshift.internal.restclient.model.properties.ResourcePropertyKeys;
import com.openshift.restclient.model.IObjectReference;
import com.openshift.restclient.model.image.ITagReference;

public class TagReference extends ModelNodeAdapter implements ITagReference, ResourcePropertyKeys {

private static final String TAG_ANNOTATIONS = "annotations";

public TagReference(ModelNode node, Map<String, String[]> propertyKeys) {
super(node, propertyKeys);
}

@Override
public boolean isAnnotatedWith(String key) {
return getAnnotations().containsKey(key);
}

@Override
public String getAnnotation(String key) {
return getAnnotations().get(key);
}

@Override
public void setAnnotation(String key, String value) {
if(value == null) return;
ModelNode annotations = get(getNode(), getPropertyKeys(), TAG_ANNOTATIONS);
annotations.get(key).set(value);
}

@Override
public Map<String, String> getAnnotations() {
return asMap(getNode(), getPropertyKeys(), TAG_ANNOTATIONS);
}

@Override
public String getName() {
return asString(getNode(),getPropertyKeys(), NAME);
}

@Override
public IObjectReference getFrom() {
return new ObjectReference(get(getNode(), getPropertyKeys(), "from"));
}

}
45 changes: 45 additions & 0 deletions src/main/java/com/openshift/restclient/model/Annotatable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2016 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.restclient.model;

import java.util.Map;

public interface Annotatable {

/**
* Returns <code>true</code> if the resource is annotated with
* the given key
* @param key
* @return true if the annotation key exists
*/
boolean isAnnotatedWith(String key);

/**
* Retrieves the annotated value for the given key
* @param key
* @return
*/
String getAnnotation(String key);

/**
* Set the resource annotation
* @param key
* @param value
*/
void setAnnotation(String key, String value);

/**
* Retrieves the annotations associated with the resource
* @return
*/
Map<String, String> getAnnotations();

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@
* @author Jeff Cantrill
*/
public interface IBuildConfig extends IResource {


/**
* To defines an optional location to push the output of this build to.
* Kind must be one of 'ImageStreamTag' or 'DockerImage'.
* @return
*/
IObjectReference getBuildOutputReference();

/**
* Returns the source URL for a build
* @return
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/openshift/restclient/model/IImageStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
******************************************************************************/
package com.openshift.restclient.model;

import java.util.Collection;

import com.openshift.restclient.images.DockerImageURI;
import com.openshift.restclient.model.image.ITagReference;

/**
* @author Jeff Cantrill
Expand Down Expand Up @@ -38,4 +41,17 @@ public interface IImageStream extends IResource{
* @return
*/
String getImageId(String tagName);

/**
* The collection of tag references for this imagestream
* @return
*/
Collection<ITagReference> getTags();

/**
* The collection of tag names as listed
* in status.tags
* @return
*/
Collection<String> getTagNames();
}
30 changes: 1 addition & 29 deletions src/main/java/com/openshift/restclient/model/IResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @author Jeff Cantrill
*/
public interface IResource extends ICapable {
public interface IResource extends ICapable, Annotatable {

Map<String, String> getMetadata();

Expand Down Expand Up @@ -80,34 +80,6 @@ public interface IResource extends ICapable {
*/
void addLabel(String key, String value);

/**
* Returns <code>true</code> if the resource is annotated with
* the given key
* @param key
* @return true if the annotation key exists
*/
boolean isAnnotatedWith(String key);

/**
* Retrieves the annotated value for the given key
* @param key
* @return
*/
String getAnnotation(String key);

/**
* Set the resource annotation
* @param key
* @param value
*/
void setAnnotation(String key, String value);

/**
* Retrieves the annotations associated with the resource
* @return
*/
Map<String, String> getAnnotations();

String getResourceVersion();

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2016 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.restclient.model.image;

import com.openshift.restclient.model.Annotatable;
import com.openshift.restclient.model.IObjectReference;

public interface ITagReference extends Annotatable {

/**
* Returns the identifier for this reference
* @return
*/
String getName();

/**
* if specified, a reference to another image that this tag should point to.
* Valid values are ImageStreamTag, ImageStreamImage, and DockerImage.
* @return
*/
IObjectReference getFrom();

String toJson();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;

import java.util.Collection;
import java.util.stream.Collectors;

import org.jboss.dmr.ModelNode;
import org.junit.BeforeClass;
import org.junit.Test;
Expand All @@ -34,11 +37,18 @@ public class ImageStreamTest {
public static void setup(){
client = mock(IClient.class);
}


@Test
public void testGetTags() {
IImageStream stream = getImageStream();
Collection<String> tags = stream.getTags().stream().map(tr->tr.getName()).collect(Collectors.toList());
assertArrayEquals(new Object [] {"8.1", "latest"}, tags.toArray());
}

@Test
public void getDockerImageRepository() {
IImageStream repo = getImageStream();
assertEquals(new DockerImageURI("172.30.244.213:5000/test/origin-ruby-sample"), repo.getDockerImageRepository());
assertEquals(new DockerImageURI("172.30.224.48:5000/openshift/wildfly:latest"), repo.getDockerImageRepository());
}

@Test
Expand Down
Loading