Search in sources :

Example 6 with ServiceDefinition

use of org.apache.knox.gateway.service.definition.ServiceDefinition in project knox by apache.

the class DefaultTopologyService method getServiceTestURLs.

public Map<String, List<String>> getServiceTestURLs(Topology t, GatewayConfig config) {
    File tFile = null;
    Map<String, List<String>> urls = new HashMap<>();
    if (topologiesDirectory.isDirectory() && topologiesDirectory.canRead()) {
        for (File f : listFiles(topologiesDirectory)) {
            if (FilenameUtils.removeExtension(f.getName()).equals(t.getName())) {
                tFile = f;
            }
        }
    }
    Set<ServiceDefinition> defs;
    if (tFile != null) {
        defs = ServiceDefinitionsLoader.getServiceDefinitions(new File(config.getGatewayServicesDir()));
        for (ServiceDefinition def : defs) {
            urls.put(def.getRole(), def.getTestURLs());
        }
    }
    return urls;
}
Also used : HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File) ServiceDefinition(org.apache.knox.gateway.service.definition.ServiceDefinition)

Example 7 with ServiceDefinition

use of org.apache.knox.gateway.service.definition.ServiceDefinition in project knox by apache.

the class DefaultServiceDefinitionRegistry method init.

@Override
public void init(GatewayConfig config, Map<String, String> options) throws ServiceLifecycleException {
    String stacks = config.getGatewayServicesDir();
    File stacksDir = new File(stacks);
    Set<ServiceDefinition> serviceDefinitions = ServiceDefinitionsLoader.getServiceDefinitions(stacksDir);
    for (ServiceDefinition serviceDefinition : serviceDefinitions) {
        List<Route> routes = serviceDefinition.getRoutes();
        for (Route route : routes) {
            try {
                Template template = Parser.parseTemplate(route.getPath());
                addServiceDefEntry(template, serviceDefinition);
            } catch (URISyntaxException e) {
                LOG.failedToParsePath(route.getPath(), e);
            }
        }
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) File(java.io.File) ServiceDefinition(org.apache.knox.gateway.service.definition.ServiceDefinition) Route(org.apache.knox.gateway.service.definition.Route) Template(org.apache.knox.gateway.util.urltemplate.Template)

Aggregations

ServiceDefinition (org.apache.knox.gateway.service.definition.ServiceDefinition)7 File (java.io.File)5 ArrayList (java.util.ArrayList)3 JAXBContext (javax.xml.bind.JAXBContext)3 Unmarshaller (javax.xml.bind.Unmarshaller)3 Route (org.apache.knox.gateway.service.definition.Route)3 FileInputStream (java.io.FileInputStream)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 JAXBException (javax.xml.bind.JAXBException)2 UrlRewriteRulesDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor)2 FileNotFoundException (java.io.FileNotFoundException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 List (java.util.List)1 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)1 DeploymentContext (org.apache.knox.gateway.deploy.DeploymentContext)1 ServiceDeploymentContributor (org.apache.knox.gateway.deploy.ServiceDeploymentContributor)1