Search in sources :

Example 11 with Check

use of io.fabric8.karaf.checks.Check in project docker-maven-plugin by fabric8io.

the class AuthConfigTest method simpleConstructor.

@Test
public void simpleConstructor() {
    Map<String, String> map = new HashMap<String, String>();
    map.put("username", "roland");
    map.put("password", "secret");
    map.put("email", "roland@jolokia.org");
    AuthConfig config = new AuthConfig(map);
    check(config);
}
Also used : HashMap(java.util.HashMap) AuthConfig(io.fabric8.maven.docker.access.AuthConfig) Test(org.junit.Test)

Example 12 with Check

use of io.fabric8.karaf.checks.Check in project docker-maven-plugin by fabric8io.

the class AuthConfigTest method dockerLoginConstructor.

@Test
public void dockerLoginConstructor() {
    AuthConfig config = new AuthConfig(Base64.encodeBase64String("roland:secret".getBytes()), "roland@jolokia.org");
    check(config);
}
Also used : AuthConfig(io.fabric8.maven.docker.access.AuthConfig) Test(org.junit.Test)

Example 13 with Check

use of io.fabric8.karaf.checks.Check in project fabric8 by jboss-fuse.

the class ContainerEditJvmOptionsAction method doExecute.

protected Object doExecute() throws Exception {
    validateContainerName(container);
    if (!FabricCommand.doesContainerExist(fabricService, container)) {
        System.out.println("Container " + container + " does not exists!");
        return null;
    }
    Container containerInstance = FabricCommand.getContainerIfExists(fabricService, container);
    String type = containerInstance.getType();
    if (!"karaf".equals(type)) {
        System.out.println("Sorry, currently only \"karaf\" type container are supported");
        return null;
    }
    // read current jvm values
    FabricManager fabricManager = new FabricManager(fabricService);
    if (full) {
        String jmxUrl = null;
        JMXConnector connector = null;
        MBeanServerConnection remote = null;
        HashMap<String, String[]> authenticationData = null;
        jmxUrl = containerInstance.getJmxUrl();
        authenticationData = prepareAuthenticationData();
        try {
            connector = connectOrRetry(authenticationData, jmxUrl);
        } catch (Exception e) {
            username = null;
            password = null;
            System.out.println("Operation Failed. Check logs.");
            log.error("Unable to connect to JMX Server", e);
            return null;
        }
        ObjectName objName = new ObjectName(JAVA_LANG_OBJECT_NAME);
        try {
            remote = connector.getMBeanServerConnection();
            String[] arguments = (String[]) remote.getAttribute(objName, "InputArguments");
            String output = Arrays.toString(arguments);
            output = output.replaceAll(",", "");
            output = output.substring(1, output.length() - 1);
            System.out.println(output);
        } catch (Exception e) {
            System.out.println("Operation Failed. Check logs.");
            log.error("Unable to fetch child jvm opts", e);
        }
        try {
            connector.close();
        } catch (IOException e) {
            log.error("Errors closing remote MBean connection", e);
        }
    } else {
        try {
            String output = fabricManager.getJvmOpts(container);
            if ("Inapplicable".equals(output)) {
                String message = container + " jvmOpts cannot be handled within Fabric. You have to set required values directly in startup scripts.";
                System.out.println(message);
                log.error(message);
                return null;
            }
            if (jvmOptions == null) {
                System.out.println(output);
            } else {
                fabricManager.setJvmOpts(container, jvmOptions);
                System.out.println("Operation succeeded. New JVM flags will be loaded at the next start of " + container + " container");
                log.info("Updated JVM flags for container {}", container);
            }
        } catch (Exception e) {
            System.out.println("Operation Failed. Check logs.");
            log.error("Unable to set ssh jvm opts", e);
        }
    }
    return null;
}
Also used : Container(io.fabric8.api.Container) FabricManager(io.fabric8.core.jmx.FabricManager) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection) FabricAuthenticationException(io.fabric8.api.FabricAuthenticationException) IOException(java.io.IOException) ObjectName(javax.management.ObjectName)

Example 14 with Check

use of io.fabric8.karaf.checks.Check in project fabric8 by jboss-fuse.

the class OpenShiftPomDeployerTest method doTest.

protected void doTest(String folder, String[] artifactUrls, String[] repoUrls, String expectedCamelDependencyScope, String expectedHawtioDependencyScope) throws Exception {
    File sourceDir = new File(baseDir, "src/test/resources/" + folder);
    assertDirectoryExists(sourceDir);
    File pomSource = new File(sourceDir, "pom.xml");
    assertFileExists(pomSource);
    File outputDir = new File(baseDir, "target/" + getClass().getName() + "/" + folder);
    outputDir.mkdirs();
    assertDirectoryExists(outputDir);
    File pom = new File(outputDir, "pom.xml");
    Files.copy(pomSource, pom);
    assertFileExists(pom);
    git = Git.init().setDirectory(outputDir).setGitDir(new File(outputDir, ".git")).call();
    assertDirectoryExists(new File(outputDir, ".git"));
    git.add().addFilepattern("pom.xml").call();
    git.commit().setMessage("Initial import").call();
    // now we have the git repo setup; lets run the update
    OpenShiftPomDeployer deployer = new OpenShiftPomDeployer(git, outputDir, deployDir, webAppDir);
    System.out.println("About to update the pom " + pom + " with artifacts: " + Arrays.asList(artifactUrls));
    List<Parser> artifacts = new ArrayList<Parser>();
    for (String artifactUrl : artifactUrls) {
        artifacts.add(Parser.parsePathWithSchemePrefix(artifactUrl));
    }
    List<MavenRepositoryURL> repos = new ArrayList<MavenRepositoryURL>();
    for (String repoUrl : repoUrls) {
        repos.add(new MavenRepositoryURL(repoUrl));
    }
    deployer.update(artifacts, repos);
    System.out.println("Completed the new pom is: ");
    System.out.println(Files.toString(pom));
    Document xml = XmlUtils.parseDoc(pom);
    Element plugins = assertXPathElement(xml, "project/profiles/profile[id = 'openshift']/build/plugins");
    Element cleanExecution = assertXPathElement(plugins, "plugin[artifactId = 'maven-clean-plugin']/executions/execution[id = 'fuse-fabric-clean']");
    Element dependencySharedExecution = assertXPathElement(plugins, "plugin[artifactId = 'maven-dependency-plugin']/executions/execution[id = 'fuse-fabric-deploy-shared']");
    Element dependencyWebAppsExecution = assertXPathElement(plugins, "plugin[artifactId = 'maven-dependency-plugin']/executions/execution[id = 'fuse-fabric-deploy-webapps']");
    Element warPluginWarName = xpath("plugin[artifactId = 'maven-war-plugin']/configuration/warName").element(plugins);
    if (warPluginWarName != null) {
        String warName = warPluginWarName.getTextContent();
        System.out.println("WarName is now:  " + warName);
        assertTrue("Should not have ROOT war name", !"ROOT".equals(warName));
    }
    Element dependencies = assertXPathElement(xml, "project/dependencies");
    Element repositories = assertXPathElement(xml, "project/repositories");
    for (Parser artifact : artifacts) {
        // lets check there's only 1 dependency for group & artifact and it has the right version
        String group = groupId(artifact);
        String artifactId = artifact.getArtifact();
        Element dependency = assertSingleDependencyForGroupAndArtifact(dependencies, group, artifactId);
        Element version = assertXPathElement(dependency, "version");
        assertEquals("Version", artifact.getVersion(), version.getTextContent());
    }
    // lets check we either preserve scope, add provided or don't add a scope if there's none present in the underlying pom
    assertDependencyScope(dependencies, "org.apache.camel", "camel-core", expectedCamelDependencyScope);
    assertDependencyScope(dependencies, "org.drools", "drools-wb-distribution-wars", "provided");
    assertDependencyScope(dependencies, "io.hawt", "hawtio-web", expectedHawtioDependencyScope);
    assertRepositoryUrl(repositories, "https://maven.repository.redhat.com/ga/");
    assertRepositoryUrl(repositories, "https://repo.fusesource.com/nexus/content/groups/ea/");
}
Also used : OpenShiftPomDeployer(io.fabric8.openshift.agent.OpenShiftPomDeployer) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) MavenRepositoryURL(io.fabric8.maven.util.MavenRepositoryURL) Document(org.w3c.dom.Document) File(java.io.File) Parser(io.fabric8.maven.util.Parser)

Example 15 with Check

use of io.fabric8.karaf.checks.Check in project fabric8 by jboss-fuse.

the class ApmAgentContext method buildDeltaList.

public List<ClassInfo> buildDeltaList() {
    List<ClassInfo> result = new ArrayList<>();
    for (ClassInfo classInfo : allMethods.values()) {
        if (classInfo.isTransformed()) {
            // check to see its still should be audited
            if (configuration.isAudit(classInfo.getClassName())) {
                boolean retransform = false;
                // check to see if there's a change to methods that should be transformed
                Set<String> transformedMethodNames = classInfo.getAllTransformedMethodNames();
                for (String methodName : transformedMethodNames) {
                    if (!configuration.isAudit(classInfo.getClassName(), methodName)) {
                        retransform = true;
                        break;
                    }
                }
                if (!retransform) {
                    // check to see if there are methods that should now be audited but weren't
                    Set<String> allMethodNames = classInfo.getAllMethodNames();
                    for (String methodName : allMethodNames) {
                        if (!transformedMethodNames.contains(methodName) && configuration.isAudit(classInfo.getClassName(), methodName)) {
                            retransform = true;
                            break;
                        }
                    }
                }
                if (retransform) {
                    result.add(classInfo);
                }
            } else {
                // we were once audited - but now need to be removed
                result.add(classInfo);
            }
        } else if (configuration.isAudit(classInfo.getClassName())) {
            if (classInfo.isCanTransform()) {
                result.add(classInfo);
            }
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ClassInfo(io.fabric8.apmagent.ClassInfo)

Aggregations

Test (org.junit.Test)35 IOException (java.io.IOException)21 File (java.io.File)17 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)14 FabricService (io.fabric8.api.FabricService)11 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)11 Container (io.fabric8.api.Container)9 PatchException (io.fabric8.patch.management.PatchException)9 Expectations (mockit.Expectations)9 Profile (io.fabric8.api.Profile)8 Map (java.util.Map)7 TreeMap (java.util.TreeMap)7 Version (io.fabric8.api.Version)6 AuthConfig (io.fabric8.maven.docker.access.AuthConfig)6 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6 Check (io.fabric8.karaf.checks.Check)5 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)5 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)5 Patch (io.fabric8.patch.management.Patch)5