use of com.openshift.restclient.model.IDeploymentConfig 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.IDeploymentConfig in project jbosstools-openshift by jbosstools.
the class ManageEnvironmentVariablesWizard method findReplicationController.
/**
* If a replication controller is selected, method returns it.
* If a deployment config is selected, method returns it.
* If a deployment is selected, method finds a deployment config and returns it.
* @param event
* @return
*/
IReplicationController findReplicationController(ExecutionEvent event) {
ISelection selection = UIUtils.getCurrentSelection(event);
IDeploymentConfig dc = UIUtils.getFirstElement(selection, IDeploymentConfig.class);
if (dc != null) {
return dc;
}
IReplicationController rc = UIUtils.getFirstElement(selection, IReplicationController.class);
if (rc != null) {
return rc;
}
IServiceWrapper deployment = UIUtils.getFirstElement(selection, IServiceWrapper.class);
Collection<IResourceWrapper<?, ?>> dcs = deployment.getResourcesOfKind(ResourceKind.DEPLOYMENT_CONFIG);
if (!dcs.isEmpty()) {
dc = (IDeploymentConfig) dcs.iterator().next().getWrapped();
if (dc != null) {
return dc;
}
}
return null;
}
use of com.openshift.restclient.model.IDeploymentConfig in project jbosstools-openshift by jbosstools.
the class ScaleDeploymentHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IDeploymentConfig dc = getDeploymentConfig(getSelectedElement(event, IResourceWrapper.class));
if (dc == null) {
IResource resource = ResourceWrapperUtils.getResource(UIUtils.getFirstElement(HandlerUtil.getCurrentSelection(event)));
return OpenShiftUIActivator.statusFactory().errorStatus(NLS.bind("Could not scale {0}: Could not find deployment config", resource == null ? "" : resource.getName()));
}
scaleUsing(event, dc, dc.getName());
return null;
}
use of com.openshift.restclient.model.IDeploymentConfig in project jbosstools-openshift by jbosstools.
the class ServerResourceViewModelWithDeploymentConfigTest method shouldReturn1stServiceInListIfInitializedServiceIsNotInListOfAllDeploymentConfigs.
@Test
public void shouldReturn1stServiceInListIfInitializedServiceIsNotInListOfAllDeploymentConfigs() {
// given
IDeploymentConfig otherDeploymentConfig = ResourceMocks.createResource(IDeploymentConfig.class, ResourceKind.DEPLOYMENT_CONFIG);
ServerResourceViewModel model = new ServerResourceViewModel(otherDeploymentConfig, connection);
model.loadResources();
// when
IResource service = model.getResource();
// then
assertThat(service).isEqualTo(ResourceMocks.PROJECT2_SERVICES[0]);
}
use of com.openshift.restclient.model.IDeploymentConfig in project jbosstools-openshift by jbosstools.
the class ResourceUtils method getDeploymentConfigFor.
private static IDeploymentConfig getDeploymentConfigFor(IService service, Connection connection) {
if (service == null) {
return null;
}
String dcName = getDeploymentConfigNameFor(service);
if (dcName != null) {
return getDeploymentConfigByName(dcName, service, connection);
} else {
String namespace = service.getNamespaceName();
IReplicationController rc = getReplicationControllerFor(service, connection.getResources(ResourceKind.REPLICATION_CONTROLLER, namespace));
if (rc == null) {
return null;
}
List<IPod> allPods = connection.getResources(ResourceKind.POD, namespace);
List<IPod> pods = allPods.stream().filter(pod -> areRelated((IPod) pod, rc)).collect(Collectors.toList());
if (CollectionUtils.isEmpty(pods)) {
return null;
}
List<IDeploymentConfig> dcs = connection.getResources(ResourceKind.DEPLOYMENT_CONFIG, namespace);
return dcs.stream().filter(dc -> areRelated((IService) service, (IDeploymentConfig) dc, pods)).findFirst().orElse(null);
}
}
Aggregations