Skip to content

Commit

Permalink
Fix #3: Delay boostrap stage
Browse files Browse the repository at this point in the history
Signed-off-by: jensenzhang <[email protected]>
  • Loading branch information
fno2010 committed Nov 5, 2017
1 parent bd3054e commit 4b814d6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
Expand Down Expand Up @@ -133,5 +138,6 @@
<httpcomponents.version>4.5.3</httpcomponents.version>
<slf4j.version>1.7.21</slf4j.version>
<jackson.version>2.8.9</jackson.version>
<servlet.version>2.5</servlet.version>
</properties>
</project>
27 changes: 27 additions & 0 deletions src/main/java/org/snlab/unicorn/Bootstrap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.snlab.unicorn;

import java.util.Collection;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.snlab.unicorn.orchestrator.OrchestratorInfo;
import org.snlab.unicorn.orchestrator.OrchestratorInfoReader;
import org.snlab.unicorn.register.UnicornRegister;
import org.snlab.unicorn.register.UnicornRegisterBuilder;

public class Bootstrap extends HttpServlet {
private final static Logger LOG = LoggerFactory.getLogger(Bootstrap.class);

@Override
public void init(ServletConfig config) throws ServletException {
LOG.info("Starting bootstrap stage...");
// Register to orchestrator
Collection<OrchestratorInfo> infos = OrchestratorInfoReader.read(UnicornDefinitions.OrchestratorConfig.CONFIG_PATH);
UnicornRegister register = new UnicornRegisterBuilder().addOrchestrators(infos).build();
register.register();
}
}
16 changes: 5 additions & 11 deletions src/main/java/org/snlab/unicorn/UnicornApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@

import org.glassfish.jersey.media.sse.SseFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.snlab.unicorn.orchestrator.OrchestratorInfo;
import org.snlab.unicorn.orchestrator.OrchestratorInfoReader;
import org.snlab.unicorn.register.UnicornRegister;
import org.snlab.unicorn.register.UnicornRegisterBuilder;

import java.util.Collection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class UnicornApplication extends ResourceConfig {
private final static Logger LOG = LoggerFactory.getLogger(UnicornApplication.class);

public UnicornApplication() {
super(UnicornService.class, SseFeature.class);

// Register to orchestrator
Collection<OrchestratorInfo> infos = OrchestratorInfoReader.read(UnicornDefinitions.OrchestratorConfig.CONFIG_PATH);
UnicornRegister register = new UnicornRegisterBuilder().addOrchestrators(infos).build();
register.register();
LOG.info("Starting unicorn application...");
}
}
5 changes: 5 additions & 0 deletions src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet>
<servlet-name>Bootstrap</servlet-name>
<servlet-class>org.snlab.unicorn.Bootstrap</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/experimental/v1/*</url-pattern>
Expand Down

0 comments on commit 4b814d6

Please sign in to comment.