Search in sources :

Example 6 with OCBinaryValidator

use of org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator in project jbosstools-openshift by jbosstools.

the class OCBinaryValidatorTest method oc310OnLinuxValidatesOKIfNonRSyncRequirementsAreTested.

@Test
public void oc310OnLinuxValidatesOKIfNonRSyncRequirementsAreTested() {
    // given
    OCBinaryValidator validator = new TestableOCBinaryValidator("papa-smurf", Platform.OS_LINUX, false);
    // when
    IStatus status = validator.getStatus(Version.parseVersion("3.10.0"), false, OCBinaryValidator.NON_RSYNC_REQUIREMENTS);
    // then
    assertThat(status.isOK()).isTrue();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) OCBinaryValidator(org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator) Test(org.junit.Test)

Example 7 with OCBinaryValidator

use of org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator 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 = ResourceUtils.getResourceOfType(IService.class, resources);
            return service == null ? null : (IService) service;
        }

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

        protected void createServerAdapter(org.eclipse.core.resources.IProject project, Connection connection, IService service, IRoute route) {
            try {
                IServerWorkingCopy server = OpenShiftServerUtils.create(OpenShiftResourceUniqueId.get(service));
                IStatus ocStatus = new OCBinaryValidator(OCBinary.getInstance().getPath(connection)).getStatus(new NullProgressMonitor());
                RsyncStatus rsyncStatus = RSyncValidator.get().getStatus();
                ServerSettingsWizardPageModel serverModel = new ServerSettingsWizardPageModel(service, route, project, connection, server, ocStatus, rsyncStatus);
                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) OCBinaryValidator(org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator) 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) RsyncStatus(org.jboss.tools.openshift.internal.core.util.RSyncValidator.RsyncStatus) 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 8 with OCBinaryValidator

use of org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator in project jbosstools-openshift by jbosstools.

the class OCBinaryValidatorTest method oc360OnMacWithSpaceInPathValidatesOKIfNonRSyncRequirementsTested.

@Test
public void oc360OnMacWithSpaceInPathValidatesOKIfNonRSyncRequirementsTested() {
    // given
    OCBinaryValidator validator = new TestableOCBinaryValidator("/my home/bin/oc", Platform.OS_MACOSX, false);
    // when
    IStatus status = validator.getStatus(Version.parseVersion("3.6.0"), false, OCBinaryValidator.NON_RSYNC_REQUIREMENTS);
    // then validates ok, path with spaces is only relevant for rsync
    assertThat(status.isOK()).isTrue();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) OCBinaryValidator(org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator) Test(org.junit.Test)

Example 9 with OCBinaryValidator

use of org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator in project jbosstools-openshift by jbosstools.

the class OCBinaryValidatorTest method oc360OnMacWithSpaceInPathValidatesKO.

@Test
public void oc360OnMacWithSpaceInPathValidatesKO() {
    // given
    OCBinaryValidator validator = new TestableOCBinaryValidator("/my home/bin/oc", Platform.OS_MACOSX, false);
    // when
    IStatus status = validator.getStatus(Version.parseVersion("3.6.0"));
    // then
    assertThat(status.isOK()).isFalse();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) OCBinaryValidator(org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator) Test(org.junit.Test)

Example 10 with OCBinaryValidator

use of org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator in project jbosstools-openshift by jbosstools.

the class OCBinaryValidatorTest method getVersionReturnsEmptyVersionForNullPath.

@Test
public void getVersionReturnsEmptyVersionForNullPath() {
    OCBinaryValidator validator = new OCBinaryValidator(null);
    assertEquals(Version.emptyVersion, validator.getVersion(new NullProgressMonitor()));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OCBinaryValidator(org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator) Test(org.junit.Test)

Aggregations

OCBinaryValidator (org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator)11 IStatus (org.eclipse.core.runtime.IStatus)10 Test (org.junit.Test)9 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 IBuildConfig (com.openshift.restclient.model.IBuildConfig)1 IProject (com.openshift.restclient.model.IProject)1 IResource (com.openshift.restclient.model.IResource)1 IService (com.openshift.restclient.model.IService)1 IRoute (com.openshift.restclient.model.route.IRoute)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1