Search in sources :

Example 61 with Logger

use of io.fabric8.arquillian.kubernetes.log.Logger in project fabric8-maven-plugin by fabric8io.

the class OpenshiftBuildServiceTest method testSuccessfulBuild.

@Test
public void testSuccessfulBuild() throws Exception {
    int nTries = 0;
    boolean bTestComplete = false;
    do {
        try {
            nTries++;
            BuildService.BuildServiceConfig config = defaultConfig.build();
            WebServerEventCollector<OpenShiftMockServer> collector = createMockServer(config, true, 50, false, false);
            OpenShiftMockServer mockServer = collector.getMockServer();
            DefaultOpenShiftClient client = (DefaultOpenShiftClient) mockServer.createOpenShiftClient();
            LOG.info("Current write timeout is : {}", client.getHttpClient().writeTimeoutMillis());
            LOG.info("Current read timeout is : {}", client.getHttpClient().readTimeoutMillis());
            LOG.info("Retry on failure : {}", client.getHttpClient().retryOnConnectionFailure());
            OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
            service.build(image);
            // we should Foadd a better way to assert that a certain call has been made
            assertTrue(mockServer.getRequestCount() > 8);
            collector.assertEventsRecordedInOrder("build-config-check", "new-build-config", "pushed");
            collector.assertEventsNotRecorded("patch-build-config");
            bTestComplete = true;
        } catch (Fabric8ServiceException exception) {
            Throwable rootCause = getRootCause(exception);
            logger.warn("A problem encountered while running test {}, retrying..", exception.getMessage());
            // Let's wait for a while, and then retry again
            if (rootCause != null && rootCause instanceof IOException) {
                continue;
            }
        }
    } while (nTries < MAX_TIMEOUT_RETRIES && !bTestComplete);
}
Also used : OpenShiftMockServer(io.fabric8.openshift.client.server.mock.OpenShiftMockServer) Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException) BuildService(io.fabric8.maven.core.service.BuildService) IOException(java.io.IOException) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient) Test(org.junit.Test)

Example 62 with Logger

use of io.fabric8.arquillian.kubernetes.log.Logger in project fabric8-maven-plugin by fabric8io.

the class ResourceValidatorTest method testInvalidOpenshiftDeployConfig.

@Test
public void testInvalidOpenshiftDeployConfig() throws IOException, URISyntaxException {
    // Given
    URL fileUrl = ResourceValidatorTest.class.getResource("/validations/openshift-invalid-deploymentconfig.yml");
    // When
    ResourceValidator resourceValidator = new ResourceValidator(Paths.get(fileUrl.toURI()).toFile(), ResourceClassifier.OPENSHIFT, logger);
    // Then
    thrown.expect(ConstraintViolationException.class);
    thrown.expect(Matchers.hasProperty("constraintViolations", IsCollectionWithSize.hasSize(1)));
    // On
    resourceValidator.validate();
}
Also used : ResourceValidator(io.fabric8.maven.core.util.validator.ResourceValidator) URL(java.net.URL) Test(org.junit.Test)

Example 63 with Logger

use of io.fabric8.arquillian.kubernetes.log.Logger in project fabric8-maven-plugin by fabric8io.

the class ResourceValidatorTest method testValidKubernetesResources.

@Test
public void testValidKubernetesResources() throws IOException, URISyntaxException {
    // Given
    URL fileUrl = ResourceValidatorTest.class.getResource("/validations/kubernetes-deploy.yml");
    // When
    ResourceValidator resourceValidator = new ResourceValidator(Paths.get(fileUrl.toURI()).toFile(), ResourceClassifier.KUBERNETES, logger);
    int validResources = resourceValidator.validate();
    // Then
    Assert.assertEquals(1, validResources);
}
Also used : ResourceValidator(io.fabric8.maven.core.util.validator.ResourceValidator) URL(java.net.URL) Test(org.junit.Test)

Example 64 with Logger

use of io.fabric8.arquillian.kubernetes.log.Logger in project fabric8-maven-plugin by fabric8io.

the class SpringBootWatcher method runRemoteSpringApplication.

private void runRemoteSpringApplication(String url) {
    log.info("Running RemoteSpringApplication against endpoint: " + url);
    Properties properties = SpringBootUtil.getSpringBootApplicationProperties(getContext().getProject());
    String remoteSecret = properties.getProperty(DEV_TOOLS_REMOTE_SECRET, System.getProperty(DEV_TOOLS_REMOTE_SECRET));
    if (Strings.isNullOrBlank(remoteSecret)) {
        log.warn("There is no `%s` property defined in your src/main/resources/application.properties. Please add one!", DEV_TOOLS_REMOTE_SECRET);
        throw new IllegalStateException("No " + DEV_TOOLS_REMOTE_SECRET + " property defined in application.properties or system properties");
    }
    ClassLoader classLoader = getClass().getClassLoader();
    if (classLoader instanceof URLClassLoader) {
        URLClassLoader pluginClassLoader = (URLClassLoader) classLoader;
        URLClassLoader projectClassLoader = ClassUtil.createProjectClassLoader(getContext().getProject(), log);
        URLClassLoader[] classLoaders = { projectClassLoader, pluginClassLoader };
        StringBuilder buffer = new StringBuilder("java -cp ");
        int count = 0;
        for (URLClassLoader urlClassLoader : classLoaders) {
            URL[] urLs = urlClassLoader.getURLs();
            for (URL u : urLs) {
                if (count++ > 0) {
                    buffer.append(File.pathSeparator);
                }
                try {
                    URI uri = u.toURI();
                    File file = new File(uri);
                    buffer.append(file.getCanonicalPath());
                } catch (Exception e) {
                    throw new IllegalStateException("Failed to create classpath: " + e, e);
                }
            }
        }
        // Add dev tools to the classpath (the main class is not read from BOOT-INF/lib)
        try {
            File devtools = getSpringBootDevToolsJar(getContext().getProject());
            buffer.append(File.pathSeparator);
            buffer.append(devtools.getCanonicalPath());
        } catch (Exception e) {
            throw new IllegalStateException("Failed to include devtools in the classpath: " + e, e);
        }
        buffer.append(" -Dspring.devtools.remote.secret=");
        buffer.append(remoteSecret);
        buffer.append(" org.springframework.boot.devtools.RemoteSpringApplication ");
        buffer.append(url);
        try {
            String command = buffer.toString();
            log.debug("Running: " + command);
            final Process process = Runtime.getRuntime().exec(command);
            final AtomicBoolean outputEnabled = new AtomicBoolean(true);
            Runtime.getRuntime().addShutdownHook(new Thread("fabric8:watch [spring-boot] shutdown hook") {

                @Override
                public void run() {
                    log.info("Terminating the Spring remote client...");
                    outputEnabled.set(false);
                    process.destroy();
                }
            });
            Logger logger = new PrefixedLogger("Spring-Remote", log);
            Thread stdOutPrinter = startOutputProcessor(logger, process.getInputStream(), false, outputEnabled);
            Thread stdErrPrinter = startOutputProcessor(logger, process.getErrorStream(), true, outputEnabled);
            int status = process.waitFor();
            stdOutPrinter.join();
            stdErrPrinter.join();
            if (status != 0) {
                log.warn("Process returned status: %s", status);
            }
        } catch (Exception e) {
            throw new RuntimeException("Failed to run RemoteSpringApplication: " + e, e);
        }
    } else {
        throw new IllegalStateException("ClassLoader must be a URLClassLoader but it is: " + classLoader.getClass().getName());
    }
}
Also used : Properties(java.util.Properties) Logger(io.fabric8.maven.docker.util.Logger) PrefixedLogger(io.fabric8.maven.core.util.PrefixedLogger) URI(java.net.URI) URL(java.net.URL) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PrefixedLogger(io.fabric8.maven.core.util.PrefixedLogger) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) File(java.io.File)

Example 65 with Logger

use of io.fabric8.arquillian.kubernetes.log.Logger in project docker-maven-plugin by fabric8io.

the class JibServiceUtil method jibPush.

/**
 * Push Image to registry using JIB
 *
 * @param imageConfiguration ImageConfiguration
 * @param pushCredentials    push credentials
 * @param tarArchive         tar archive built during build goal
 * @param log                Logger
 */
public static void jibPush(ImageConfiguration imageConfiguration, Credential pushCredentials, File tarArchive, Logger log) {
    BuildImageConfiguration buildImageConfiguration = imageConfiguration.getBuildConfiguration();
    String imageName = getFullImageName(imageConfiguration, null);
    try {
        for (String tag : getAllImageTags(buildImageConfiguration.getTags(), imageName)) {
            String imageNameWithTag = getFullImageName(imageConfiguration, tag);
            log.info("Pushing image: %s", imageNameWithTag);
            pushImage(TarImage.at(tarArchive.toPath()), imageNameWithTag, pushCredentials, log);
        }
    } catch (IllegalStateException e) {
        log.error("Exception occurred while pushing the image: %s", imageConfiguration.getName());
        throw new IllegalStateException(e.getMessage(), e);
    } catch (InterruptedException e) {
        log.error("Thread interrupted", e);
        Thread.currentThread().interrupt();
    }
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Aggregations

Test (org.junit.Test)47 File (java.io.File)26 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)20 Verifications (mockit.Verifications)17 ArrayList (java.util.ArrayList)15 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)12 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)10 IOException (java.io.IOException)9 Expectations (mockit.Expectations)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 AssemblyConfiguration (io.fabric8.maven.docker.config.AssemblyConfiguration)6 Logger (io.fabric8.maven.docker.util.Logger)6 MojoParameters (io.fabric8.maven.docker.util.MojoParameters)6 Properties (java.util.Properties)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