下面列出了io.fabric8.kubernetes.api.model.NodeList#io.fabric8.kubernetes.client.dsl.internal.PodOperationsImpl 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void shouldCreateKubernetesClusterObject() throws Exception {
final KubernetesClient kubernetesClient = mock(KubernetesClient.class);
NodeOperationsImpl nodes = mock(NodeOperationsImpl.class);
PodOperationsImpl pods = mock(PodOperationsImpl.class);
when(nodes.list()).thenReturn(new NodeList());
when(kubernetesClient.nodes()).thenReturn(nodes);
when(pods.withLabel(Constants.CREATED_BY_LABEL_KEY, Constants.PLUGIN_ID)).thenReturn(pods);
when(pods.list()).thenReturn(new PodList());
when(kubernetesClient.pods()).thenReturn(pods);
final KubernetesCluster cluster = new KubernetesCluster(kubernetesClient);
verify(kubernetesClient, times(1)).nodes();
verify(kubernetesClient, times(1)).pods();
}
@Test
public void shouldBuildStatusReportView() throws Exception {
NodeOperationsImpl nodes = mock(NodeOperationsImpl.class);
PodOperationsImpl pods = mock(PodOperationsImpl.class);
when(nodes.list()).thenReturn(new NodeList());
when(kubernetesClient.nodes()).thenReturn(nodes);
when(pods.withLabel(Constants.CREATED_BY_LABEL_KEY, Constants.PLUGIN_ID)).thenReturn(pods);
when(pods.list()).thenReturn(new PodList());
when(kubernetesClient.pods()).thenReturn(pods);
final PluginStatusReportViewBuilder builder = mock(PluginStatusReportViewBuilder.class);
final Template template = mock(Template.class);
when(builder.getTemplate("status-report.template.ftlh")).thenReturn(template);
when(builder.build(eq(template), any(KubernetesCluster.class))).thenReturn("status-report");
final GoPluginApiResponse response = new ClusterStatusReportExecutor(request, builder, kubernetesClientFactory).execute();
assertThat(response.responseCode(), is(200));
assertThat(response.responseBody(), is("{\"view\":\"status-report\"}"));
}
protected void configureBuild(BuildStatus work) {
work.setStatus(Status.CONFIGURING);
configureService.execute(new Runnable() {
@Override
@SuppressFBWarnings("REC_CATCH_EXCEPTION")
public void run() {
info(work.getOpenShiftName(), "Publishing - Configuring ...");
String namespace = work.getNamespace();
PublishConfiguration publishConfig = work.getPublishConfiguration();
VDBMetaData vdb = publishConfig.getVDB();
String openShiftName = work.getOpenShiftName();
try {
OpenShiftClient client = openshiftClient();
info(openShiftName, "Publishing - Checking for base image");
// create build contents as tar file
info(openShiftName, "Publishing - Creating zip archive");
GenericArchive archive = ShrinkWrap.create(GenericArchive.class, "contents.tar");
String pomFile = generatePomXml(vdb, publishConfig.isEnableOData(), publishConfig.isSecurityEnabled());
debug(openShiftName, "Publishing - Generated pom file: " + StringConstants.NEW_LINE + pomFile);
archive.add(new StringAsset(pomFile), "pom.xml");
normalizeDataSourceNames(vdb);
AccessibleByteArrayOutputStream vdbContents = DefaultMetadataInstance.toBytes(vdb);
archive.add(new ByteArrayAsset(new ByteArrayInputStream(vdbContents.getBuffer(), 0, vdbContents.getCount())), "/src/main/resources/" + vdb.getName() + "-vdb.xml");
InputStream configIs = this.getClass().getClassLoader().getResourceAsStream("s2i/application.properties");
archive.add(new ByteArrayAsset(ObjectConverterUtil.convertToByteArray(configIs)),
"/src/main/resources/application.properties");
for (Model model : vdb.getModels()) {
if (model.isSource()) {
buildDataSourceBuilders(model, archive);
}
}
InputStream appIs = this.getClass().getClassLoader().getResourceAsStream("s2i/Application.java");
archive.add(new ByteArrayAsset(ObjectConverterUtil.convertToByteArray(appIs)),
"/src/main/java/io/integration/Application.java");
info(openShiftName, "Publishing - Converting archive to TarExport");
InputStream buildContents = archive.as(TarExporter.class).exportAsInputStream();
info(openShiftName, "Publishing - Completed creating build contents construction");
info(openShiftName, "Publishing - Creating image stream");
// use the contents to invoke a binary build
ImageStream is = createImageStream(client, namespace, openShiftName);
info(openShiftName, "Publishing - Creating build config");
BuildConfig buildConfig = createBuildConfig(client, namespace, openShiftName, is, publishConfig);
info(openShiftName, "Publishing - Creating build");
Build build = createBuild(client, namespace, buildConfig, buildContents);
String buildName = build.getMetadata().getName();
info(openShiftName, "Publishing - Build created: " + buildName);
PodOperationsImpl publishPod = (PodOperationsImpl)client.pods().withName(buildName + "-build");
info(openShiftName, "Publishing - Awaiting pod readiness ...");
waitUntilPodIsReady(openShiftName, client, buildName + "-build", 20);
info(openShiftName, "Publishing - Fetching environment variables for vdb data sources");
if (publishConfig.isSecurityEnabled()) {
SSOConfigurationProperties configurationProperties = publishConfig.getSsoConfigurationProperties();
publishConfig.addEnvironmentVariables(getEnvironmentVariablesForSecurity(configurationProperties));
}
publishConfig.addEnvironmentVariables(
getEnvironmentVariablesForVDBDataSources(vdb, publishConfig, openShiftName));
publishConfig.addSecretVariables(getSecretVariablesForVDBDataSources(vdb, publishConfig));
work.setName(buildName);
work.setStatusMessage("Build Running");
work.setPublishPodName(publishPod.getName());
work.setLastUpdated();
work.setStatus(Status.BUILDING);
info(openShiftName, "Publishing - Configuration completed. Building ... Pod Name: " + work.getPublishPodName());
} catch (Exception ex) {
work.setStatus(Status.FAILED);
work.setStatusMessage(ex.getLocalizedMessage());
error(work.getOpenShiftName(), "Publishing - Build failed", ex);
} finally {
//
// Building is a long running operation so close the log file
//
closeLog(openShiftName);
}
}
});
}