use of com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger 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.model.deploy.IDeploymentImageChangeTrigger 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.model.deploy.IDeploymentImageChangeTrigger 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;
}
}
use of com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger in project jbosstools-openshift by jbosstools.
the class DeployImageJob method stubDeploymentConfig.
protected IResource stubDeploymentConfig(IResourceFactory factory, final String name, DockerImageURI imageUri, IImageStream is) {
IDeploymentConfig dc = factory.stub(ResourceKind.DEPLOYMENT_CONFIG, name, parameters.getProject().getName());
dc.addLabel(SELECTOR_KEY, name);
dc.addTemplateLabel(SELECTOR_KEY, name);
for (Label label : parameters.getLabels()) {
dc.addTemplateLabel(label.getName(), label.getValue());
}
dc.setReplicas(parameters.getReplicas());
dc.setReplicaSelector(SELECTOR_KEY, name);
Map<String, String> envs = getModifiedEnvVars(parameters.getEnvironmentVariables(), parameters.getImageEnvVars());
dc.addContainer(dc.getName(), imageUri, new HashSet<>(parameters.getPortSpecs()), envs, parameters.getVolumes());
dc.addTrigger(DeploymentTriggerType.CONFIG_CHANGE);
if (is != null) {
IDeploymentImageChangeTrigger imageChangeTrigger = (IDeploymentImageChangeTrigger) dc.addTrigger(DeploymentTriggerType.IMAGE_CHANGE);
imageChangeTrigger.setAutomatic(true);
imageChangeTrigger.setContainerName(name);
imageChangeTrigger.setFrom(new DockerImageURI(null, null, is.getName(), imageUri.getTag()));
imageChangeTrigger.setKind(ResourceKind.IMAGE_STREAM_TAG);
imageChangeTrigger.setNamespace(is.getNamespaceName());
}
return dc;
}
use of com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger in project jbosstools-openshift by jbosstools.
the class DockerImageLabelsTest method setup.
@Before
public void setup() throws IOException {
this.connection = createConnection("https://localhost:8181", "aUser");
this.labelsThatFailsToLoad = spy(new TestableDockerImageLabels(null, connection));
this.dc = ResourceMocks.createDeploymentConfig("aDeploymentConfig", ResourceMocks.createProject("aProject"), null, null);
IDeploymentImageChangeTrigger trigger = ResourceMocks.createDeploymentImageChangeTrigger(DeploymentTriggerType.IMAGE_CHANGE, "nodejs:latest");
ResourceMocks.mockGetTriggers(Collections.singletonList(trigger), dc);
IResource imageStreamTag = mockImageStreamTag(NODEJS_IMAGESTREAM_TAG_URL);
doReturn(imageStreamTag).when(connection).getResource(eq(ResourceKind.IMAGE_STREAM_TAG), anyString(), anyString());
this.labels = spy(new TestableDockerImageLabels(dc, connection));
}
Aggregations