Search in sources :

Example 36 with io.fabric8.kubernetes.api.model

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

the class ProfileEditTest method deployment.

@Deployment
@StartLevelAware(autostart = true)
public static Archive<?> deployment() {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "profile-edit-test.jar");
    archive.addPackage(CommandSupport.class.getPackage());
    archive.setManifest(new Asset() {

        @Override
        public InputStream openStream() {
            OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
            builder.addBundleManifestVersion(2);
            builder.addBundleSymbolicName(archive.getName());
            builder.addBundleVersion("1.0.0");
            builder.addImportPackages(ServiceLocator.class, FabricService.class);
            builder.addImportPackages("io.fabric8.git");
            builder.addImportPackages(AbstractCommand.class, Action.class);
            builder.addImportPackage("org.apache.felix.service.command;status=provisional");
            builder.addImportPackages(ConfigurationAdmin.class, ServiceTracker.class, Logger.class);
            return builder.openStream();
        }
    });
    return archive;
}
Also used : Action(org.apache.felix.gogo.commands.Action) ServiceTracker(org.osgi.util.tracker.ServiceTracker) InputStream(java.io.InputStream) AbstractCommand(org.apache.felix.gogo.commands.basic.AbstractCommand) Logger(org.slf4j.Logger) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) ServiceLocator(io.fabric8.api.gravia.ServiceLocator) FabricService(io.fabric8.api.FabricService) OSGiManifestBuilder(org.jboss.osgi.metadata.OSGiManifestBuilder) Asset(org.jboss.shrinkwrap.api.asset.Asset) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) CommandSupport(io.fabric8.itests.support.CommandSupport) StartLevelAware(org.jboss.arquillian.osgi.StartLevelAware) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 37 with io.fabric8.kubernetes.api.model

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

the class ContainerUpgradeAndRollbackTest method deployment.

@Deployment
@StartLevelAware(autostart = true)
public static Archive<?> deployment() {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "container-upgrade-rollback-test.jar");
    archive.addPackage(CommandSupport.class.getPackage());
    archive.setManifest(new Asset() {

        @Override
        public InputStream openStream() {
            OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
            builder.addBundleManifestVersion(2);
            builder.addBundleSymbolicName(archive.getName());
            builder.addBundleVersion("1.0.0");
            builder.addImportPackages(ServiceLocator.class, FabricService.class);
            builder.addImportPackages("io.fabric8.git");
            builder.addImportPackages(AbstractCommand.class, Action.class);
            builder.addImportPackage("org.apache.felix.service.command;status=provisional");
            builder.addImportPackages(ConfigurationAdmin.class, ServiceTracker.class, Logger.class);
            return builder.openStream();
        }
    });
    return archive;
}
Also used : Action(org.apache.felix.gogo.commands.Action) ServiceTracker(org.osgi.util.tracker.ServiceTracker) InputStream(java.io.InputStream) AbstractCommand(org.apache.felix.gogo.commands.basic.AbstractCommand) Logger(org.slf4j.Logger) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) ServiceLocator(io.fabric8.api.gravia.ServiceLocator) FabricService(io.fabric8.api.FabricService) OSGiManifestBuilder(org.jboss.osgi.metadata.OSGiManifestBuilder) Asset(org.jboss.shrinkwrap.api.asset.Asset) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) CommandSupport(io.fabric8.itests.support.CommandSupport) StartLevelAware(org.jboss.arquillian.osgi.StartLevelAware) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 38 with io.fabric8.kubernetes.api.model

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

the class ArchetypeGenerateAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    // if no directory then use workspace
    if (directory == null) {
        // must have a workspace location configured
        Preferences preferences = Preferences.userNodeForPackage(getClass());
        String location = preferences.get(ArchetypeWorkspace.PREFERENCE_WORKSPACE, null);
        if (location == null) {
            System.out.println("No workspace location has been set.");
            System.out.println("Use the archetype-workspace command to set a workspace first.");
            System.out.println("");
            return null;
        } else {
            System.out.println("Using current workspace: " + location);
            directory = location;
        }
    } else {
        System.out.println("Using directory as workspace: " + directory);
    }
    File target = new File(directory);
    // make sure the directory exists, auto-creating if missing
    if (!target.exists()) {
        target.mkdirs();
    }
    if (!target.exists() || !target.isDirectory()) {
        System.err.println("Workspace does not exists or is not a directory: " + directory);
        return null;
    }
    Archetype archetype = null;
    // try artifact first
    if (!isNullOrBlank(archetypeOrFilter)) {
        archetype = archetypeService.getArchetypeByArtifact(archetypeOrFilter);
        if (archetype == null) {
            // then by coordinate
            archetype = archetypeService.getArchetype(archetypeOrFilter);
        }
    }
    // no archetype yet so present a list where the user can select
    while (archetype == null) {
        List<Archetype> archetypes = archetypeService.listArchetypes(archetypeOrFilter, true);
        System.out.println("Choose archetype:");
        Iterator<Archetype> it = archetypes.iterator();
        int i = 0;
        while (it.hasNext()) {
            Archetype select = it.next();
            System.out.println(String.format("%4d: -> %-50s %s", ++i, select.artifactId, select.description));
        }
        boolean choosing = true;
        while (choosing) {
            // default select last
            String choose = ShellUtils.readLine(session, String.format("Choose a number or apply filter (case insensitive): %d: ", i), false);
            if (Strings.isNullOrBlank(choose)) {
                // user pressed enter so we select the last
                choose = "" + i;
            }
            try {
                int no = Integer.valueOf(choose);
                // is the number within range
                if (no >= 1 && no <= archetypes.size()) {
                    archetype = archetypes.get(no - 1);
                    break;
                } else {
                    System.out.println("Number " + no + " out of range. Please try again!");
                    continue;
                }
            } catch (NumberFormatException e) {
                // no its a filter, so we use this as filter, and show the list again
                archetypeOrFilter = choose;
                choosing = false;
                archetype = null;
            }
        }
    }
    // okay we have selected an archetype now
    File archetypeFile = fetchArchetype(archetype);
    if (archetypeFile == null || !archetypeFile.exists()) {
        System.err.println("No archetype found for \"" + archetypeOrFilter + "\" coordinates");
        return null;
    }
    System.out.println("----------------------------------------------------------------------------");
    System.out.println("Using archetype: " + archetype.artifactId);
    String defaultGroupId = "io.fabric8";
    String defaultArtifactId = archetype.artifactId + "-example";
    String defaultVersion = "1.0-SNAPSHOT";
    String defaultName = archetype.name;
    String defaultDescription = isNotBlank(archetype.description) ? archetype.description : "";
    System.out.println("----- Configure archetype -----");
    String groupId = ShellUtils.readLine(session, String.format("Define value for property 'groupId' (%s): ", defaultGroupId), false);
    String artifactId = ShellUtils.readLine(session, String.format("Define value for property 'artifactId' (%s): ", defaultArtifactId), false);
    String version = ShellUtils.readLine(session, String.format("Define value for property 'version' (%s): ", defaultVersion), false);
    groupId = isNullOrBlank(groupId) ? defaultGroupId : groupId;
    artifactId = isNullOrBlank(artifactId) ? defaultArtifactId : artifactId;
    version = isNullOrBlank(version) ? defaultVersion : version;
    String defaultPackageName = (groupId + "." + artifactId).replaceAll("-", ".");
    String packageName = ShellUtils.readLine(session, String.format("Define value for property 'package' (%s): ", defaultPackageName), false);
    // use artifact id as default directory name (maven does this also)
    String defaultDirectoryName = isNullOrBlank(artifactId) ? defaultArtifactId : artifactId;
    directory = ShellUtils.readLine(session, String.format("Define value for property 'directoryName' (%s): ", defaultDirectoryName), false);
    packageName = isNullOrBlank(packageName) ? defaultPackageName : packageName;
    directory = isNullOrBlank(directory) ? artifactId : directory;
    String name = ShellUtils.readLine(session, String.format("Define value for property 'name' (%s): ", defaultName), false);
    String description = ShellUtils.readLine(session, String.format("Define value for property 'description' (%s): ", defaultDescription), false);
    // use null to indicate we want out of the box description
    name = isNullOrBlank(name) ? null : name;
    description = isNullOrBlank(description) ? null : description;
    File childDir = new File(target, directory);
    ArchetypeHelper helper = new ArchetypeHelper(archetypeFile, childDir, groupId, artifactId, version, name, description);
    helper.setPackageName(packageName);
    Map<String, String> properties = helper.parseProperties();
    // if we have fabric8.profile as a property then lets configured it now, as its mandatory
    // and use artifactId as its default suggested value
    String profile = null;
    if (properties.containsKey("fabric8-profile")) {
        profile = properties.remove("fabric8-profile");
        String defaultProfile = isNullOrBlank(profile) ? artifactId : profile;
        String p = ShellUtils.readLine(session, String.format("Define value for property 'fabric8.profile' (%s): ", defaultProfile), false);
        profile = isNullOrBlank(p) ? defaultProfile : p;
    }
    // show additional properties and ask to use them as-is
    boolean mustChoose = false;
    if (!properties.isEmpty()) {
        // check if we must choose if there is an empty value or a value that has a ${ } token so we dont have a default value
        for (String value : properties.values()) {
            if (isNullOrBlank(value) || value.contains("$")) {
                mustChoose = true;
                break;
            }
        }
        if (!mustChoose) {
            System.out.println("----- Additional properties -----");
            for (String key : properties.keySet()) {
                System.out.println(String.format("Using property '%s' (%s): ", key, properties.get(key)));
            }
        }
        boolean choosing = true;
        while (mustChoose || choosing) {
            String confirm = null;
            if (!mustChoose) {
                confirm = ShellUtils.readLine(session, "Confirm additional properties configuration: (Y): ", false);
                confirm = isNullOrBlank(confirm) ? "Y" : confirm;
            }
            if (mustChoose || !"Y".equalsIgnoreCase(confirm)) {
                // ask for replacement properties suggesting the defaults
                if (!properties.isEmpty()) {
                    System.out.println("----- Configure additional properties -----");
                    for (String key : properties.keySet()) {
                        String value = properties.get(key);
                        // if the value is empty or a token, then do not show any default value
                        if (isNullOrBlank(value) || value.contains("$")) {
                            value = "";
                        }
                        String p = ShellUtils.readLine(session, String.format("Define value for property '%s' (%s): ", key, value), false);
                        p = isNullOrBlank(p) ? value : p;
                        properties.put(key, p);
                    }
                }
                mustChoose = false;
            } else {
                choosing = false;
            }
        }
    }
    // remover to include the profile back into properties
    if (profile != null) {
        properties.put("fabric8-profile", profile);
    }
    if (!properties.isEmpty()) {
        // set override properties
        helper.setOverrideProperties(properties);
    }
    String confirm = ShellUtils.readLine(session, "Create project: (Y): ", false);
    confirm = confirm == null || confirm.trim().equals("") ? "Y" : confirm;
    if ("Y".equalsIgnoreCase(confirm)) {
        System.out.println("----------------------------------------------------------------------------");
        System.out.println(String.format("Creating project in directory: %s", childDir.getCanonicalPath()));
        helper.execute();
        System.out.println("Project created successfully");
        System.out.println("");
    } else {
        System.out.println("----------------------------------------------------------------------------");
        System.out.println("Creating project aborted!");
        System.out.println("");
    }
    return null;
}
Also used : Archetype(io.fabric8.tooling.archetype.catalog.Archetype) ArchetypeHelper(io.fabric8.tooling.archetype.generator.ArchetypeHelper) Preferences(java.util.prefs.Preferences) File(java.io.File)

Example 39 with io.fabric8.kubernetes.api.model

use of io.fabric8.kubernetes.api.model in project fabric8-maven-plugin by fabric8io.

the class DockerBuildServiceTest method testSuccessfulBuild.

@Test
public void testSuccessfulBuild() throws Exception {
    new Expectations() {

        {
            hub.getBuildService();
            result = buildService;
        }
    };
    final BuildService.BuildContext context = new BuildService.BuildContext.Builder().build();
    final io.fabric8.maven.core.service.BuildService.BuildServiceConfig config = new io.fabric8.maven.core.service.BuildService.BuildServiceConfig.Builder().dockerBuildContext(context).build();
    final String imageName = "image-name";
    final ImageConfiguration image = new ImageConfiguration.Builder().name(imageName).buildConfig(new BuildImageConfiguration.Builder().from("from").build()).build();
    DockerBuildService service = new DockerBuildService(hub, config);
    service.build(image);
    new FullVerificationsInOrder() {

        {
            buildService.buildImage(image, context);
            buildService.tagImage(imageName, image);
        }
    };
}
Also used : Expectations(mockit.Expectations) BuildService(io.fabric8.maven.docker.service.BuildService) FullVerificationsInOrder(mockit.FullVerificationsInOrder) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) Test(org.junit.Test)

Example 40 with io.fabric8.kubernetes.api.model

use of io.fabric8.kubernetes.api.model in project fabric8-maven-plugin by fabric8io.

the class IconEnricher method getDefaultIconRef.

/**
 * Lets use the project and its classpath to try figure out what default icon to use
 *
 * @return the icon ref if we can detect one or return null
 */
private String getDefaultIconRef() {
    MavenProject project = getProject();
    EnricherContext context = getContext();
    if (hasClass(project, "io.fabric8.funktion.runtime.Main") || MavenUtil.hasDependencyOnAnyArtifactOfGroup(project, "io.fabric8.funktion")) {
        return "funktion";
    }
    if (hasClass(project, "org.apache.camel.CamelContext")) {
        return "camel";
    }
    if (hasPlugin(project, "org.springframework.boot:spring-boot-maven-plugin") || hasClass(project, "org.springframework.boot.SpringApplication")) {
        return "spring-boot";
    }
    if (hasClass(project, "org.springframework.core.Constants")) {
        return "spring";
    }
    if (hasClass(project, "org.vertx.java.core.Handler", "io.vertx.core.Handler")) {
        return "vertx";
    }
    if (hasPlugin(project, "org.wildfly.swarm:wildfly-swarm-plugin") || MavenUtil.hasDependencyOnAnyArtifactOfGroup(project, "org.wildfly.swarm")) {
        return "wildfly-swarm";
    }
    return null;
}
Also used : MavenProject(org.apache.maven.project.MavenProject) EnricherContext(io.fabric8.maven.enricher.api.EnricherContext)

Aggregations

Test (org.junit.Test)29 FabricService (io.fabric8.api.FabricService)26 File (java.io.File)22 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)18 InputStream (java.io.InputStream)16 Logger (org.slf4j.Logger)16 ServiceLocator (io.fabric8.api.gravia.ServiceLocator)15 CommandSupport (io.fabric8.itests.support.CommandSupport)15 Deployment (org.jboss.arquillian.container.test.api.Deployment)15 StartLevelAware (org.jboss.arquillian.osgi.StartLevelAware)15 OSGiManifestBuilder (org.jboss.osgi.metadata.OSGiManifestBuilder)15 Asset (org.jboss.shrinkwrap.api.asset.Asset)15 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)15 ServiceTracker (org.osgi.util.tracker.ServiceTracker)15 IOException (java.io.IOException)14 Action (org.apache.felix.gogo.commands.Action)14 AbstractCommand (org.apache.felix.gogo.commands.basic.AbstractCommand)14 MavenResolver (io.fabric8.maven.MavenResolver)11 Container (io.fabric8.api.Container)10 BundleContext (org.osgi.framework.BundleContext)9