use of org.apache.knox.gateway.topology.Application in project knox by apache.
the class DeploymentFactory method validateNoAppsWithDuplicateUrlsInTopology.
// Verify that there are no two apps with duplicate urls.
static void validateNoAppsWithDuplicateUrlsInTopology(Topology topology) {
if (topology != null) {
Collection<Application> apps = topology.getApplications();
if (apps != null) {
for (Application app : apps) {
List<String> urls = app.getUrls();
if (urls == null || urls.isEmpty()) {
urls = new ArrayList<String>(1);
urls.add(app.getName());
}
for (String url : urls) {
List<Application> dups = findApplicationsByUrl(topology, url);
if (dups != null) {
for (Application dup : dups) {
if (dup != app) {
throw new DeploymentException("Topology " + topology.getName() + " contains applications " + app.getName() + " and " + dup.getName() + " with the same url: " + url);
}
}
}
}
}
}
}
}
use of org.apache.knox.gateway.topology.Application in project knox by apache.
the class DeploymentFactory method findApplicationsByUrl.
static List<Application> findApplicationsByUrl(Topology topology, String url) {
List<Application> foundApps = new ArrayList<Application>();
if (topology != null) {
url = Urls.trimLeadingAndTrailingSlash(url);
Collection<Application> searchApps = topology.getApplications();
if (searchApps != null) {
for (Application searchApp : searchApps) {
List<String> searchUrls = searchApp.getUrls();
if (searchUrls == null || searchUrls.isEmpty()) {
searchUrls = new ArrayList<String>(1);
searchUrls.add(searchApp.getName());
}
for (String searchUrl : searchUrls) {
if (url.equalsIgnoreCase(Urls.trimLeadingAndTrailingSlash(searchUrl))) {
foundApps.add(searchApp);
break;
}
}
}
}
}
return foundApps;
}
use of org.apache.knox.gateway.topology.Application in project knox by apache.
the class DeploymentFactory method selectContextApplications.
private static Map<String, ServiceDeploymentContributor> selectContextApplications(GatewayConfig config, Topology topology) {
Map<String, ServiceDeploymentContributor> contributors = new HashMap<>();
if (topology != null) {
for (Application application : topology.getApplications()) {
String name = application.getName();
if (name == null || name.isEmpty()) {
throw new DeploymentException("Topologies cannot contain an application without a name.");
}
ApplicationDeploymentContributor contributor = new ApplicationDeploymentContributor(config, application);
List<String> urls = application.getUrls();
if (urls == null || urls.isEmpty()) {
urls = new ArrayList<String>(1);
urls.add("/" + name);
}
for (String url : urls) {
if (url == null || url.isEmpty() || url.equals("/")) {
if (!topology.getServices().isEmpty()) {
throw new DeploymentException(String.format("Topologies with services cannot contain an application (%s) with a root url.", name));
}
}
contributors.put(url, contributor);
}
}
}
return contributors;
}
use of org.apache.knox.gateway.topology.Application in project knox by apache.
the class DeploymentFactoryTest method test_validateNoAppsWithDuplicateUrlsInTopology.
@Test(timeout = TestUtils.SHORT_TIMEOUT)
public void test_validateNoAppsWithDuplicateUrlsInTopology() {
DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology(null);
Topology topology = new Topology();
topology.setName("test-topology");
DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology(topology);
Application application;
topology = new Topology();
topology.setName("test-topology");
application = new Application();
application.setName("test-application-1");
topology.addApplication(application);
DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology(topology);
topology = new Topology();
topology.setName("test-topology");
application = new Application();
application.setName("test-application-1");
topology.addApplication(application);
application = new Application();
application.setName("test-application-2");
topology.addApplication(application);
DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology(topology);
topology = new Topology();
topology.setName("test-topology");
application = new Application();
application.setName("test-application-1");
topology.addApplication(application);
application = new Application();
application.setName("test-application-2");
application.addUrl("/test-application-2");
topology.addApplication(application);
DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology(topology);
topology = new Topology();
topology.setName("test-topology");
application = new Application();
application.setName("test-application-1");
topology.addApplication(application);
application = new Application();
application.setName("test-application-2");
application.addUrl("/");
topology.addApplication(application);
DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology(topology);
topology = new Topology();
topology.setName("test-topology");
application = new Application();
application.setName("test-application-1");
topology.addApplication(application);
application = new Application();
application.setName("test-application-2");
application.addUrl("/");
topology.addApplication(application);
DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology(topology);
topology = new Topology();
topology.setName("test-topology");
application = new Application();
application.setName("test-application-1");
application.addUrl("/test-application-1");
topology.addApplication(application);
application = new Application();
application.setName("test-application-2");
application.addUrl("/test-application-2");
topology.addApplication(application);
DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology(topology);
topology = new Topology();
topology.setName("test-topology");
application = new Application();
application.setName("test-application-1");
application.addUrl("/test-application-dup");
topology.addApplication(application);
application = new Application();
application.setName("test-application-2");
application.addUrl("/test-application-dup");
topology.addApplication(application);
try {
DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology(topology);
fail("Expected DeploymentException");
} catch (DeploymentException e) {
// Expected.
}
topology = new Topology();
topology.setName("test-topology");
application = new Application();
application.setName("test-application-1");
application.addUrl("/");
topology.addApplication(application);
application = new Application();
application.setName("test-application-2");
application.addUrl("/");
topology.addApplication(application);
try {
DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology(topology);
fail("Expected DeploymentException");
} catch (DeploymentException e) {
// Expected.
}
topology = new Topology();
topology.setName("test-topology");
application = new Application();
application.setName("test-application-1");
application.addUrl("");
topology.addApplication(application);
application = new Application();
application.setName("test-application-2");
application.addUrl("/");
topology.addApplication(application);
try {
DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology(topology);
fail("Expected DeploymentException");
} catch (DeploymentException e) {
// Expected.
}
topology = new Topology();
topology.setName("test-topology");
application = new Application();
application.setName("test-application-1");
topology.addApplication(application);
application = new Application();
application.setName("test-application-2");
application.addUrl("/test-application-1");
topology.addApplication(application);
try {
DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology(topology);
fail("Expected DeploymentException");
} catch (DeploymentException e) {
// Expected.
}
topology = new Topology();
topology.setName("test-topology");
application = new Application();
application.setName("test-application-1");
topology.addApplication(application);
application = new Application();
application.setName("test-application-1");
topology.addApplication(application);
try {
DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology(topology);
fail("Expected DeploymentException");
} catch (DeploymentException e) {
// Expected.
}
topology = new Topology();
topology.setName("test-topology");
application = new Application();
application.setName("test-application-1");
application.addUrl("/test-application-1");
application.addUrl("/test-application-3");
topology.addApplication(application);
application = new Application();
application.setName("test-application-2");
application.addUrl("/test-application-2");
application.addUrl("/test-application-3");
topology.addApplication(application);
try {
DeploymentFactory.validateNoAppsWithDuplicateUrlsInTopology(topology);
fail("Expected DeploymentException");
} catch (DeploymentException e) {
// Expected.
}
}
use of org.apache.knox.gateway.topology.Application in project knox by apache.
the class DeploymentFactoryTest method test_validateNoAppsWithRootUrlsInServicesTopology.
@Test(timeout = TestUtils.SHORT_TIMEOUT)
public void test_validateNoAppsWithRootUrlsInServicesTopology() {
DeploymentFactory.validateNoAppsWithRootUrlsInServicesTopology(null);
Topology topology = new Topology();
topology.setName("test-topology");
DeploymentFactory.validateNoAppsWithRootUrlsInServicesTopology(topology);
Service service;
Application application;
topology = new Topology();
topology.setName("test-topology");
service = new Service();
service.setName("test-service");
service.setRole("test-service");
topology.addService(service);
application = new Application();
application.setName("test-application");
topology.addApplication(application);
topology = new Topology();
topology.setName("test-topology");
service = new Service();
service.setName("test-service");
service.setRole("test-service");
topology.addService(service);
application = new Application();
application.setName("test-application");
application.addUrl("");
topology.addApplication(application);
try {
DeploymentFactory.validateNoAppsWithRootUrlsInServicesTopology(topology);
fail("Expected DeploymentException");
} catch (DeploymentException e) {
// Expected.
}
topology = new Topology();
topology.setName("test-topology");
service = new Service();
service.setName("test-service");
service.setRole("test-service");
topology.addService(service);
application = new Application();
application.setName("test-application");
application.addUrl("/");
topology.addApplication(application);
try {
DeploymentFactory.validateNoAppsWithRootUrlsInServicesTopology(topology);
fail("Expected DeploymentException");
} catch (DeploymentException e) {
// Expected.
}
topology = new Topology();
topology.setName("test-topology");
service = new Service();
service.setName("test-service");
service.setRole("test-service");
topology.addService(service);
application = new Application();
application.setName("test-application");
application.addUrl("/");
topology.addApplication(application);
try {
DeploymentFactory.validateNoAppsWithRootUrlsInServicesTopology(topology);
fail("Expected DeploymentException");
} catch (DeploymentException e) {
// Expected.
}
topology = new Topology();
topology.setName("test-topology");
service = new Service();
service.setName("test-service");
service.setRole("test-service");
topology.addService(service);
application = new Application();
application.setName("test-application");
application.addUrl("/test-application");
application.addUrl("/");
topology.addApplication(application);
try {
DeploymentFactory.validateNoAppsWithRootUrlsInServicesTopology(topology);
fail("Expected DeploymentException");
} catch (DeploymentException e) {
// Expected.
}
}
Aggregations