use of com.openshift.restclient.images.DockerImageURI in project jbosstools-openshift by jbosstools.
the class DockerImageLabels method load.
/**
* Loads the docker image meta data for a given resource. The given resource is
* used to infer a deployment config which then is used to determined the docker
* image being used. The meta data of this docker image is then loaded.
*
* @param reosurce
* the openshift resource to load the image metadata for
* @return
*/
protected String load(IResource resource) {
IDeploymentConfig dc = ResourceUtils.getDeploymentConfigFor(resource, connection);
if (dc == null) {
return null;
}
IDeploymentImageChangeTrigger trigger = getImageChangeTrigger(dc.getTriggers());
if (trigger == null) {
return null;
}
DockerImageURI uri = trigger.getFrom();
return getImageStreamTag(uri, resource.getNamespaceName());
// String imageRef = getImageRef(dc, connection);
// int imageDigestIndex = imageRef.indexOf(DOCKER_IMAGE_DIGEST_IDENTIFIER);
// if (imageDigestIndex > 0) {
// String imageDigest = imageRef.substring(imageDigestIndex);
// return getImageStreamTag(imageDigest, imageRef, project.getName(), connection);
// } else {
// IImageStream imageStream = connection.getResource(ResourceKind.IMAGE_STREAM, project.getName(), imageRef);
// if ( imageStream != null) {
// // DockerImageURI uri = imageStream.getDockerImageRepository();
// // return importImageStream(uri.getAbsoluteUri(), project);
// IDockerImageMetadata metadata = DockerImageUtils.lookupImageMetadata(project, uri);
// return metadata.toString();
// } else {
// return importImageStream(imageRef, project);
// }
// }
}
use of com.openshift.restclient.images.DockerImageURI in project jbosstools-openshift by jbosstools.
the class OpenshiftEapProfileDetectorTest method createBuildConfig.
@SuppressWarnings("deprecation")
private IBuildConfig createBuildConfig(Class<? extends IBuildStrategy> clazz, String name) {
IBuildConfig bc = mock(IBuildConfig.class);
DockerImageURI image = mock(DockerImageURI.class);
when(image.getName()).thenReturn(name);
IBuildStrategy strategy = null;
if (clazz == null) {
strategy = mock(ISourceBuildStrategy.class);
} else if (IDockerBuildStrategy.class.isAssignableFrom(clazz)) {
IDockerBuildStrategy dbs = mock(IDockerBuildStrategy.class);
when(dbs.getBaseImage()).thenReturn(image);
strategy = dbs;
} else if (ICustomBuildStrategy.class.isAssignableFrom(clazz)) {
ICustomBuildStrategy cbs = mock(ICustomBuildStrategy.class);
when(cbs.getImage()).thenReturn(image);
strategy = cbs;
} else if (ISTIBuildStrategy.class.isAssignableFrom(clazz)) {
ISTIBuildStrategy sts = mock(ISTIBuildStrategy.class);
when(sts.getImage()).thenReturn(image);
strategy = sts;
} else if (ISourceBuildStrategy.class.isAssignableFrom(clazz)) {
ISourceBuildStrategy sbs = mock(ISourceBuildStrategy.class);
when(sbs.getImage()).thenReturn(image);
strategy = sbs;
}
when(bc.getBuildStrategy()).thenReturn(strategy);
Map<String, String> labels = Collections.singletonMap("template", name);
when(bc.getLabels()).thenReturn(labels);
return bc;
}
use of com.openshift.restclient.images.DockerImageURI in project jbosstools-openshift by jbosstools.
the class ResourceMocks method createSourceBuildStrategy.
public static IBuildStrategy createSourceBuildStrategy(String uri) {
DockerImageURI dockerUri = mock(DockerImageURI.class);
doReturn(uri).when(dockerUri).getAbsoluteUri();
ISourceBuildStrategy strategy = mock(ISourceBuildStrategy.class);
doReturn(BuildStrategyType.SOURCE).when(strategy).getType();
doReturn(dockerUri).when(strategy).getImage();
return strategy;
}
use of com.openshift.restclient.images.DockerImageURI in project jbosstools-openshift by jbosstools.
the class ResourceMocks method createDeploymentImageChangeTrigger.
/**
* Returns a mock of a {@link IDeploymentImageChangeTrigger} of the given type and with the given (from-) uri.
* @param type
* @param uri
* @return
*
* @see #mockGetTriggers(List, IDeploymentConfig)
*/
public static IDeploymentImageChangeTrigger createDeploymentImageChangeTrigger(String type, String uri) {
IDeploymentImageChangeTrigger trigger = mock(IDeploymentImageChangeTrigger.class);
doReturn(new DockerImageURI(uri)).when(trigger).getFrom();
doReturn(type).when(trigger).getType();
return trigger;
}
use of com.openshift.restclient.images.DockerImageURI in project jbosstools-openshift by jbosstools.
the class DeployImageJob method updateTriggerIfUpdate.
protected boolean updateTriggerIfUpdate(Connection connection, String project, String name) {
try {
IDeploymentConfig dc = connection.getResource(ResourceKind.DEPLOYMENT_CONFIG, project, name);
IDeploymentImageChangeTrigger trigger = (IDeploymentImageChangeTrigger) dc.getTriggers().stream().filter(t -> DeploymentTriggerType.IMAGE_CHANGE.equals(t.getType())).findFirst().orElse(null);
if (trigger == null || !ResourceKind.IMAGE_STREAM_TAG.equals(trigger.getKind()) || StringUtils.isBlank(trigger.getNamespace()) || connection.getResource(ResourceKind.IMAGE_STREAM, trigger.getNamespace(), trigger.getFrom().getName()) == null) {
return false;
}
DockerImageURI sourceImage = getSourceImage();
if (sourceImage.getName().equals(trigger.getFrom().getName()) && !sourceImage.getTag().equals(trigger.getFrom().getTag())) {
trigger.setFrom(new DockerImageURI(null, null, sourceImage.getName(), sourceImage.getTag()));
connection.updateResource(dc);
}
return true;
} catch (NotFoundException e) {
return false;
} catch (OpenShiftException e) {
if (e.getStatus() != null && e.getStatus().getCode() == IHttpConstants.STATUS_NOT_FOUND) {
return false;
}
throw e;
}
}
Aggregations