use of org.ballerinax.kubernetes.handlers.ServiceHandler in project kubernetes by ballerinax.
the class KubernetesServiceGeneratorTests method testServiceGenerate.
@Test
public void testServiceGenerate() {
ServiceModel serviceModel = new ServiceModel();
serviceModel.setName("MyService");
serviceModel.setPort(9090);
serviceModel.setServiceType("NodePort");
serviceModel.setSelector("MyAPP");
Map<String, String> labels = new HashMap<>();
labels.put(KubernetesConstants.KUBERNETES_SELECTOR_KEY, "TestAPP");
serviceModel.setLabels(labels);
ServiceHandler kubernetesServiceGenerator = new ServiceHandler(serviceModel);
try {
String serviceYAML = kubernetesServiceGenerator.generate();
Assert.assertNotNull(serviceYAML);
File artifactLocation = new File("target/kubernetes");
artifactLocation.mkdir();
File tempFile = File.createTempFile("temp", serviceModel.getName() + ".yaml", artifactLocation);
KubernetesUtils.writeToFile(serviceYAML, tempFile.getPath());
log.info("Generated YAML: \n" + serviceYAML);
Assert.assertTrue(tempFile.exists());
// tempFile.deleteOnExit();
} catch (IOException e) {
Assert.fail("Unable to write to file");
} catch (KubernetesPluginException e) {
Assert.fail("Unable to generate yaml from service");
}
}
use of org.ballerinax.kubernetes.handlers.ServiceHandler in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method generateService.
private void generateService(ServiceModel serviceModel, String balxFilePath, String outputDir) throws KubernetesPluginException {
String balxFileName = KubernetesUtils.extractBalxName(balxFilePath);
serviceModel.addLabel(KubernetesConstants.KUBERNETES_SELECTOR_KEY, balxFileName);
serviceModel.setSelector(balxFileName);
String serviceContent = new ServiceHandler(serviceModel).generate();
try {
KubernetesUtils.writeToFile(serviceContent, outputDir + File.separator + balxFileName + SVC_FILE_POSTFIX + YAML);
} catch (IOException e) {
throw new KubernetesPluginException("Error while writing service content", e);
}
}
Aggregations