Search in sources :

Example 1 with IDeploymentConfig

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);
// }
// }
}
Also used : DockerImageURI(com.openshift.restclient.images.DockerImageURI) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger)

Example 2 with IDeploymentConfig

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;
}
Also used : IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) IServiceWrapper(org.jboss.tools.openshift.internal.ui.models.IServiceWrapper) ISelection(org.eclipse.jface.viewers.ISelection) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IReplicationController(com.openshift.restclient.model.IReplicationController)

Example 3 with IDeploymentConfig

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;
}
Also used : IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IResource(com.openshift.restclient.model.IResource)

Example 4 with IDeploymentConfig

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]);
}
Also used : ServerResourceViewModel(org.jboss.tools.openshift.internal.ui.server.ServerResourceViewModel) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IResource(com.openshift.restclient.model.IResource) Test(org.junit.Test)

Example 5 with IDeploymentConfig

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);
    }
}
Also used : Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) IBuildConfig(com.openshift.restclient.model.IBuildConfig) KeyValueFilterFactory(org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) IProject(com.openshift.restclient.model.IProject) HashSet(java.util.HashSet) IPod(com.openshift.restclient.model.IPod) IClientCapability(com.openshift.restclient.capability.resources.IClientCapability) CollectionUtils(org.apache.commons.collections.CollectionUtils) EGitUtils(org.jboss.tools.openshift.egit.core.EGitUtils) Map(java.util.Map) KeyValueFilter(org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory.KeyValueFilter) URIish(org.eclipse.jgit.transport.URIish) OpenShiftResourceSelectors(org.jboss.tools.openshift.core.OpenShiftResourceSelectors) ITags(com.openshift.restclient.capability.resources.ITags) IImageStreamImport(com.openshift.restclient.model.image.IImageStreamImport) StatusFactory(org.jboss.tools.foundation.core.plugin.log.StatusFactory) IService(com.openshift.restclient.model.IService) IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) MapUtils(org.apache.commons.collections.MapUtils) NLS(org.eclipse.osgi.util.NLS) Collection(java.util.Collection) IBuild(com.openshift.restclient.model.IBuild) Set(java.util.Set) OpenShiftCoreActivator(org.jboss.tools.openshift.internal.core.OpenShiftCoreActivator) Collectors(java.util.stream.Collectors) IObjectReference(com.openshift.restclient.model.IObjectReference) Connection(org.jboss.tools.openshift.core.connection.Connection) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) OpenShiftAPIAnnotations(org.jboss.tools.openshift.core.OpenShiftAPIAnnotations) IClient(com.openshift.restclient.IClient) CapabilityVisitor(com.openshift.restclient.capability.CapabilityVisitor) IRoute(com.openshift.restclient.model.route.IRoute) Optional(java.util.Optional) ModelNode(org.jboss.dmr.ModelNode) Comparator(java.util.Comparator) Collections(java.util.Collections) IReplicationController(com.openshift.restclient.model.IReplicationController) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IReplicationController(com.openshift.restclient.model.IReplicationController) IPod(com.openshift.restclient.model.IPod) IService(com.openshift.restclient.model.IService)

Aggregations

IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)24 Test (org.junit.Test)11 Connection (org.jboss.tools.openshift.core.connection.Connection)9 IResource (com.openshift.restclient.model.IResource)8 IService (com.openshift.restclient.model.IService)7 IDeploymentImageChangeTrigger (com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger)7 DockerImageURI (com.openshift.restclient.images.DockerImageURI)6 IProject (com.openshift.restclient.model.IProject)5 Collection (java.util.Collection)4 ResourceKind (com.openshift.restclient.ResourceKind)3 IImageStream (com.openshift.restclient.model.IImageStream)3 IReplicationController (com.openshift.restclient.model.IReplicationController)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3 List (java.util.List)3 IServiceWrapper (org.jboss.tools.openshift.internal.ui.models.IServiceWrapper)3 IClient (com.openshift.restclient.IClient)2 IResourceFactory (com.openshift.restclient.IResourceFactory)2 IPod (com.openshift.restclient.model.IPod)2