Finalising connector
This commit is contained in:
parent
8119c282ac
commit
3310eeb5f7
|
@ -1,5 +1,6 @@
|
||||||
package org.gcube.smartgears.connector.resourceregistry;
|
package org.gcube.smartgears.connector.resourceregistry;
|
||||||
|
|
||||||
|
import org.gcube.smartgears.connector.resourceregistry.resourcemanager.EServiceManager;
|
||||||
import org.gcube.smartgears.connector.resourceregistry.resourcemanager.HostingNodeManager;
|
import org.gcube.smartgears.connector.resourceregistry.resourcemanager.HostingNodeManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,8 +12,6 @@ public class Constants {
|
||||||
|
|
||||||
public static final String HOSTING_NODE_MANAGER_PROPERTY = HostingNodeManager.class.getSimpleName();
|
public static final String HOSTING_NODE_MANAGER_PROPERTY = HostingNodeManager.class.getSimpleName();
|
||||||
|
|
||||||
public static final long default_container_publication_frequency_in_seconds = 60;
|
public static final String ESERVICE_MANAGER_PROPERTY = EServiceManager.class.getSimpleName();
|
||||||
|
|
||||||
public static final int application_republish_frequency_in_minutes = 20;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
package org.gcube.smartgears.connector.resourceregistry;
|
package org.gcube.smartgears.connector.resourceregistry;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
import java.util.TreeSet;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.gcube.common.security.AuthorizedTasks;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
|
||||||
|
import org.gcube.smartgears.connector.resourceregistry.resourcemanager.EServiceManager;
|
||||||
import org.gcube.smartgears.connector.resourceregistry.resourcemanager.HostingNodeManager;
|
import org.gcube.smartgears.connector.resourceregistry.resourcemanager.HostingNodeManager;
|
||||||
import org.gcube.smartgears.context.Property;
|
import org.gcube.smartgears.context.Property;
|
||||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||||
|
@ -21,120 +28,126 @@ public class FacetBasedPublisher implements Publisher {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean create(ContainerContext containerContext, Set<String> contexts) {
|
public boolean create(ContainerContext containerContext, Set<String> contexts) {
|
||||||
// Used at startup and in add to context
|
|
||||||
HostingNodeManager hostingNodeManager = new HostingNodeManager(containerContext);
|
HostingNodeManager hostingNodeManager = new HostingNodeManager(containerContext);
|
||||||
AuthorizationProvider authorizationProvider = containerContext.configuration().authorizationProvider();
|
AuthorizationProvider authorizationProvider = containerContext.configuration().authorizationProvider();
|
||||||
boolean first = true;
|
SortedSet<String> contextToIterate = new TreeSet<>(contexts);
|
||||||
for (String context : contexts) {
|
final String context = contextToIterate.first();
|
||||||
try {
|
|
||||||
UUID contextUUID = ContextUtility.getContextUUID(context);
|
try {
|
||||||
if(first) {
|
AuthorizedTasks.executeSafely( () -> {
|
||||||
hostingNodeManager.createHostingNode();
|
for (final String c : contextToIterate) {
|
||||||
Property property = new Property(Constants.HOSTING_NODE_MANAGER_PROPERTY, hostingNodeManager);
|
try {
|
||||||
containerContext.properties().add(property);
|
UUID contextUUID = ContextUtility.getContextUUID(context);
|
||||||
first = false;
|
if(context.compareTo(c)==0) {
|
||||||
}else {
|
hostingNodeManager.createHostingNode();
|
||||||
|
Property property = new Property(Constants.HOSTING_NODE_MANAGER_PROPERTY, hostingNodeManager);
|
||||||
|
containerContext.properties().add(property);
|
||||||
|
}else {
|
||||||
|
hostingNodeManager.addToContext(contextUUID);
|
||||||
|
}
|
||||||
|
}catch (Throwable e) {
|
||||||
|
logger.error("Error while publishing {} (id='{}') in context '{}'", HostingNode.NAME, containerContext.id(), context, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}catch (Exception e) {
|
}, authorizationProvider.getSecretForContext(context));
|
||||||
|
}catch (Throwable e) {
|
||||||
}
|
logger.error("Error while publishing {} (id='{}')", HostingNode.NAME, containerContext.id(), e);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean create(ApplicationContext applicationContext, Set<String> contexts) {
|
public boolean create(ApplicationContext applicationContext, Set<String> contexts) {
|
||||||
// Used at startup and in add to context
|
EServiceManager eServiceManager = new EServiceManager(applicationContext);
|
||||||
|
AuthorizationProvider authorizationProvider = applicationContext.container().configuration().authorizationProvider();
|
||||||
|
SortedSet<String> contextToIterate = new TreeSet<>(contexts);
|
||||||
|
final String context = contextToIterate.first();
|
||||||
|
|
||||||
|
try {
|
||||||
|
AuthorizedTasks.executeSafely( () -> {
|
||||||
|
for (final String c : contextToIterate) {
|
||||||
|
try {
|
||||||
|
UUID contextUUID = ContextUtility.getContextUUID(context);
|
||||||
|
if(context.compareTo(c)==0) {
|
||||||
|
eServiceManager.createEService();
|
||||||
|
Property property = new Property(Constants.ESERVICE_MANAGER_PROPERTY, eServiceManager);
|
||||||
|
applicationContext.properties().add(property);
|
||||||
|
}else {
|
||||||
|
eServiceManager.addToContext(contextUUID);
|
||||||
|
}
|
||||||
|
}catch (Throwable e) {
|
||||||
|
logger.error("Error while publishing {} (name='{}', id='{}') in context '{}'", EService.NAME, applicationContext.name(), applicationContext.id(), context, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, authorizationProvider.getSecretForContext(context));
|
||||||
|
}catch (Throwable e) {
|
||||||
|
logger.error("Error while publishing {} (name='{}', id='{}')", EService.NAME, applicationContext.name(), applicationContext.id(), e);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean remove(ContainerContext containerContext, Set<String> contexts) {
|
||||||
|
HostingNodeManager hostingNodeManager = (HostingNodeManager) containerContext.properties().lookup(Constants.HOSTING_NODE_MANAGER_PROPERTY).value();
|
||||||
|
AuthorizationProvider authorizationProvider = containerContext.configuration().authorizationProvider();
|
||||||
|
for(String context : contexts) {
|
||||||
|
try {
|
||||||
|
AuthorizedTasks.executeSafely( () -> {
|
||||||
|
try {
|
||||||
|
hostingNodeManager.removeFromCurrentContext();
|
||||||
|
}catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}, authorizationProvider.getSecretForContext(context));
|
||||||
|
}catch (Throwable e) {
|
||||||
|
logger.error("Unable to remove {} (id='{}') from context '{}'", HostingNode.NAME, containerContext.id(), context, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean remove(ApplicationContext applicationContext, Set<String> contexts) {
|
public boolean remove(ApplicationContext applicationContext, Set<String> contexts) {
|
||||||
// Remove from contexts
|
EServiceManager eServiceManager = (EServiceManager) applicationContext.properties().lookup(Constants.ESERVICE_MANAGER_PROPERTY).value();
|
||||||
return false;
|
AuthorizationProvider authorizationProvider = applicationContext.container().configuration().authorizationProvider();
|
||||||
|
for(String context : contexts) {
|
||||||
|
try {
|
||||||
|
AuthorizedTasks.executeSafely( () -> {
|
||||||
|
try {
|
||||||
|
eServiceManager.removeFromCurrentContext();
|
||||||
|
}catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}, authorizationProvider.getSecretForContext(context));
|
||||||
|
}catch (Throwable e) {
|
||||||
|
logger.error("Unable to remove {} (name='{}', id='{}') from context '{}'", EService.NAME, applicationContext.name(), applicationContext.id(), context, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean remove(ContainerContext containerContext, Set<String> contexts) {
|
|
||||||
// Remove from contexts
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean update(ApplicationContext applicationContext) {
|
|
||||||
// Periodic updates
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean update(ContainerContext containerContext) {
|
public boolean update(ContainerContext containerContext) {
|
||||||
// Periodic updates
|
HostingNodeManager hostingNodeManager = (HostingNodeManager) containerContext.properties().lookup(Constants.HOSTING_NODE_MANAGER_PROPERTY).value();
|
||||||
return false;
|
try {
|
||||||
|
hostingNodeManager.updateFacets();
|
||||||
|
} catch (ResourceRegistryException e) {
|
||||||
|
logger.error("Unable to update {} (id='{}')", HostingNode.NAME, containerContext.id(), e);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean update(ApplicationContext applicationContext) {
|
||||||
// @Override
|
EServiceManager eServiceManager = (EServiceManager) applicationContext.properties().lookup(Constants.ESERVICE_MANAGER_PROPERTY).value();
|
||||||
// public boolean publishContainer(ContainerContext containerContext, Set<String> contexts) {
|
try {
|
||||||
// HostingNodeManager hostingNodeManager = new HostingNodeManager(containerContext);
|
eServiceManager.updateFacets();
|
||||||
//
|
} catch (ResourceRegistryException e) {
|
||||||
// AuthorizationProvider authorizationProvider = containerContext.configuration().authorizationProvider();
|
logger.error("Unable to update {} (name='{}', id='{}') ", EService.NAME, applicationContext.name(), applicationContext.id(), e);
|
||||||
// Set<String> authorizedContexts = authorizationProvider.getContexts();
|
}
|
||||||
// for (String context : authorizedContexts) {
|
return true;
|
||||||
//
|
}
|
||||||
// }
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean publishApplication(ApplicationContext applicationContext, Set<String> contexts) {
|
|
||||||
// EServiceManager eServiceManager = new EServiceManager(applicationContext);
|
|
||||||
//
|
|
||||||
// AuthorizationProvider provider = applicationContext.container().configuration().authorizationProvider();
|
|
||||||
//
|
|
||||||
// for (String context : provider.getContexts())
|
|
||||||
// try {
|
|
||||||
// logger.info("publishing application in context {}", context);
|
|
||||||
// AuthorizedTasks.executeSafely(new Runnable() {
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void run() {
|
|
||||||
// try {
|
|
||||||
// logger.info("(inside task)publishing application in context {}", context);
|
|
||||||
// String resource = toXml(enpoint);
|
|
||||||
// registry.getStubs().create(resource, enpoint.type().toString());
|
|
||||||
// logger.debug("publisher resource in context {} : {}",context, resource);
|
|
||||||
// }catch (Exception e) {
|
|
||||||
// logger.error("erro publishing application", e);
|
|
||||||
// throw new RuntimeException(e);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// }, provider.getSecretForContext(context));
|
|
||||||
// }catch (Throwable e) {
|
|
||||||
// logger.error("error publisshing application profile in context {}", context, e);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean unpublishContainer(ContainerContext container, Set<String> contexts) {
|
|
||||||
// // TODO Auto-generated method stub
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public boolean unpublishApplication(ApplicationContext application, Set<String> contexts) {
|
|
||||||
// // TODO Auto-generated method stub
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private String toXml(Resource resource){
|
|
||||||
// StringWriter writer = new StringWriter();
|
|
||||||
// Resources.marshal(resource, writer);
|
|
||||||
// return writer.toString();
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue