use of io.fabric8.openshift.client.OpenShiftClient in project fabric8-maven-plugin by fabric8io.
the class Fabric8ServiceHub method init.
private void init() {
Objects.requireNonNull(clusterAccess, "clusterAccess");
Objects.requireNonNull(log, "log");
this.resolvedMode = clusterAccess.resolvePlatformMode(platformMode, log);
if (resolvedMode != PlatformMode.kubernetes && resolvedMode != PlatformMode.openshift) {
throw new IllegalArgumentException("Unknown platform mode " + platformMode + " resolved as " + resolvedMode);
}
this.client = clusterAccess.createDefaultClient(log);
if (this.controller == null) {
this.controller = new Controller(this.client);
this.controller.setThrowExceptionOnError(true);
}
// Lazily building services
this.services.putIfAbsent(ClientToolsService.class, new LazyBuilder<ClientToolsService>() {
@Override
protected ClientToolsService build() {
return new ClientToolsService(controller, log);
}
});
this.services.putIfAbsent(PortForwardService.class, new LazyBuilder<PortForwardService>() {
@Override
protected PortForwardService build() {
return new PortForwardService(getClientToolsService(), log, client);
}
});
this.services.putIfAbsent(BuildService.class, new LazyBuilder<BuildService>() {
@Override
protected BuildService build() {
BuildService buildService;
// Creating platform-dependent services
if (resolvedMode == PlatformMode.openshift) {
// Openshift services
buildService = new OpenshiftBuildService((OpenShiftClient) client, log, dockerServiceHub, buildServiceConfig);
} else {
// Kubernetes services
buildService = new DockerBuildService(dockerServiceHub, buildServiceConfig);
}
return buildService;
}
});
this.services.putIfAbsent(ArtifactResolverService.class, new LazyBuilder<ArtifactResolverService>() {
@Override
protected ArtifactResolverService build() {
return new ArtifactResolverServiceMavenImpl(repositorySystem, mavenProject);
}
});
}
use of io.fabric8.openshift.client.OpenShiftClient in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildService method applyResourceObjects.
private void applyResourceObjects(BuildServiceConfig config, OpenShiftClient client, KubernetesListBuilder builder) throws Exception {
// Adding a workaround to handle intermittent Socket closed errors while
// building on OpenShift. See https://github.com/fabric8io/fabric8-maven-plugin/issues/1133
// for more details.
int nTries = 0;
boolean bResourcesCreated = false;
Exception buildException = null;
do {
try {
if (config.getEnricherTask() != null) {
config.getEnricherTask().execute(builder);
}
if (builder.hasItems()) {
KubernetesList k8sList = builder.build();
client.lists().create(k8sList);
}
// If we are here, it means resources got created successfully.
bResourcesCreated = true;
} catch (Exception aException) {
// Retry only when Exception is of socket closed message.
if (aException.getMessage() != null && aException.getMessage().contains("Socket closed")) {
log.warn("Problem encountered while applying resource objects, retrying..");
buildException = aException;
nTries++;
Thread.sleep(RESOURCE_CREATION_RETRY_TIMEOUT_IN_MILLIS);
// Make a connection to cluster again.
client = clusterAccess.createDefaultClient(log);
} else {
// and simply throw as it is.
throw new MojoExecutionException(aException.getMessage());
}
}
} while (nTries < RESOURCE_CREATION_RETRIES && !bResourcesCreated);
if (!bResourcesCreated)
throw new MojoExecutionException(buildException.getMessage());
}
use of io.fabric8.openshift.client.OpenShiftClient in project fabric8-maven-plugin by fabric8io.
the class ClusterAccessTest method createClientTestOpenshift.
@Test
public void createClientTestOpenshift() throws Exception {
paths.add("/oapi");
paths.add("/oapi/v1");
RootPaths rootpaths = new RootPaths();
rootpaths.setPaths(paths);
mockServer.expect().get().withPath("/").andReturn(200, rootpaths).always();
ClusterAccess clusterAccess = new ClusterAccess(null, client);
Client outputClient = clusterAccess.createDefaultClient(logger);
assertTrue(outputClient instanceof OpenShiftClient);
}
use of io.fabric8.openshift.client.OpenShiftClient in project fabric8-maven-plugin by fabric8io.
the class OpenshiftBuildServiceTest method checkTarPackage.
@Test
public void checkTarPackage() throws Exception {
int nTries = 0;
boolean bTestComplete = false;
do {
try {
nTries++;
BuildService.BuildServiceConfig config = defaultConfig.build();
WebServerEventCollector<OpenShiftMockServer> collector = createMockServer(config, true, 50, true, true);
OpenShiftMockServer mockServer = collector.getMockServer();
OpenShiftClient client = mockServer.createOpenShiftClient();
final OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
ImageConfiguration imageWithEnv = new ImageConfiguration.Builder(image).buildConfig(new BuildImageConfiguration.Builder(image.getBuildConfiguration()).env(Collections.singletonMap("FOO", "BAR")).build()).build();
service.createBuildArchive(imageWithEnv);
final List<ArchiverCustomizer> customizer = new LinkedList<>();
new Verifications() {
{
archiveService.createDockerBuildArchive(withInstanceOf(ImageConfiguration.class), withInstanceOf(MojoParameters.class), withCapture(customizer));
assertTrue(customizer.size() == 1);
}
};
customizer.get(0).customize(tarArchiver);
final List<File> file = new LinkedList<>();
new Verifications() {
{
String path;
tarArchiver.addFile(withCapture(file), path = withCapture());
assertEquals(".s2i/environment", path);
}
};
assertEquals(1, file.size());
List<String> lines;
try (FileReader reader = new FileReader(file.get(0))) {
lines = IOUtils.readLines(reader);
}
assertTrue(lines.contains("FOO=BAR"));
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.openshift.client.OpenShiftClient in project kie-wb-common by kiegroup.
the class OpenShiftAccessInterfaceImpl method getOpenShiftClient.
@Override
public OpenShiftClient getOpenShiftClient(final ProviderId providerId) {
if (!clientMap.containsKey(providerId.getId())) {
checkInstanceOf("providerId", providerId, OpenShiftProvider.class);
ProviderConfig providerConfig = ((OpenShiftProvider) providerId).getConfig();
OpenShiftClient client = newOpenShiftClient(providerConfig);
clientMap.put(providerId.getId(), client);
}
return clientMap.get(providerId.getId());
}
Aggregations