use of org.apache.knox.gateway.deploy.ServiceDeploymentContributor in project knox by apache.
the class ServiceDefinitionsLoaderTest method testServiceDefinitionLoading.
@Test
public void testServiceDefinitionLoading() {
URL url = ClassLoader.getSystemResource("services");
Set<ServiceDeploymentContributor> contributors = ServiceDefinitionsLoader.loadServiceDefinitions(new File(url.getFile()));
assertNotNull(contributors);
assertEquals(2, contributors.size());
for (ServiceDeploymentContributor contributor : contributors) {
if (contributor.getName().equals("foo")) {
Assert.assertEquals("1.0.0", contributor.getVersion().toString());
assertEquals("FOO", contributor.getRole());
} else if (contributor.getName().equals("bar")) {
Assert.assertEquals("2.0.0", contributor.getVersion().toString());
assertEquals("BAR", contributor.getRole());
} else {
fail("the loaded services don't match the test input");
}
}
}
use of org.apache.knox.gateway.deploy.ServiceDeploymentContributor in project knox by apache.
the class ServiceDefinitionsLoader method loadServiceDefinitions.
public static Set<ServiceDeploymentContributor> loadServiceDefinitions(File servicesDir) {
Set<ServiceDeploymentContributor> contributors = new HashSet<>();
if (servicesDir.exists() && servicesDir.isDirectory()) {
try {
JAXBContext context = JAXBContext.newInstance(ServiceDefinition.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
for (File file : getFileList(servicesDir)) {
try {
FileInputStream inputStream = new FileInputStream(file);
ServiceDefinition definition = (ServiceDefinition) unmarshaller.unmarshal(inputStream);
// look for rewrite rules as a sibling (for now)
UrlRewriteRulesDescriptor rewriteRulesDescriptor = loadRewriteRules(file.getParentFile());
contributors.add(new ServiceDefinitionDeploymentContributor(definition, rewriteRulesDescriptor));
log.addedServiceDefinition(definition.getName(), definition.getRole(), definition.getVersion());
} catch (FileNotFoundException e) {
log.failedToFindServiceDefinitionFile(file.getAbsolutePath(), e);
}
}
} catch (JAXBException e) {
log.failedToLoadServiceDefinition(SERVICE_FILE_NAME, e);
}
}
return contributors;
}
Aggregations