Search in sources :

Example 1 with NotFoundException

use of com.openshift.restclient.NotFoundException 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;
    }
}
Also used : ResourceCreationJobUtils.findExistingResources(org.jboss.tools.openshift.internal.ui.job.ResourceCreationJobUtils.findExistingResources) StringUtils(org.apache.commons.lang.StringUtils) IImageStream(com.openshift.restclient.model.IImageStream) HashMap(java.util.HashMap) AbstractDelegatingMonitorJob(org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob) DockerImageUtils(org.jboss.tools.openshift.internal.core.docker.DockerImageUtils) OpenShiftException(com.openshift.restclient.OpenShiftException) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) IProject(com.openshift.restclient.model.IProject) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ITargetPort(com.openshift.restclient.model.route.ITargetPort) IStatus(org.eclipse.core.runtime.IStatus) Map(java.util.Map) NotFoundException(com.openshift.restclient.NotFoundException) IResourceFactory(com.openshift.restclient.IResourceFactory) Trace(org.jboss.tools.openshift.internal.core.Trace) OpenShiftUIActivator(org.jboss.tools.openshift.internal.ui.OpenShiftUIActivator) IService(com.openshift.restclient.model.IService) ResourceCreationJobUtils.createErrorStatusForExistingResources(org.jboss.tools.openshift.internal.ui.job.ResourceCreationJobUtils.createErrorStatusForExistingResources) IHttpConstants(com.openshift.restclient.http.IHttpConstants) DockerImageURI(com.openshift.restclient.images.DockerImageURI) IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) NLS(org.eclipse.osgi.util.NLS) Label(org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label) Collection(java.util.Collection) Status(org.eclipse.core.runtime.Status) Connection(org.jboss.tools.openshift.core.connection.Connection) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IDeployImageParameters(org.jboss.tools.openshift.internal.ui.wizard.deployimage.IDeployImageParameters) List(java.util.List) ICommonAttributes(org.jboss.tools.openshift.core.ICommonAttributes) OpenShiftAPIAnnotations(org.jboss.tools.openshift.core.OpenShiftAPIAnnotations) IServicePort(com.openshift.restclient.model.IServicePort) IRoute(com.openshift.restclient.model.route.IRoute) DeploymentTriggerType(com.openshift.restclient.model.deploy.DeploymentTriggerType) Collections(java.util.Collections) EnvironmentVariable(org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable) DockerImageURI(com.openshift.restclient.images.DockerImageURI) OpenShiftException(com.openshift.restclient.OpenShiftException) NotFoundException(com.openshift.restclient.NotFoundException) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger)

Aggregations

IResourceFactory (com.openshift.restclient.IResourceFactory)1 NotFoundException (com.openshift.restclient.NotFoundException)1 OpenShiftException (com.openshift.restclient.OpenShiftException)1 ResourceKind (com.openshift.restclient.ResourceKind)1 IHttpConstants (com.openshift.restclient.http.IHttpConstants)1 DockerImageURI (com.openshift.restclient.images.DockerImageURI)1 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)1 IImageStream (com.openshift.restclient.model.IImageStream)1 IProject (com.openshift.restclient.model.IProject)1 IResource (com.openshift.restclient.model.IResource)1 IService (com.openshift.restclient.model.IService)1 IServicePort (com.openshift.restclient.model.IServicePort)1 DeploymentTriggerType (com.openshift.restclient.model.deploy.DeploymentTriggerType)1 IDeploymentImageChangeTrigger (com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger)1 IRoute (com.openshift.restclient.model.route.IRoute)1 ITargetPort (com.openshift.restclient.model.route.ITargetPort)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1