-
Notifications
You must be signed in to change notification settings - Fork 111
[JBIDE-21626] Add ImageStreamImport Capability #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
|---|---|---|
| @@ -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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
|
|
||
| } | ||
| 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); | ||
|
|
||
| } |
| 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(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
|
|
||
| /** | ||
| * The status of the image retrieval | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in what status can image retrieval be? RUNNING? SUCCESSFULL? FAILED?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| * | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this trigger the import or is it unrelated?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| } | ||
There was a problem hiding this comment.
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?