Search in sources :

Example 26 with IBuildConfig

use of com.openshift.restclient.model.IBuildConfig in project jbosstools-openshift by jbosstools.

the class NewApplicationWizard method performFinish.

@Override
public boolean performFinish() {
    final IResourcesModelJob createJob = isTemplateFlow() ? fromTemplateModel.createFinishJob() : fromImageModel.createFinishJob();
    createJob.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            IStatus status = event.getResult();
            if (JobUtils.isOk(status) || JobUtils.isWarning(status)) {
                Display.getDefault().syncExec(createJob.getSummaryRunnable(getShell()));
                OpenShiftUIUtils.showOpenShiftExplorer();
                if (model.getEclipseProject() != null) {
                    // No need to import the project from git, it's already here
                    return;
                }
                Collection<IResource> resources = createJob.getResources();
                final Map<IProject, Collection<IBuildConfig>> projectsAndBuildConfigs = getBuildConfigs(resources);
                if (projectsAndBuildConfigs.isEmpty()) {
                    return;
                }
                Connection connection = model.getConnection();
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        ImportApplicationWizard wizard = new ImportApplicationWizard(projectsAndBuildConfigs);
                        wizard.addImportJobChangeListener(new JobChangeAdapter() {

                            @Override
                            public void done(IJobChangeEvent event) {
                                IService service = getService(resources);
                                List<org.eclipse.core.resources.IProject> importedProjects = wizard.getImportJob().getImportedProjects();
                                if (service != null && importedProjects.size() == 1) {
                                    Display.getDefault().asyncExec(new Runnable() {

                                        @Override
                                        public void run() {
                                            if (MessageDialog.openQuestion(getShell(), "Create server adapter", NLS.bind("Would you like to create a server adapter for the imported {0} project?", importedProjects.get(0).getName()))) {
                                                createServerAdapter(importedProjects.get(0), connection, service, getRoute(resources));
                                            }
                                        }
                                    });
                                }
                            }
                        });
                        new WizardDialog(getShell(), wizard).open();
                    }
                });
            }
        }

        protected Map<IProject, Collection<IBuildConfig>> getBuildConfigs(Collection<IResource> resources) {
            Map<IProject, Collection<IBuildConfig>> projects = new LinkedHashMap<>();
            for (IResource resource : resources) {
                if (resource instanceof IBuildConfig) {
                    IBuildConfig buildConfig = (IBuildConfig) resource;
                    if (StringUtils.isNotBlank(buildConfig.getSourceURI())) {
                        IProject p = buildConfig.getProject();
                        Collection<IBuildConfig> buildConfigs = projects.get(p);
                        if (buildConfigs == null) {
                            buildConfigs = new LinkedHashSet<>();
                            projects.put(p, buildConfigs);
                        }
                        buildConfigs.add(buildConfig);
                    }
                }
            }
            return projects;
        }

        protected IService getService(Collection<IResource> resources) {
            IResource service = getResourceOfType(resources, IService.class);
            return service == null ? null : (IService) service;
        }

        protected IRoute getRoute(Collection<IResource> resources) {
            IResource route = getResourceOfType(resources, IRoute.class);
            return route == null ? null : (IRoute) route;
        }

        private IResource getResourceOfType(Collection<IResource> resources, Class<? extends IResource> type) {
            for (IResource resource : resources) {
                if (type.isInstance(resource)) {
                    return resource;
                }
            }
            return null;
        }

        protected void createServerAdapter(org.eclipse.core.resources.IProject project, Connection connection, IService service, IRoute route) {
            try {
                IServerWorkingCopy server = OpenShiftServerUtils.create(OpenShiftResourceUniqueId.get(service));
                ServerSettingsWizardPageModel serverModel = new ServerSettingsWizardPageModel(service, route, project, connection, server, OCBinary.getInstance().getStatus(connection, new NullProgressMonitor()), RSyncValidator.get().getStatus());
                serverModel.loadResources();
                serverModel.updateServer();
                server.setAttribute(OpenShiftServerUtils.SERVER_START_ON_CREATION, false);
                serverModel.saveServer(null);
            } catch (CoreException ce) {
                OpenShiftUIActivator.getDefault().getLogger().logError("Error occured while creating a server adapter", ce);
                return;
            }
        }
    });
    boolean success = false;
    try {
        Job job = new JobChainBuilder(createJob.getJob()).runWhenSuccessfullyDone(new RefreshResourcesJob(createJob, true)).build();
        IStatus status = runInWizard(job, createJob.getDelegatingProgressMonitor(), getContainer());
        success = isFailed(status);
    } catch (InvocationTargetException | InterruptedException e) {
        OpenShiftUIActivator.getDefault().getLogger().logError(e);
        success = false;
    } finally {
        UsageStats.getInstance().newV3Application(model.getConnection().getHost(), success);
    }
    return success;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) ImportApplicationWizard(org.jboss.tools.openshift.internal.ui.wizard.importapp.ImportApplicationWizard) IRoute(com.openshift.restclient.model.route.IRoute) RefreshResourcesJob(org.jboss.tools.openshift.internal.ui.job.RefreshResourcesJob) IBuildConfig(com.openshift.restclient.model.IBuildConfig) List(java.util.List) IResourcesModelJob(org.jboss.tools.openshift.internal.ui.job.IResourcesModelJob) RefreshResourcesJob(org.jboss.tools.openshift.internal.ui.job.RefreshResourcesJob) Job(org.eclipse.core.runtime.jobs.Job) IService(com.openshift.restclient.model.IService) JobChainBuilder(org.jboss.tools.openshift.internal.common.core.job.JobChainBuilder) Connection(org.jboss.tools.openshift.core.connection.Connection) ServerSettingsWizardPageModel(org.jboss.tools.openshift.internal.ui.server.ServerSettingsWizardPageModel) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) IProject(com.openshift.restclient.model.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IResourcesModelJob(org.jboss.tools.openshift.internal.ui.job.IResourcesModelJob) CoreException(org.eclipse.core.runtime.CoreException) IServerWorkingCopy(org.eclipse.wst.server.core.IServerWorkingCopy) Collection(java.util.Collection) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IResource(com.openshift.restclient.model.IResource)

Example 27 with IBuildConfig

use of com.openshift.restclient.model.IBuildConfig in project jbosstools-openshift by jbosstools.

the class ServerSettingsWizardPageModel method getDeployProject.

protected org.eclipse.core.resources.IProject getDeployProject(IResource resource) {
    // TODO: JBIDE-23490 check if association can be done for non service resources
    if (resource == null) {
        return null;
    }
    IProject openShiftProject = getOpenShiftProject(resource);
    List<IBuildConfig> buildConfigs = getBuildConfigs(openShiftProject);
    IBuildConfig buildConfig = ResourceUtils.getBuildConfigFor(resource, buildConfigs);
    return ResourceUtils.getWorkspaceProjectFor(buildConfig, getProjects());
}
Also used : IBuildConfig(com.openshift.restclient.model.IBuildConfig) IProject(com.openshift.restclient.model.IProject)

Example 28 with IBuildConfig

use of com.openshift.restclient.model.IBuildConfig in project jbosstools-openshift by jbosstools.

the class NewApplicationSummaryFromTemplateDialog method createAreaAfterResourceSummary.

@Override
protected void createAreaAfterResourceSummary(Composite parent) {
    Composite area = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(area);
    GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(area);
    final Collection<IBuildConfig> buildConfigs = findBuildConfigsWithWebHooks();
    if (!buildConfigs.isEmpty()) {
        Link webHooksLink = new Link(area, SWT.NONE);
        webHooksLink.setText("Click <a>here</a> to display the webhooks available to automatically trigger builds.");
        GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).applyTo(webHooksLink);
        webHooksLink.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                WebHooksDialog dialog = new WebHooksDialog(getParentShell(), buildConfigs);
                dialog.open();
            }
        });
    }
    if (job.getParameters().isEmpty()) {
        return;
    }
    Label lblParams = new Label(area, SWT.WRAP);
    lblParams.setText("Please make note of the following parameters which may include values required to administer your resources:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).hint(100, SWT.DEFAULT).grab(true, false).applyTo(lblParams);
    Composite container = new Composite(parent, SWT.NONE);
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.TOP).grab(true, true).applyTo(container);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).equalWidth(false).applyTo(container);
    Composite parameters = new Composite(container, SWT.NONE);
    GridDataFactory.fillDefaults().hint(100, 200).grab(true, true).applyTo(parameters);
    TableViewer viewer = createTable(parameters);
    viewer.setInput(job.getParameters());
    Button copyToClipboard = new Button(container, SWT.PUSH);
    copyToClipboard.setImage(OpenShiftImages.COPY_TO_CLIPBOARD_IMG);
    copyToClipboard.setToolTipText("Copy parameters to clipboard");
    copyToClipboard.addSelectionListener(onClickCopyButton(lblParams));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(false, false).applyTo(copyToClipboard);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) IBuildConfig(com.openshift.restclient.model.IBuildConfig) Button(org.eclipse.swt.widgets.Button) WebHooksDialog(org.jboss.tools.openshift.internal.ui.webhooks.WebHooksDialog) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Label(org.eclipse.swt.widgets.Label) TableViewer(org.eclipse.jface.viewers.TableViewer) Link(org.eclipse.swt.widgets.Link)

Example 29 with IBuildConfig

use of com.openshift.restclient.model.IBuildConfig in project jbosstools-openshift by jbosstools.

the class WebhookUtilTest method givenBuildConfigWithTriggers.

private IBuildConfig givenBuildConfigWithTriggers(IBuildTrigger... buildTriggers) {
    IBuildConfig buildConfig = mock(IBuildConfig.class);
    List<IBuildTrigger> triggers = (buildTriggers == null) ? Collections.<IBuildTrigger>emptyList() : Arrays.asList(buildTriggers);
    when(buildConfig.getBuildTriggers()).thenReturn(triggers);
    return buildConfig;
}
Also used : IBuildConfig(com.openshift.restclient.model.IBuildConfig) IBuildTrigger(com.openshift.restclient.model.build.IBuildTrigger)

Aggregations

IBuildConfig (com.openshift.restclient.model.IBuildConfig)29 Test (org.junit.Test)12 IService (com.openshift.restclient.model.IService)5 IResource (com.openshift.restclient.model.IResource)4 Collection (java.util.Collection)4 DockerImageURI (com.openshift.restclient.images.DockerImageURI)3 IProject (com.openshift.restclient.model.IProject)3 ISourceBuildStrategy (com.openshift.restclient.model.build.ISourceBuildStrategy)3 IRoute (com.openshift.restclient.model.route.IRoute)3 ResourceKind (com.openshift.restclient.ResourceKind)2 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)2 IBuildStrategy (com.openshift.restclient.model.build.IBuildStrategy)2 ICustomBuildStrategy (com.openshift.restclient.model.build.ICustomBuildStrategy)2 IDockerBuildStrategy (com.openshift.restclient.model.build.IDockerBuildStrategy)2 IWebhookTrigger (com.openshift.restclient.model.build.IWebhookTrigger)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 IStatus (org.eclipse.core.runtime.IStatus)2