Search in sources :

Example 16 with Resolver

use of io.fabric8.patch.management.conflicts.Resolver in project fabric8 by jboss-fuse.

the class DeployToProfileMojo method uploadRequirements.

protected DeployResults uploadRequirements(J4pClient client, ProjectRequirements requirements) throws Exception {
    String json = DtoHelper.getMapper().writeValueAsString(requirements);
    ObjectName mbeanName = ProjectDeployerImpl.OBJECT_NAME;
    getLog().info("Updating " + (requirements.isAbstractProfile() ? "abstract " : "") + "profile: " + requirements.getProfileId() + " with parent profile(s): " + requirements.getParentProfiles() + (requirements.isUseResolver() ? " using OSGi resolver" : "") + (requirements.isLocked() ? " locked" : ""));
    getLog().info("About to invoke mbean " + mbeanName + " on jolokia URL: " + jolokiaUrl + " with user: " + fabricServer.getUsername());
    getLog().debug("JSON: " + json);
    try {
        // Append bundles to existing profile bundles if we're not running the plugin at project root
        Boolean appendBundles = !mavenSession.getExecutionRootDirectory().equalsIgnoreCase(project.getBasedir().toString());
        J4pExecRequest request = new J4pExecRequest(mbeanName, "deployProjectJsonMergeOption(java.lang.String,boolean)", json, appendBundles);
        J4pResponse<J4pExecRequest> response = client.execute(request, "POST");
        Object value = response.getValue();
        if (value == null) {
            return null;
        } else {
            DeployResults answer = DtoHelper.getMapper().reader(DeployResults.class).readValue(value.toString());
            if (answer != null) {
                String profileUrl = answer.getProfileUrl();
                if (profileUrl != null) {
                    getLog().info("");
                    getLog().info("Profile page: " + profileUrl);
                    getLog().info("");
                } else {
                    getLog().info("Result: " + answer);
                }
            } else {
                getLog().info("Result: " + value);
            }
            return answer;
        }
    } catch (J4pRemoteException e) {
        if (e.getMessage().contains(".InstanceNotFoundException")) {
            throw new MojoExecutionException("Could not find the mbean " + mbeanName + " in the JVM for " + jolokiaUrl + ". Are you sure this JVM is running the Fabric8 console?");
        } else {
            getLog().error("Failed to invoke mbean " + mbeanName + " on jolokia URL: " + jolokiaUrl + " with user: " + fabricServer.getUsername() + ". Error: " + e.getErrorType());
            getLog().error("Stack: " + e.getRemoteStackTrace());
            throw e;
        }
    }
}
Also used : J4pRemoteException(org.jolokia.client.exception.J4pRemoteException) DeployResults(io.fabric8.deployer.dto.DeployResults) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) J4pExecRequest(org.jolokia.client.request.J4pExecRequest) ObjectName(javax.management.ObjectName)

Example 17 with Resolver

use of io.fabric8.patch.management.conflicts.Resolver in project fabric8 by jboss-fuse.

the class ContainerPlaceholderResolverTest method testResolveAttributeCase.

@Test
public void testResolveAttributeCase() throws Exception {
    PlaceholderResolver resolver = getContainerPlaceholderResolver();
    assertEquals(ip, resolver.resolve(fabricService, null, null, null, "container:root/IP"));
    assertEquals(localhostname, resolver.resolve(fabricService, null, null, null, "container:root/LocalHostName"));
    assertEquals(bindaddress, resolver.resolve(fabricService, null, null, null, "container:root/Bindaddress"));
    assertEquals(containerResolver, resolver.resolve(fabricService, null, null, null, "container:root/Resolver"));
    verify(fabricService);
    verify(dataStore);
}
Also used : PlaceholderResolver(io.fabric8.api.PlaceholderResolver) Test(org.junit.Test)

Example 18 with Resolver

use of io.fabric8.patch.management.conflicts.Resolver in project fabric8 by jboss-fuse.

the class ContainerPlaceholderResolverTest method testResolveCurrentName.

@Test
@Ignore("[FABRIC-1110] Mocked test makes invalid assumption on the implementation")
public void testResolveCurrentName() throws Exception {
    final FabricService fabricService = createMock(FabricService.class);
    final DataStore dataStore = createMock(DataStore.class);
    expect(fabricService.getCurrentContainerName()).andReturn("root").anyTimes();
    expect(fabricService.getContainer(EasyMock.<String>anyObject())).andReturn(new ContainerImpl(null, "root", fabricService));
    replay(fabricService);
    replay(dataStore);
    PlaceholderResolver resolver = getContainerPlaceholderResolver();
    assertEquals("root", resolver.resolve(fabricService, null, null, null, "container:name"));
    verify(fabricService);
    verify(dataStore);
}
Also used : FabricService(io.fabric8.api.FabricService) ContainerImpl(io.fabric8.internal.ContainerImpl) DataStore(io.fabric8.api.DataStore) PlaceholderResolver(io.fabric8.api.PlaceholderResolver) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 19 with Resolver

use of io.fabric8.patch.management.conflicts.Resolver in project fabric8 by jboss-fuse.

the class EncryptedPropertyResolverTest method testResolve.

@Test
public void testResolve() throws Exception {
    CuratorFramework curator = createMock(CuratorFramework.class);
    GetDataBuilder getDataBuilder = createMock(GetDataBuilder.class);
    expect(curator.getData()).andReturn(getDataBuilder).anyTimes();
    expect(getDataBuilder.forPath(AUTHENTICATION_CRYPT_ALGORITHM.getPath())).andReturn("PBEWithMD5AndDES".getBytes()).anyTimes();
    expect(getDataBuilder.forPath(AUTHENTICATION_CRYPT_PASSWORD.getPath())).andReturn("mypassword".getBytes()).anyTimes();
    replay(curator);
    replay(getDataBuilder);
    FabricService fabricService = createMock(FabricService.class);
    expect(fabricService.adapt(CuratorFramework.class)).andReturn(curator).anyTimes();
    replay(fabricService);
    PlaceholderResolver resolver = getEncryptedPropertyResolver();
    assertEquals("encryptedpassword", resolver.resolve(fabricService, null, null, null, "crypt:URdoo9++D3tsoC9ODrTfLNK5WzviknO3Ig6qbI2HuvQ="));
    verify(curator);
    verify(getDataBuilder);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) FabricService(io.fabric8.api.FabricService) GetDataBuilder(org.apache.curator.framework.api.GetDataBuilder) PlaceholderResolver(io.fabric8.api.PlaceholderResolver) Test(org.junit.Test)

Example 20 with Resolver

use of io.fabric8.patch.management.conflicts.Resolver in project fabric8 by jboss-fuse.

the class EncryptedPropertyResolverTest method testResolveZkEnc.

@Test
public void testResolveZkEnc() throws Exception {
    CuratorFramework curator = createMock(CuratorFramework.class);
    GetDataBuilder getDataBuilder = createMock(GetDataBuilder.class);
    expect(curator.getData()).andReturn(getDataBuilder).anyTimes();
    expect(getDataBuilder.forPath(AUTHENTICATION_CRYPT_ALGORITHM.getPath())).andReturn("PBEWithMD5AndDES".getBytes()).anyTimes();
    expect(getDataBuilder.forPath(AUTHENTICATION_CRYPT_PASSWORD.getPath())).andReturn("ZKENC=bXlwYXNzd29yZA==".getBytes()).anyTimes();
    replay(curator);
    replay(getDataBuilder);
    FabricService fabricService = createMock(FabricService.class);
    expect(fabricService.adapt(CuratorFramework.class)).andReturn(curator).anyTimes();
    replay(fabricService);
    PlaceholderResolver resolver = getEncryptedPropertyResolver();
    assertEquals("encryptedpassword", resolver.resolve(fabricService, null, null, null, "crypt:URdoo9++D3tsoC9ODrTfLNK5WzviknO3Ig6qbI2HuvQ="));
    verify(curator);
    verify(getDataBuilder);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) FabricService(io.fabric8.api.FabricService) GetDataBuilder(org.apache.curator.framework.api.GetDataBuilder) PlaceholderResolver(io.fabric8.api.PlaceholderResolver) Test(org.junit.Test)

Aggregations

File (java.io.File)23 MavenResolver (io.fabric8.maven.MavenResolver)22 Test (org.junit.Test)21 IOException (java.io.IOException)20 FabricService (io.fabric8.api.FabricService)10 Container (io.fabric8.api.Container)9 RuntimeProperties (io.fabric8.api.RuntimeProperties)7 HashMap (java.util.HashMap)7 PlaceholderResolver (io.fabric8.api.PlaceholderResolver)6 HashSet (java.util.HashSet)6 Hashtable (java.util.Hashtable)6 Metadata (org.apache.maven.artifact.repository.metadata.Metadata)6 Map (java.util.Map)5 DownloadManager (io.fabric8.agent.download.DownloadManager)4 AbstractRuntimeProperties (io.fabric8.api.scr.AbstractRuntimeProperties)4 MavenConfigurationImpl (io.fabric8.maven.util.MavenConfigurationImpl)4 FileInputStream (java.io.FileInputStream)4 URI (java.net.URI)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4