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);
}
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();
}
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);
}
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());
}
}
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();
}
}
Aggregations