Search in sources :

Example 56 with Project

use of io.fabric8.openshift.api.model.Project in project docker-maven-plugin by fabric8io.

the class ComposeUtilsTest method resolveComposeFileWithRelativeComposeFileAndAbsoluteBaseDir.

@Test
public void resolveComposeFileWithRelativeComposeFileAndAbsoluteBaseDir() throws Exception {
    // relative/path/to/docker-compose.yaml
    String relComposeFile = join(SEP, "relative", "path", "to", "docker-compose.yaml");
    final String absMavenProjectDir = createTmpFile(className).getAbsolutePath();
    new Expectations() {

        {
            project.getBasedir();
            result = new File(absMavenProjectDir);
        }
    };
    assertEquals(new File(ABS_BASEDIR, relComposeFile), ComposeUtils.resolveComposeFileAbsolutely(ABS_BASEDIR, relComposeFile, project));
    new VerificationsInOrder() {

        {
            project.getBasedir();
        }
    };
}
Also used : Expectations(mockit.Expectations) PathTestUtil.createTmpFile(io.fabric8.maven.docker.util.PathTestUtil.createTmpFile) File(java.io.File) VerificationsInOrder(mockit.VerificationsInOrder) Test(org.junit.Test)

Example 57 with Project

use of io.fabric8.openshift.api.model.Project in project docker-maven-plugin by fabric8io.

the class ComposeUtilsTest method resolveComposeFileWithRelativeComposeFileAndRelativeBaseDir.

@Test
public void resolveComposeFileWithRelativeComposeFileAndRelativeBaseDir() throws Exception {
    // relative/path/to/docker-compose.yaml
    String relComposeFile = join(SEP, "relative", "path", "to", "docker-compose.yaml");
    String relBaseDir = "basedir" + SEP;
    final String absMavenProjectDir = createTmpFile(className).getAbsolutePath();
    new Expectations() {

        {
            project.getBasedir();
            result = new File(absMavenProjectDir);
        }
    };
    assertEquals(new File(new File(absMavenProjectDir, relBaseDir), relComposeFile), ComposeUtils.resolveComposeFileAbsolutely(relBaseDir, relComposeFile, project));
    new VerificationsInOrder() {

        {
            project.getBasedir();
        }
    };
}
Also used : Expectations(mockit.Expectations) PathTestUtil.createTmpFile(io.fabric8.maven.docker.util.PathTestUtil.createTmpFile) File(java.io.File) VerificationsInOrder(mockit.VerificationsInOrder) Test(org.junit.Test)

Example 58 with Project

use of io.fabric8.openshift.api.model.Project in project kie-wb-common by kiegroup.

the class OpenShiftClient method destroy.

public void destroy(String id) throws OpenShiftClientException {
    try {
        OpenShiftRuntimeId runtimeId = OpenShiftRuntimeId.fromString(id);
        String prjName = runtimeId.project();
        String svcName = runtimeId.service();
        // TODO: should we always depend on the app label being specified, or gotten from the service?
        String appName = runtimeId.application();
        if (appName == null || appName.isEmpty()) {
            Service service = delegate.services().inNamespace(prjName).withName(svcName).get();
            if (service != null) {
                appName = service.getMetadata().getLabels().get(APP_LABEL);
            }
        }
        /*
             * cascading delete of deploymentConfigs means we don't have to also do the following:
             *     delegate.deploymentConfigs().inNamespace(prjName).withLabel(APP_LABEL, appName).delete();
             *     delegate.replicationControllers().inNamespace(prjName).withLabel(APP_LABEL, appName).delete();
             *     delegate.pods().inNamespace(prjName).withLabel(APP_LABEL, appName).delete();
             * , but deleting services and routes are still necessary:
             */
        delegate.deploymentConfigs().inNamespace(prjName).withName(svcName).cascading(true).delete();
        if (appName != null) {
            delegate.services().inNamespace(prjName).withLabel(APP_LABEL, appName).delete();
            delegate.routes().inNamespace(prjName).withLabel(APP_LABEL, appName).delete();
        } else {
            delegate.services().inNamespace(prjName).delete();
            delegate.routes().inNamespace(prjName).delete();
        }
        // clean up any generated image streams, secrets, and service accounts
        for (ImageStream item : delegate.imageStreams().inNamespace(prjName).list().getItems()) {
            if (isGuvnorAlaGenerated(item)) {
                delegate.imageStreams().inNamespace(prjName).delete(item);
            }
        }
        for (Secret item : delegate.secrets().inNamespace(prjName).list().getItems()) {
            if (isGuvnorAlaGenerated(item)) {
                delegate.secrets().inNamespace(prjName).delete(item);
            }
        }
        for (ServiceAccount item : delegate.serviceAccounts().inNamespace(prjName).list().getItems()) {
            if (isGuvnorAlaGenerated(item)) {
                delegate.serviceAccounts().inNamespace(prjName).delete(item);
            }
        }
        // clean up generated project
        if (isGuvnorAlaGenerated(delegate.projects().withName(prjName).get())) {
            delegate.projects().withName(prjName).delete();
        }
    } catch (Throwable t) {
        throw new OpenShiftClientException(t.getMessage(), t);
    }
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) Service(io.fabric8.kubernetes.api.model.Service) ImageStream(io.fabric8.openshift.api.model.ImageStream) OpenShiftClientException(org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException) IntOrString(io.fabric8.kubernetes.api.model.IntOrString)

Example 59 with Project

use of io.fabric8.openshift.api.model.Project in project fabric8 by jboss-fuse.

the class CreateProfileZipMojo method generateZip.

protected void generateZip() throws DependencyTreeBuilderException, MojoExecutionException, IOException, MojoFailureException {
    ProjectRequirements requirements = new ProjectRequirements();
    DependencyDTO rootDependency = null;
    if (isIncludeArtifact()) {
        rootDependency = loadRootDependency();
        requirements.setRootDependency(rootDependency);
    }
    configureRequirements(requirements);
    if (isIncludeArtifact()) {
        addProjectArtifactBundle(requirements);
    }
    File profileBuildDir = createProfileBuildDir(requirements.getProfileId());
    boolean hasConfigDir = profileConfigDir.isDirectory();
    if (hasConfigDir) {
        copyProfileConfigFiles(profileBuildDir, profileConfigDir);
    } else {
        getLog().info("The profile configuration files directory " + profileConfigDir + " doesn't exist, so not copying any additional project documentation or configuration files");
    }
    // to avoid generating dummy profiles for parent poms
    if (hasConfigDir || rootDependency != null || notEmpty(requirements.getBundles()) || notEmpty(requirements.getFeatures()) || notEmpty(requirements.getFeatureRepositories())) {
        if (includeReadMe) {
            copyReadMe(project.getFile().getParentFile(), profileBuildDir);
        }
        if (generateSummaryFile) {
            String description = project.getDescription();
            if (Strings.isNotBlank(description)) {
                File summaryMd = new File(profileBuildDir, "Summary.md");
                summaryMd.getParentFile().mkdirs();
                if (!summaryMd.exists()) {
                    byte[] bytes = description.getBytes();
                    Files.copy(new ByteArrayInputStream(bytes), new FileOutputStream(summaryMd));
                }
            }
        }
        if (isIncludeArtifact()) {
            writeProfileRequirements(requirements, profileBuildDir);
        }
        generateFabricAgentProperties(requirements, new File(profileBuildDir, "io.fabric8.agent.properties"));
        // only generate if its a WAR project
        if ("war".equals(project.getPackaging())) {
            generateFabricContextPathProperties(requirements, new File(profileBuildDir, Constants.WEB_CONTEXT_PATHS_PID + ".properties"));
        }
        Zips.createZipFile(getLog(), buildDir, outputFile);
        projectHelper.attachArtifact(project, artifactType, artifactClassifier, outputFile);
        getLog().info("Created profile zip file: " + outputFile);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) DependencyDTO(io.fabric8.deployer.dto.DependencyDTO) ProjectRequirements(io.fabric8.deployer.dto.ProjectRequirements) File(java.io.File)

Example 60 with Project

use of io.fabric8.openshift.api.model.Project in project fabric8 by jboss-fuse.

the class CreateScriptMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    try {
        DependencyDTO rootDependency = loadRootDependency();
        ProjectRequirements requirements = new ProjectRequirements();
        requirements.setRootDependency(rootDependency);
        configureRequirements(requirements);
        addProjectArtifactBundle(requirements);
        generateScript(requirements, outputFile);
        projectHelper.attachArtifact(project, artifactType, artifactClassifier, outputFile);
    } catch (MojoExecutionException e) {
        throw e;
    } catch (Exception e) {
        throw new MojoExecutionException("Error executing", e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DependencyDTO(io.fabric8.deployer.dto.DependencyDTO) ProjectRequirements(io.fabric8.deployer.dto.ProjectRequirements) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Aggregations

Test (org.junit.Test)51 ResourceConfig (io.fabric8.maven.core.config.ResourceConfig)29 File (java.io.File)14 Expectations (mockit.Expectations)14 ArrayList (java.util.ArrayList)13 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)11 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)11 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)9 IOException (java.io.IOException)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)8 VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)7 GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)6 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)6 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)5 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)5 MojoFailureException (org.apache.maven.plugin.MojoFailureException)5 MavenProject (org.apache.maven.project.MavenProject)5 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)4 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3