77import org .apache .log4j .Logger ;
88import org .fogbowcloud .manager .core .ConfigurationConstants ;
99import org .fogbowcloud .manager .core .DefaultMemberValidator ;
10+ import org .fogbowcloud .manager .core .FederationMemberPicker ;
1011import org .fogbowcloud .manager .core .FederationMemberValidator ;
1112import org .fogbowcloud .manager .core .ManagerController ;
13+ import org .fogbowcloud .manager .core .RoundRobinMemberPicker ;
14+ import org .fogbowcloud .manager .core .plugins .AccountingPlugin ;
1215import org .fogbowcloud .manager .core .plugins .AuthorizationPlugin ;
16+ import org .fogbowcloud .manager .core .plugins .BenchmarkingPlugin ;
1317import org .fogbowcloud .manager .core .plugins .ComputePlugin ;
1418import org .fogbowcloud .manager .core .plugins .IdentityPlugin ;
1519import org .fogbowcloud .manager .core .plugins .ImageStoragePlugin ;
20+ import org .fogbowcloud .manager .core .plugins .accounting .FCUAccountingPlugin ;
21+ import org .fogbowcloud .manager .core .plugins .benchmarking .FCUStaticBenchmarkingPlugin ;
1622import org .fogbowcloud .manager .core .plugins .egi .EgiImageStoragePlugin ;
1723import org .fogbowcloud .manager .occi .OCCIApplication ;
1824import org .fogbowcloud .manager .xmpp .ManagerXmppComponent ;
2531public class Main {
2632
2733 private static final Logger LOGGER = Logger .getLogger (Main .class );
28-
34+ private static final int EXIT_ERROR_CODE = 128 ;
35+
2936 public static void main (String [] args ) throws Exception {
3037 configureLog4j ();
3138
3239 Properties properties = new Properties ();
3340 FileInputStream input = new FileInputStream (args [0 ]);
3441 properties .load (input );
3542
36- ComputePlugin computePlugin ;
43+ ComputePlugin computePlugin = null ;
3744 try {
3845 computePlugin = (ComputePlugin ) createInstance (
3946 ConfigurationConstants .COMPUTE_CLASS_KEY , properties );
4047 } catch (Exception e ) {
4148 LOGGER .warn ("Compute Plugin not especified in the properties." , e );
42- return ;
49+ System . exit ( EXIT_ERROR_CODE ) ;
4350 }
4451
4552 AuthorizationPlugin authorizationPlugin = null ;
@@ -48,7 +55,7 @@ public static void main(String[] args) throws Exception {
4855 ConfigurationConstants .AUTHORIZATION_CLASS_KEY , properties );
4956 } catch (Exception e ) {
5057 LOGGER .warn ("Authorization Plugin not especified in the properties." , e );
51- return ;
58+ System . exit ( EXIT_ERROR_CODE ) ;
5259 }
5360
5461 IdentityPlugin localIdentityPlugin = null ;
@@ -57,7 +64,7 @@ public static void main(String[] args) throws Exception {
5764 ConfigurationConstants .LOCAL_PREFIX );
5865 } catch (Exception e ) {
5966 LOGGER .warn ("Local Identity Plugin not especified in the properties." , e );
60- return ;
67+ System . exit ( EXIT_ERROR_CODE ) ;
6168 }
6269
6370 IdentityPlugin federationIdentityPlugin = null ;
@@ -66,15 +73,16 @@ public static void main(String[] args) throws Exception {
6673 ConfigurationConstants .FEDERATION_PREFIX );
6774 } catch (Exception e ) {
6875 LOGGER .warn ("Federation Identity Plugin not especified in the properties." , e );
69- return ;
76+ System . exit ( EXIT_ERROR_CODE ) ;
7077 }
7178
72- FederationMemberValidator validator = new DefaultMemberValidator ();
79+ FederationMemberValidator validator = new DefaultMemberValidator (properties );
7380 try {
7481 validator = (FederationMemberValidator ) createInstance (
7582 ConfigurationConstants .MEMBER_VALIDATOR_KEY , properties );
7683 } catch (Exception e ) {
7784 LOGGER .warn ("Member Validator not especified in the properties." );
85+ System .exit (EXIT_ERROR_CODE );
7886 }
7987
8088 if (properties .get (ConfigurationConstants .RENDEZVOUS_JID_KEY ) == null
@@ -91,6 +99,34 @@ public static void main(String[] args) throws Exception {
9199 imageStoragePlugin = new EgiImageStoragePlugin (properties , computePlugin );
92100 LOGGER .warn ("Image Storage plugin not specified in properties. Using the default one." , e );
93101 }
102+
103+ BenchmarkingPlugin benchmarkingPlugin = null ;
104+ try {
105+ benchmarkingPlugin = (BenchmarkingPlugin ) createInstance (
106+ ConfigurationConstants .BENCHMARKING_PLUGIN_CLASS_KEY , properties );
107+ } catch (Exception e ) {
108+ benchmarkingPlugin = new FCUStaticBenchmarkingPlugin (properties );
109+ LOGGER .warn ("Benchmarking plugin not specified in properties. Using the default one." , e );
110+ }
111+
112+ AccountingPlugin accountingPlugin = null ;
113+ try {
114+ accountingPlugin = (AccountingPlugin ) createInstanceWithBenchmarkingPlugin (
115+ ConfigurationConstants .ACCOUNTING_PLUGIN_CLASS_KEY , properties , benchmarkingPlugin );
116+ } catch (Exception e ) {
117+ accountingPlugin = new FCUAccountingPlugin (properties , benchmarkingPlugin );
118+ LOGGER .warn ("Accounting plugin not specified in properties. Using the default one." , e );
119+ }
120+
121+ FederationMemberPicker memberPickerPlugin = null ;
122+ try {
123+ memberPickerPlugin = (FederationMemberPicker ) createInstanceWithAccoutingPlugin (
124+ ConfigurationConstants .MEMBER_PICKER_PLUGIN_CLASS_KEY , properties ,
125+ accountingPlugin );
126+ } catch (Exception e ) {
127+ memberPickerPlugin = new RoundRobinMemberPicker (properties , accountingPlugin );
128+ LOGGER .warn ("Member picker plugin not specified in properties. Using the default one." , e );
129+ }
94130
95131 ManagerController facade = new ManagerController (properties );
96132 facade .setComputePlugin (computePlugin );
@@ -99,7 +135,10 @@ public static void main(String[] args) throws Exception {
99135 facade .setFederationIdentityPlugin (federationIdentityPlugin );
100136 facade .setImageStoragePlugin (imageStoragePlugin );
101137 facade .setValidator (validator );
102-
138+ facade .setBenchmarkingPlugin (benchmarkingPlugin );
139+ facade .setAccountingPlugin (accountingPlugin );
140+ facade .setMemberPickerPlugin (memberPickerPlugin );
141+
103142 ManagerXmppComponent xmpp = new ManagerXmppComponent (
104143 properties .getProperty (ConfigurationConstants .XMPP_JID_KEY ),
105144 properties .getProperty (ConfigurationConstants .XMPP_PASS_KEY ),
@@ -111,7 +150,7 @@ public static void main(String[] args) throws Exception {
111150 xmpp .connect ();
112151 } catch (ComponentException e ) {
113152 LOGGER .error ("Conflict in the initialization of xmpp component." , e );
114- return ;
153+ System . exit ( EXIT_ERROR_CODE ) ;
115154 }
116155 xmpp .process (false );
117156 xmpp .init ();
@@ -122,11 +161,16 @@ public static void main(String[] args) throws Exception {
122161 Slf4jLoggerFacade loggerFacade = new Slf4jLoggerFacade ();
123162 Engine .getInstance ().setLoggerFacade (loggerFacade );
124163
125- Component http = new Component ();
126- http .getServers ().add (Protocol .HTTP ,
127- Integer .parseInt (properties .getProperty (ConfigurationConstants .HTTP_PORT_KEY )));
128- http .getDefaultHost ().attach (application );
129- http .start ();
164+ try {
165+ Component http = new Component ();
166+ http .getServers ().add (Protocol .HTTP ,
167+ Integer .parseInt (properties .getProperty (ConfigurationConstants .HTTP_PORT_KEY )));
168+ http .getDefaultHost ().attach (application );
169+ http .start ();
170+ } catch (Exception e ) {
171+ LOGGER .error ("Conflict in the initialization of the HTTP component." , e );
172+ System .exit (EXIT_ERROR_CODE );
173+ }
130174 }
131175
132176 private static Object getIdentityPluginByPrefix (Properties properties , String prefix )
@@ -153,6 +197,20 @@ private static Object createInstanceWithComputePlugin(String propName,
153197 return Class .forName (properties .getProperty (propName )).getConstructor (Properties .class , ComputePlugin .class )
154198 .newInstance (properties , computePlugin );
155199 }
200+
201+ private static Object createInstanceWithBenchmarkingPlugin (
202+ String propName , Properties properties ,
203+ BenchmarkingPlugin benchmarkingPlugin ) throws Exception {
204+ return Class .forName (properties .getProperty (propName )).getConstructor (Properties .class , BenchmarkingPlugin .class )
205+ .newInstance (properties , benchmarkingPlugin );
206+ }
207+
208+ private static Object createInstanceWithAccoutingPlugin (
209+ String propName , Properties properties ,
210+ AccountingPlugin accoutingPlugin ) throws Exception {
211+ return Class .forName (properties .getProperty (propName )).getConstructor (Properties .class , AccountingPlugin .class )
212+ .newInstance (properties , accoutingPlugin );
213+ }
156214
157215 private static void configureLog4j () {
158216 ConsoleAppender console = new ConsoleAppender ();
0 commit comments