Search in sources :

Example 6 with ProjectRequirements

use of io.fabric8.deployer.dto.ProjectRequirements in project fabric8 by jboss-fuse.

the class ProjectDeployerImpl method deployProjectJsonMergeOption.

@Override
public DeployResults deployProjectJsonMergeOption(String requirementsJson, boolean appendProfileBundles) throws Exception {
    ProjectRequirements requirements = DtoHelper.getMapper().readValue(requirementsJson, ProjectRequirements.class);
    Objects.notNull(requirements, "ProjectRequirements");
    return deployProject(requirements, appendProfileBundles);
}
Also used : ProjectRequirements(io.fabric8.deployer.dto.ProjectRequirements)

Example 7 with ProjectRequirements

use of io.fabric8.deployer.dto.ProjectRequirements in project fabric8 by jboss-fuse.

the class ProjectDeployerImpl method getOrCreateVersion.

private Version getOrCreateVersion(ProjectRequirements requirements) {
    ProfileService profileService = fabricService.get().adapt(ProfileService.class);
    String versionId = getVersionId(requirements);
    Version version = findVersion(fabricService.get(), versionId);
    if (version == null) {
        String baseId = requirements.getBaseVersion();
        baseId = getVersionOrDefaultVersion(fabricService.get(), baseId);
        Version baseVersion = findVersion(fabricService.get(), baseId);
        if (baseVersion != null) {
            version = profileService.createVersionFrom(baseVersion.getId(), versionId, null);
        } else {
            version = VersionBuilder.Factory.create(versionId).getVersion();
            version = profileService.createVersion(version);
        }
    }
    return version;
}
Also used : ProfileService(io.fabric8.api.ProfileService) Version(io.fabric8.api.Version)

Example 8 with ProjectRequirements

use of io.fabric8.deployer.dto.ProjectRequirements in project fabric8 by jboss-fuse.

the class ProjectDeployerTest method testProfileDeploy.

@Test
@Ignore("[FABRIC-1110] Mocked test makes invalid assumption on the implementation")
public void testProfileDeploy() throws Exception {
    String groupId = "foo";
    String artifactId = "bar";
    String expectedProfileId = groupId + "-" + artifactId;
    String versionId = "1.0";
    ProjectRequirements requirements = new ProjectRequirements();
    DependencyDTO rootDependency = new DependencyDTO();
    requirements.setRootDependency(rootDependency);
    rootDependency.setGroupId(groupId);
    rootDependency.setArtifactId(artifactId);
    rootDependency.setVersion("1.0.0");
    List<String> parentProfileIds = Arrays.asList("karaf");
    List<String> features = Arrays.asList("cxf", "war");
    requirements.setParentProfiles(parentProfileIds);
    requirements.setFeatures(features);
    projectDeployer.deployProject(requirements);
    // now we should have a profile created
    Profile profile = assertProfileInFabric(expectedProfileId, versionId);
    assertBundleCount(profile, 1);
    assertEquals("parent ids", parentProfileIds, profile.getParentIds());
    assertFeatures(profile, features);
    String requirementsFileName = "dependencies/" + groupId + "/" + artifactId + "-requirements.json";
    byte[] jsonData = profile.getFileConfiguration(requirementsFileName);
    assertNotNull("should have found some JSON for: " + requirementsFileName, jsonData);
    String json = new String(jsonData);
    LOG.info("Got JSON: " + json);
    // lets replace the version, parent, features
    rootDependency.setVersion("1.0.1");
    projectDeployer.deployProject(requirements);
    profile = assertProfileInFabric(expectedProfileId, versionId);
    assertBundleCount(profile, 1);
    // now lets make a new version
    expectedProfileId = "cheese";
    versionId = "1.2";
    requirements.setVersion(versionId);
    requirements.setProfileId(expectedProfileId);
    parentProfileIds = Arrays.asList("default");
    features = Arrays.asList("camel", "war");
    requirements.setParentProfiles(parentProfileIds);
    requirements.setFeatures(features);
    projectDeployer.deployProject(requirements);
    profile = assertProfileInFabric(expectedProfileId, versionId);
    assertBundleCount(profile, 1);
    assertEquals("parent ids", parentProfileIds, profile.getParentIds());
    assertFeatures(profile, features);
// assertProfileMetadata();
}
Also used : DependencyDTO(io.fabric8.deployer.dto.DependencyDTO) ProjectRequirements(io.fabric8.deployer.dto.ProjectRequirements) Profile(io.fabric8.api.Profile) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with ProjectRequirements

use of io.fabric8.deployer.dto.ProjectRequirements in project fabric8 by jboss-fuse.

the class MavenUploadProxyServlet method handleDeploy.

private void handleDeploy(HttpServletRequest req, UploadContext result) throws Exception {
    String profile = req.getParameter("profile");
    String version = req.getParameter("version");
    if (profile != null && version != null) {
        ProjectRequirements requirements = toProjectRequirements(result);
        requirements.setProfileId(profile);
        requirements.setVersion(version);
        DeployResults deployResults = addToProfile(requirements);
        LOGGER.info(String.format("Deployed artifact %s to profile: %s", result.toArtifact(), deployResults));
    }
}
Also used : DeployResults(io.fabric8.deployer.dto.DeployResults) ProjectRequirements(io.fabric8.deployer.dto.ProjectRequirements)

Example 10 with ProjectRequirements

use of io.fabric8.deployer.dto.ProjectRequirements in project fabric8 by jboss-fuse.

the class DeployToProfileMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (isIgnoreProject())
        return;
    try {
        ProjectRequirements requirements = new ProjectRequirements();
        if (isIncludeArtifact()) {
            DependencyDTO rootDependency = loadRootDependency();
            requirements.setRootDependency(rootDependency);
        }
        configureRequirements(requirements);
        // validate requirements
        if (requirements.getProfileId() != null) {
            // make sure the profile id is a valid name
            FabricValidations.validateProfileName(requirements.getProfileId());
        }
        boolean newUserAdded = false;
        fabricServer = mavenSettings.getServer(serverId);
        // we may have username and password from jolokiaUrl
        String jolokiaUsername = null;
        String jolokiaPassword = null;
        try {
            URL url = new URL(jolokiaUrl);
            String s = url.getUserInfo();
            if (Strings.isNotBlank(s) && s.indexOf(':') > 0) {
                int idx = s.indexOf(':');
                jolokiaUsername = s.substring(0, idx);
                jolokiaPassword = s.substring(idx + 1);
                customUsernameAndPassword = true;
            }
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException("Option jolokiaUrl is invalid due " + e.getMessage());
        }
        // jolokia url overrides username/password configured in maven settings
        if (jolokiaUsername != null) {
            if (fabricServer == null) {
                fabricServer = new Server();
            }
            getLog().info("Using username: " + jolokiaUsername + " and password from provided jolokiaUrl option");
            fabricServer.setId(serverId);
            fabricServer.setUsername(jolokiaUsername);
            fabricServer.setPassword(jolokiaPassword);
        }
        if (fabricServer == null) {
            boolean create = false;
            if (mavenSettings.isInteractiveMode() && mavenSettingsWriter != null) {
                System.out.println("Maven settings file: " + mavenSettingsFile.getAbsolutePath());
                System.out.println();
                System.out.println();
                System.out.println("There is no <server> section in your ~/.m2/settings.xml file for the server id: " + serverId);
                System.out.println();
                System.out.println("You can enter the username/password now and have the settings.xml updated or you can do this by hand if you prefer.");
                System.out.println();
                while (true) {
                    String value = readInput("Would you like to update the settings.xml file now? (y/n): ").toLowerCase();
                    if (value.startsWith("n")) {
                        System.out.println();
                        System.out.println();
                        break;
                    } else if (value.startsWith("y")) {
                        create = true;
                        break;
                    }
                }
                if (create) {
                    System.out.println("Please let us know the login details for this server: " + serverId);
                    System.out.println();
                    String userName = readInput("Username: ");
                    String password = readPassword("Password: ");
                    String password2 = readPassword("Repeat Password: ");
                    while (!password.equals(password2)) {
                        System.out.println("Passwords do not match, please try again.");
                        password = readPassword("Password: ");
                        password2 = readPassword("Repeat Password: ");
                    }
                    System.out.println();
                    fabricServer = new Server();
                    fabricServer.setId(serverId);
                    fabricServer.setUsername(userName);
                    fabricServer.setPassword(password);
                    mavenSettings.addServer(fabricServer);
                    if (mavenSettingsFile.exists()) {
                        int counter = 1;
                        while (true) {
                            File backupFile = new File(mavenSettingsFile.getAbsolutePath() + ".backup-" + counter++ + ".xml");
                            if (!backupFile.exists()) {
                                System.out.println("Copied original: " + mavenSettingsFile.getAbsolutePath() + " to: " + backupFile.getAbsolutePath());
                                Files.copy(mavenSettingsFile, backupFile);
                                break;
                            }
                        }
                    }
                    Map<String, Object> config = new HashMap<String, Object>();
                    mavenSettingsWriter.write(mavenSettingsFile, config, mavenSettings);
                    System.out.println("Updated settings file: " + mavenSettingsFile.getAbsolutePath());
                    System.out.println();
                    newUserAdded = true;
                }
            }
        }
        if (fabricServer == null) {
            String message = "No <server> element can be found in ~/.m2/settings.xml for the server <id>" + serverId + "</id> so we cannot connect to fabric8!\n\n" + "Please add the following to your ~/.m2/settings.xml file (using the correct user/password values):\n\n" + "<servers>\n" + "  <server>\n" + "    <id>" + serverId + "</id>\n" + "    <username>admin</username>\n" + "    <password>admin</password>\n" + "  </server>\n" + "</servers>\n";
            getLog().error(message);
            throw new MojoExecutionException(message);
        }
        // now lets invoke the mbean
        J4pClient client = createJolokiaClient();
        if (upload) {
            uploadDeploymentUnit(client, newUserAdded || customUsernameAndPassword);
        } else {
            getLog().info("Uploading to the fabric8 maven repository is disabled");
        }
        DeployResults results = uploadRequirements(client, requirements);
        if (results != null) {
            uploadReadMeFile(client, results);
            uploadProfileConfigurations(client, results);
            refreshProfile(client, results);
        }
    } catch (MojoExecutionException e) {
        throw e;
    } catch (Exception e) {
        throw new MojoExecutionException("Error executing", e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) DeployResults(io.fabric8.deployer.dto.DeployResults) Server(org.apache.maven.settings.Server) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) J4pClient(org.jolokia.client.J4pClient) DependencyDTO(io.fabric8.deployer.dto.DependencyDTO) URL(java.net.URL) MalformedObjectNameException(javax.management.MalformedObjectNameException) J4pRemoteException(org.jolokia.client.exception.J4pRemoteException) ArtifactDeploymentException(org.apache.maven.artifact.deployer.ArtifactDeploymentException) J4pConnectException(org.jolokia.client.exception.J4pConnectException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) J4pException(org.jolokia.client.exception.J4pException) ProjectRequirements(io.fabric8.deployer.dto.ProjectRequirements) File(java.io.File)

Aggregations

ProjectRequirements (io.fabric8.deployer.dto.ProjectRequirements)11 DependencyDTO (io.fabric8.deployer.dto.DependencyDTO)6 Profile (io.fabric8.api.Profile)4 DeployResults (io.fabric8.deployer.dto.DeployResults)4 ProfileBuilder (io.fabric8.api.ProfileBuilder)3 ProfileService (io.fabric8.api.ProfileService)3 File (java.io.File)3 IOException (java.io.IOException)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 Version (io.fabric8.api.Version)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 J4pRemoteException (org.jolokia.client.exception.J4pRemoteException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DownloadManager (io.fabric8.agent.download.DownloadManager)1 Feature (io.fabric8.agent.model.Feature)1 FabricRequirements (io.fabric8.api.FabricRequirements)1 ProfileRegistry (io.fabric8.api.ProfileRegistry)1 ProfileRequirements (io.fabric8.api.ProfileRequirements)1 RuntimeProperties (io.fabric8.api.RuntimeProperties)1 AbstractRuntimeProperties (io.fabric8.api.scr.AbstractRuntimeProperties)1