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 @@ -415,6 +415,7 @@ private Map<String, String> getTypeMappings(String apiVersion){
typeMappings.put(ResourceKind.DEPLOYMENT_CONFIG, osEndpoint);
typeMappings.put(ResourceKind.IMAGE_STREAM, osEndpoint);
typeMappings.put(ResourceKind.IMAGE_STREAM_TAG, osEndpoint);
typeMappings.put(ResourceKind.IMAGE_STREAM_IMPORT, osEndpoint);
typeMappings.put(ResourceKind.OAUTH_ACCESS_TOKEN, osEndpoint);
typeMappings.put(ResourceKind.OAUTH_AUTHORIZE_TOKEN, osEndpoint);
typeMappings.put(ResourceKind.OAUTH_CLIENT, osEndpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.openshift.internal.restclient.model.authorization.PolicyBinding;
import com.openshift.internal.restclient.model.authorization.RoleBinding;
import com.openshift.internal.restclient.model.build.BuildRequest;
import com.openshift.internal.restclient.model.image.ImageStreamImport;
import com.openshift.internal.restclient.model.oauth.OAuthAccessToken;
import com.openshift.internal.restclient.model.oauth.OAuthAuthorizeToken;
import com.openshift.internal.restclient.model.oauth.OAuthClient;
Expand Down Expand Up @@ -79,6 +80,7 @@ public class ResourceFactory implements IResourceFactory{
IMPL_MAP.put(ResourceKind.CONFIG, Config.class);
IMPL_MAP.put(ResourceKind.DEPLOYMENT_CONFIG, DeploymentConfig.class);
IMPL_MAP.put(ResourceKind.IMAGE_STREAM, ImageStream.class);
IMPL_MAP.put(ResourceKind.IMAGE_STREAM_IMPORT, ImageStreamImport.class);
IMPL_MAP.put(ResourceKind.LIST, com.openshift.internal.restclient.model.List.class);
IMPL_MAP.put(ResourceKind.OAUTH_ACCESS_TOKEN, OAuthAccessToken.class);
IMPL_MAP.put(ResourceKind.OAUTH_AUTHORIZE_TOKEN, OAuthAuthorizeToken.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.openshift.internal.restclient.capability.resources.DeployCapability;
import com.openshift.internal.restclient.capability.resources.DeploymentConfigTraceability;
import com.openshift.internal.restclient.capability.resources.DeploymentTraceability;
import com.openshift.internal.restclient.capability.resources.ImageStreamImportCapability;
import com.openshift.internal.restclient.capability.resources.OpenShiftBinaryPodLogRetrieval;
import com.openshift.internal.restclient.capability.resources.OpenShiftBinaryPortForwarding;
import com.openshift.internal.restclient.capability.resources.OpenShiftBinaryRSync;
Expand All @@ -34,6 +35,7 @@
import com.openshift.restclient.capability.resources.IDeployCapability;
import com.openshift.restclient.capability.resources.IDeploymentConfigTraceability;
import com.openshift.restclient.capability.resources.IDeploymentTraceability;
import com.openshift.restclient.capability.resources.IImageStreamImportCapability;
import com.openshift.restclient.capability.resources.IPodLogRetrieval;
import com.openshift.restclient.capability.resources.IPortForwardable;
import com.openshift.restclient.capability.resources.IProjectTemplateList;
Expand Down Expand Up @@ -108,6 +110,7 @@ public static void initializeCapabilities(Map<Class<? extends ICapability>, ICap
public static void initializeCapabilities(Map<Class<? extends ICapability>, ICapability> capabilities, IProject project, IClient client){
initializeCapability(capabilities, IProjectTemplateProcessing.class, new ProjectTemplateProcessing(project, client));
initializeCapability(capabilities, IProjectTemplateList.class, new ProjectTemplateListCapability(project, client));
initializeCapability(capabilities, IImageStreamImportCapability.class, new ImageStreamImportCapability(project, client));
}

public static void initializeCapabilities(Map<Class<? extends ICapability>, ICapability> capabilities, Service service, IClient client){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ public String getName() {
public void deploy() {
try {
final String deploymentName = getLatestDeploymentName();
LOG.debug("Attempting to deploy latest deployment for config '%s'. Loading deployment: '%s'", config.getName(), deploymentName);
LOG.debug("Attempting to deploy latest deployment for config %s. Loading deployment: %s", config.getName(), deploymentName);
IReplicationController deployment = client.get(ResourceKind.REPLICATION_CONTROLLER, deploymentName, config.getNamespace());
final String status = getStatusFor(deployment);
if(!COMPLETED_STATES.contains(status)) {
LOG.debug("Skipping deployment because deployment status '%s' for '%s' is not in %s", new Object [] {status, deploymentName, COMPLETED_STATES});
LOG.debug("Skipping deployment because deployment status %s for %s is not in %s", new Object [] {status, deploymentName, COMPLETED_STATES});
return;
}
}catch(OpenShiftException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*******************************************************************************
* 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.capability.resources;

import com.openshift.restclient.IClient;
import com.openshift.restclient.ResourceKind;
import com.openshift.restclient.capability.resources.IImageStreamImportCapability;
import com.openshift.restclient.images.DockerImageURI;
import com.openshift.restclient.model.IProject;
import com.openshift.restclient.model.image.IImageStreamImport;

/**
*
* @author jeff.cantrill
*
*/
public class ImageStreamImportCapability implements IImageStreamImportCapability {

private IClient client;
private IProject project;

public ImageStreamImportCapability(IProject project, IClient client) {
this.project = project;
this.client = client;
}

@Override
public IImageStreamImport importImageMetadata(DockerImageURI uri) {

IImageStreamImport streamImport = client.getResourceFactory().stub(ResourceKind.IMAGE_STREAM_IMPORT, "jbosstools-openshift-deployimage", project.getName());
streamImport.setImport(false);
streamImport.addImage("DockerImage", uri);
return client.create(streamImport);
}


@Override
public boolean isSupported() {
return true;
}

@Override
public String getName() {
return ImageStreamImportCapability.class.getSimpleName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
public class ImageStream extends KubernetesResource implements IImageStream {

private static final String DOCKER_IMAGE_REPO = "status.dockerImageRepository";
private static final String DOCKER_IMAGE_REPO = "spec.dockerImageRepository";
private static final String SPEC_TAGS = "spec.tags";
private static final String STATUS_TAGS = "status.tags";
private static final String TAG = "tag";
Expand All @@ -44,17 +44,21 @@ public ImageStream(ModelNode node, IClient client, Map<String, String []> proper
super(node, client, propertyKeys);
this.propertyKeys = propertyKeys;
}

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

@Override
public void setDockerImageRepository(String uri) {
set(DOCKER_IMAGE_REPO, uri);
}

@Override
public DockerImageURI getDockerImageRepository() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the difference to #getDockerImageRepositorySpec?

return new DockerImageURI(asString(DOCKER_IMAGE_REPO));
}


@Override
public Collection<String> getTagNames() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ public boolean isAnnotatedWith(String key) {
return annotations.containsKey(key);
}

protected Map<String, String []> getPropertyKeys(){
return this.propertyKeys;
}

public IClient getClient(){
return client;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*******************************************************************************
* 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 java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;

import org.jboss.dmr.ModelNode;

import com.openshift.internal.restclient.model.KubernetesResource;
import com.openshift.internal.restclient.model.Status;
import com.openshift.restclient.IClient;
import com.openshift.restclient.images.DockerImageURI;
import com.openshift.restclient.model.IStatus;
import com.openshift.restclient.model.image.IImageStreamImport;

/**
*
* @author jeff.cantrill
*
*/
public class ImageStreamImport extends KubernetesResource implements IImageStreamImport {

private static final String IMAGE_DOCKER_IMAGE_REFERENCE = "image.dockerImageReference";
private static final String STATUS = "status";
private static final String STATUS_IMAGES = "status.images";
private static final String FROM_KIND = "from.kind";
private static final String SPEC_IMAGES = "spec.images";
private static final String SPEC_IMPORT = "spec.import";

public ImageStreamImport(ModelNode node, IClient client, Map<String, String[]> overrideProperties) {
super(node, client, overrideProperties);
}

@Override
public void setImport(boolean importTags) {
set(SPEC_IMPORT, importTags);
}

@Override
public boolean isImport() {
return asBoolean(SPEC_IMPORT);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the meaning of this method? What does it answer? (it's missing javadoc in the interface)

}

@Override
public void addImage(String fromKind, DockerImageURI imageUri) {
ModelNode image = new ModelNode();
set(image, FROM_KIND, fromKind);
set(image, "from.name", imageUri.getUriWithoutTag());
get(SPEC_IMAGES).add(image);
}

@Override
public Collection<IStatus> getImageStatus() {
Collection<IStatus> status = new ArrayList<>();
ModelNode images = get(STATUS_IMAGES);
if(images.isDefined()) {
images.asList()
.stream()
.filter(n->get(n,STATUS).isDefined())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're only returning images that have a status. Why wont certain have one?

.forEach(n->status.add(new Status(get(n,STATUS), getClient(), getPropertyKeys())));
}
return status;
}

@Override
public String getImageJsonFor(DockerImageURI uri) {
String prefix = uri.getUriWithoutTag();
ModelNode images = get(STATUS_IMAGES);
if(images.isDefined()) {
Optional<ModelNode> node = images.asList()
.stream()
.filter(n->asString(n, IMAGE_DOCKER_IMAGE_REFERENCE).startsWith(prefix))
.findFirst();
if(node.isPresent()) {
return node.get().toJSONString(true);
}
}
return null;
}

}
3 changes: 3 additions & 0 deletions src/main/java/com/openshift/restclient/ResourceKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public final class ResourceKind {
public static final String DEPLOYMENT_CONFIG = "DeploymentConfig";
public static final String IMAGE_STREAM = "ImageStream";
public static final String IMAGE_STREAM_TAG = "ImageStreamTag";
public static final String IMAGE_STREAM_IMPORT = "ImageStreamImport";
public static final String OAUTH_ACCESS_TOKEN = "OAuthAccessToken";
public static final String OAUTH_AUTHORIZE_TOKEN = "OAuthAuthorizeToken";
public static final String OAUTH_CLIENT = "OAuthClient";
Expand Down Expand Up @@ -89,6 +90,8 @@ public static String pluralize(String kind) {
set.add(BUILD_CONFIG);
set.add(DEPLOYMENT_CONFIG);
set.add(IMAGE_STREAM );
set.add(IMAGE_STREAM_TAG);
set.add(IMAGE_STREAM_IMPORT);
set.add(OAUTH_ACCESS_TOKEN);
set.add(OAUTH_AUTHORIZE_TOKEN);
set.add(OAUTH_CLIENT);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*******************************************************************************
* 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.capability.resources;

import com.openshift.restclient.capability.ICapability;
import com.openshift.restclient.images.DockerImageURI;
import com.openshift.restclient.model.image.IImageStreamImport;

/**
* Import tags from a repository for an image
*
* @author jeff.cantrill
*
*/
public interface IImageStreamImportCapability extends ICapability {

/**
* Import docker image metadata
* @param uri
* @return
* @throws OpenShiftException
*/
IImageStreamImport importImageMetadata(DockerImageURI uri);

}
16 changes: 14 additions & 2 deletions src/main/java/com/openshift/restclient/model/IImageStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,26 @@
public interface IImageStream extends IResource{

/**
* Retrieve the docker image URI for which this image repository
* is responsible
* Get the image repository uri abstracted by this
* image stream
* @return
*/
DockerImageURI getDockerImageRepository();

/**
* Set the image repository uri abstracted by this
* image stream
* @return
*/
void setDockerImageRepository(DockerImageURI imageUri);

/**
* Set the image repository uri abstracted by this
* image stream
* @return
*/
void setDockerImageRepository(String imageUri);

/**
* Sets a new tag in an image stream
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*******************************************************************************
* 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 java.util.Collection;

import com.openshift.restclient.images.DockerImageURI;
import com.openshift.restclient.model.IResource;
import com.openshift.restclient.model.IStatus;

/**
*
* @author jeff.cantrill
*
*/
public interface IImageStreamImport extends IResource {

/**
* Set to true to import tags for the imagestream; false to just retrieve
* @param importTags
*/
void setImport(boolean importTags);

/**
* Are the tags to be imported for the imagestream
* @return true if import; false otherwise
*/
boolean isImport();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this method for? missing javadoc to explain it


/**
* Add image info those being imorted
* @param fromKind The indirection of where to find the image.
* Typically is DockerImage, ImageStreamTag
* @param uriWithoutTag
*/
void addImage(String fromKind, DockerImageURI imageUri);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as a user of this API, can I call this? What can I do with it? I guess that if I can, I'll subsequently have to do something more?
what is fromKind? dare maybe add "@see" in javadoc and explain?


/**
* The status of the image retrieval
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in what status can image retrieval be? RUNNING? SUCCESSFULL? FAILED?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are status constructs which are complex types returned from various calls.

* @return
*/
Collection<IStatus> getImageStatus();

/**
* Get the raw json docker metadata for
* the given uir. Tries to match uri without tag
* to the beginning of image.dockerImageReference
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this trigger the import or is it unrelated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result of posting this resource grabs the tags and returns them to you. This allows you to get the raw json to further inspect. I don't know if this content maps directly to docker structures and I didn't want to add a dependency to the linux docker tooling here. Additionally, I dont know if it was worth trying to add a class to represent this info. It would be really nice if we could get items without having to return a class; walking across arrays is still a problem

* @param uri
* @return json string or null if not matched.
*/
String getImageJsonFor(DockerImageURI uri);
}
Loading