2022-12-06 18:29:31 +01:00
package org.gcube.gcat ;
import java.io.IOException ;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider ;
2022-12-07 17:21:14 +01:00
import org.gcube.gcat.configuration.isproxies.FacetBasedISConfigurationProxy ;
import org.gcube.gcat.configuration.isproxies.FacetBasedISConfigurationProxyFactory ;
2022-12-06 18:29:31 +01:00
import org.gcube.gcat.rest.RequestFilter ;
import org.gcube.smartgears.ApplicationManager ;
2022-12-07 22:59:21 +01:00
import org.gcube.smartgears.ContextProvider ;
import org.gcube.smartgears.context.application.ApplicationContext ;
2022-12-06 18:29:31 +01:00
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
/ * *
* @author Luca Frosini ( ISTI - CNR )
* /
public class GCatInitializator implements ApplicationManager {
/ * *
* Logger
* /
private static Logger logger = LoggerFactory . getLogger ( GCatInitializator . class ) ;
/ * *
* { @inheritDoc }
* The method discover the plugins available on classpath and their own
* supported capabilities and publish a ServiceEndpoint with the
* discovered information .
* Furthermore create / connect to DB
* /
@Override
public void onInit ( ) {
RequestFilter requestFilter = new RequestFilter ( ) ;
try {
requestFilter . filter ( null ) ;
} catch ( IOException e ) {
throw new RuntimeException ( e ) ;
}
String context = SecretManagerProvider . instance . get ( ) . getContext ( ) ;
logger . trace (
" \ n------------------------------------------------------- \ n "
+ " GCat is Starting on context {} \ n "
+ " ------------------------------------------------------- " ,
context ) ;
2022-12-07 22:59:21 +01:00
ApplicationContext applicationContext = ContextProvider . get ( ) ;
String gcatEServiceID = applicationContext . id ( ) ;
2022-12-07 17:21:14 +01:00
FacetBasedISConfigurationProxy facetBasedISConfigurationProxy = FacetBasedISConfigurationProxyFactory . getInstance ( context ) ;
2022-12-07 22:59:21 +01:00
facetBasedISConfigurationProxy . setGcatEServiceID ( gcatEServiceID ) ;
2022-12-07 17:21:14 +01:00
try {
facetBasedISConfigurationProxy . createCallsForToVirtualService ( ) ;
} catch ( Exception e ) {
logger . warn ( " Gcat is not configured through the Facet Based IS in context {}. Please create/addToContext the expected resources ASAP. The Gcore IS will be used. " , context , e ) ;
}
2022-12-06 18:29:31 +01:00
logger . trace (
" \ n------------------------------------------------------- \ n "
+ " GCat Started Successfully on context {} \ n "
+ " ------------------------------------------------------- " ,
context ) ;
}
/ * *
* { @inheritDoc }
* This function is invoked before the service will stop and unpublish the
* resource from the IS to maintain the infrastructure integrity .
* Furthermore close the connection to DB .
* /
@Override
public void onShutdown ( ) {
RequestFilter requestFilter = new RequestFilter ( ) ;
try {
requestFilter . filter ( null ) ;
} catch ( IOException e ) {
throw new RuntimeException ( e ) ;
}
String context = SecretManagerProvider . instance . get ( ) . getContext ( ) ;
logger . trace (
" \ n------------------------------------------------------- \ n "
+ " GCat is Stopping on context {} \ n "
+ " ------------------------------------------------------- " ,
context ) ;
2022-12-07 17:21:14 +01:00
/ *
2022-12-13 10:54:50 +01:00
* We don ' t delete the relation .
* Thanks to the propagation constraint ,
* it will be deleted when the EService will be deleted .
*
2022-12-07 22:59:21 +01:00
ApplicationContext applicationContext = ContextProvider . get ( ) ;
String gcatEServiceID = applicationContext . id ( ) ;
2022-12-07 17:21:14 +01:00
FacetBasedISConfigurationProxy facetBasedISConfigurationProxy = FacetBasedISConfigurationProxyFactory . getInstance ( context ) ;
2022-12-07 22:59:21 +01:00
facetBasedISConfigurationProxy . setGcatEServiceID ( gcatEServiceID ) ;
2022-12-07 17:21:14 +01:00
try {
facetBasedISConfigurationProxy . deleteCallsForToVirtualService ( ) ;
} catch ( Exception e ) {
logger . warn ( " Gcat is not configured through the Facet Based IS in context {}. Please create/addToContext the expected resources ASAP. The Gcore IS will be used. " , context , e ) ;
}
* /
2022-12-06 18:29:31 +01:00
logger . trace (
" \ n------------------------------------------------------- \ n "
+ " GCat Stopped Successfully on context {} \ n "
+ " ------------------------------------------------------- " ,
context ) ;
}
}