Search in sources :

Example 41 with Logger

use of io.fabric8.maven.docker.util.Logger in project fabric8 by jboss-fuse.

the class SubsystemResolver method resolve.

public Map<Resource, List<Wire>> resolve(MetadataBuilder builder, Set<String> overrides, String featureResolutionRange, final org.osgi.service.repository.Repository globalRepository) throws Exception {
    if (root == null) {
        return Collections.emptyMap();
    }
    // Download bundles
    root.downloadBundles(manager, builder, overrides, featureResolutionRange);
    // Populate digraph and resolve
    digraph = new StandardRegionDigraph(null, null);
    populateDigraph(digraph, root);
    Resolver resolver = new ResolverImpl(new Slf4jResolverLog(LOGGER));
    Downloader downloader = manager.createDownloader();
    wiring = resolver.resolve(new SubsystemResolveContext(root, digraph, globalRepository, downloader));
    downloader.await();
    // Remove wiring to the fake environment resource
    if (environmentResource != null) {
        for (List<Wire> wires : wiring.values()) {
            for (Iterator<Wire> iterator = wires.iterator(); iterator.hasNext(); ) {
                Wire wire = iterator.next();
                if (wire.getProvider() == environmentResource) {
                    iterator.remove();
                }
            }
        }
    }
    // Fragments are always wired to their host only, so create fake wiring to
    // the subsystem the host is wired to
    associateFragments();
    return wiring;
}
Also used : Resolver(org.osgi.service.resolver.Resolver) Slf4jResolverLog(io.fabric8.agent.resolver.Slf4jResolverLog) Downloader(io.fabric8.agent.download.Downloader) ResolverImpl(org.apache.felix.resolver.ResolverImpl) Wire(org.osgi.resource.Wire) StandardRegionDigraph(org.eclipse.equinox.internal.region.StandardRegionDigraph)

Example 42 with Logger

use of io.fabric8.maven.docker.util.Logger in project fabric8 by jboss-fuse.

the class Log4jLogQuery method toLogEvent.

protected LogEvent toLogEvent(LoggingEvent element) {
    LogEvent answer = new LogEvent();
    answer.setClassName(element.getFQNOfLoggerClass());
    // TODO
    // answer.setContainerName(element.get);
    ThrowableInformation throwableInformation = element.getThrowableInformation();
    if (throwableInformation != null) {
        ThrowableFormatter renderer = new ThrowableFormatter();
        String[] stack = renderer.doRender(throwableInformation.getThrowable());
        if (stack == null) {
            stack = element.getThrowableStrRep();
        }
        answer.setException(stack);
    }
    LocationInfo locationInformation = element.getLocationInformation();
    if (locationInformation != null) {
        answer.setFileName(locationInformation.getFileName());
        answer.setClassName(locationInformation.getClassName());
        answer.setMethodName(locationInformation.getMethodName());
        answer.setLineNumber(locationInformation.getLineNumber());
    }
    Level level = element.getLevel();
    if (level != null) {
        answer.setLevel(level.toString());
    }
    // TODO
    answer.setLogger(element.getLoggerName());
    Category logger = element.getLogger();
    Object message = element.getMessage();
    if (message != null) {
        // TODO marshal differently?
        answer.setMessage(message.toString());
    }
    answer.setProperties(element.getProperties());
    // TODO
    answer.setSeq(element.getTimeStamp());
    answer.setTimestamp(new Date(element.getTimeStamp()));
    answer.setThread(element.getThreadName());
    answer.setHost(getHostName());
    return answer;
}
Also used : Category(org.apache.log4j.Category) LogEvent(io.fabric8.insight.log.LogEvent) ThrowableInformation(org.apache.log4j.spi.ThrowableInformation) Level(org.apache.log4j.Level) Date(java.util.Date) LocationInfo(org.apache.log4j.spi.LocationInfo)

Example 43 with Logger

use of io.fabric8.maven.docker.util.Logger in project fabric8 by jboss-fuse.

the class ExceptionMavenCoordsTest method testQueryOfLogMessages.

@Test
public void testQueryOfLogMessages() throws Exception {
    Logger testLog = LoggerFactory.getLogger("io.fabric8.insight.log.log4j.TestLogger");
    // now lets force an exception with a stack trace from camel...
    try {
        CamelContextHelper.getMandatoryEndpoint(null, null);
    } catch (Throwable e) {
        testLog.error("Expected exception for testing: " + e, e);
    }
    // now lets find the error
    LogResults results = logQuery.allLogResults();
    List<LogEvent> logEvents = Log4jTest.assertNotEmpty(results);
    LogEvent log = logEvents.get(0);
    assertNotNull("Should have a log event", log);
    List<String> list = Arrays.asList(log.getException());
    assertTrue("Should have more than 1 items in the stack trace but got: " + list, list.size() > 1);
    String first = list.get(1);
    LOG.info("First line: " + first);
    String expects = "[org.apache.camel:camel-core:";
    assertTrue("Should have camel coordinate '" + expects + "' but got " + first, first.indexOf(expects) > 0);
    for (String line : list) {
        LOG.info(line);
    }
}
Also used : LogResults(io.fabric8.insight.log.LogResults) LogEvent(io.fabric8.insight.log.LogEvent) Logger(org.slf4j.Logger) Test(org.junit.Test)

Example 44 with Logger

use of io.fabric8.maven.docker.util.Logger in project fabric8-maven-plugin by fabric8io.

the class ApplyMojo method applyEntities.

protected void applyEntities(Controller controller, KubernetesClient kubernetes, String namespace, String fileName, Set<HasMetadata> entities) throws Exception {
    // Apply all items
    for (HasMetadata entity : entities) {
        if (entity instanceof Pod) {
            Pod pod = (Pod) entity;
            controller.applyPod(pod, fileName);
        } else if (entity instanceof Service) {
            Service service = (Service) entity;
            controller.applyService(service, fileName);
        } else if (entity instanceof ReplicationController) {
            ReplicationController replicationController = (ReplicationController) entity;
            controller.applyReplicationController(replicationController, fileName);
        } else if (entity != null) {
            controller.apply(entity, fileName);
        }
    }
    String command = clusterAccess.isOpenShiftImageStream(log) ? "oc" : "kubectl";
    log.info("[[B]]HINT:[[B]] Use the command `%s get pods -w` to watch your pods start up", command);
    Logger serviceLogger = createExternalProcessLogger("[[G]][SVC][[G]] ");
    long serviceUrlWaitTimeSeconds = this.serviceUrlWaitTimeSeconds;
    for (HasMetadata entity : entities) {
        if (entity instanceof Service) {
            Service service = (Service) entity;
            String name = getName(service);
            Resource<Service, DoneableService> serviceResource = kubernetes.services().inNamespace(namespace).withName(name);
            String url = null;
            // lets wait a little while until there is a service URL in case the exposecontroller is running slow
            for (int i = 0; i < serviceUrlWaitTimeSeconds; i++) {
                if (i > 0) {
                    Thread.sleep(1000);
                }
                Service s = serviceResource.get();
                if (s != null) {
                    url = getExternalServiceURL(s);
                    if (Strings.isNotBlank(url)) {
                        break;
                    }
                }
                if (!isExposeService(service)) {
                    break;
                }
            }
            // lets not wait for other services
            serviceUrlWaitTimeSeconds = 1;
            if (Strings.isNotBlank(url) && url.startsWith("http")) {
                serviceLogger.info("" + name + ": " + url);
            }
        }
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Pod(io.fabric8.kubernetes.api.model.Pod) DoneableService(io.fabric8.kubernetes.api.model.DoneableService) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) DoneableService(io.fabric8.kubernetes.api.model.DoneableService) Service(io.fabric8.kubernetes.api.model.Service) KubernetesHelper.createIntOrString(io.fabric8.kubernetes.api.KubernetesHelper.createIntOrString) Logger(io.fabric8.maven.docker.util.Logger)

Example 45 with Logger

use of io.fabric8.maven.docker.util.Logger in project fabric8-maven-plugin by fabric8io.

the class JavaExecGeneratorMainClassDeterminationTest method testMainClassDeterminationFromConfig.

/**
 * The main class is determined via config in a non-fat-jar deployment
 * @throws MojoExecutionException
 */
@Test
public void testMainClassDeterminationFromConfig() throws MojoExecutionException {
    new MockBuild();
    new MockProcessorConfig("the.main.ClassName");
    new MockMavenProject();
    final GeneratorContext generatorContext = new GeneratorContext.Builder().project(new MavenProject()).config(new ProcessorConfig()).strategy(OpenShiftBuildStrategy.docker).logger(log).build();
    JavaExecGenerator generator = new JavaExecGenerator(generatorContext);
    final List<ImageConfiguration> images = new ArrayList<ImageConfiguration>();
    List<ImageConfiguration> customized = generator.customize(images, false);
    assertEquals("1 images returned", (long) 1, (long) customized.size());
    ImageConfiguration imageConfig = customized.get(0);
    assertEquals("Image name", "TheImageName", imageConfig.getName());
    assertEquals("Main Class set as environment variable", "the.main.ClassName", imageConfig.getBuildConfiguration().getEnv().get(JavaExecGenerator.JAVA_MAIN_CLASS_ENV_VAR));
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) ArrayList(java.util.ArrayList) GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)30 File (java.io.File)11 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)10 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 URL (java.net.URL)8 GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)7 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)6 ResourceValidator (io.fabric8.maven.core.util.validator.ResourceValidator)6 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)6 Logger (io.fabric8.maven.docker.util.Logger)6 Util.readAsString (io.fabric8.arquillian.utils.Util.readAsString)5 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)5 Pod (io.fabric8.kubernetes.api.model.Pod)5 OpenShiftMockServer (io.fabric8.openshift.client.server.mock.OpenShiftMockServer)5 Expectations (mockit.Expectations)5 Logger (io.fabric8.arquillian.kubernetes.log.Logger)4 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)4 BuildService (io.fabric8.maven.core.service.BuildService)4 Fabric8ServiceException (io.fabric8.maven.core.service.Fabric8ServiceException)4