Issue #2385 Fixed subscription backup web service. Restored subscriptions are now scheduled in the bandwidth manager

Change-Id: I7e0e98517ff7d2213957004c6a94e38cf7063cce

Former-commit-id: 40fec1c49a0a4aa2ecb4afdf4cf225e6359efd28
This commit is contained in:
Benjamin Phillippe 2013-10-23 16:15:13 -05:00
parent b5072746fe
commit 0905d6ffdd
7 changed files with 170 additions and 100 deletions

View file

@ -22,7 +22,6 @@ package com.raytheon.uf.common.registry.services.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.xml.bind.JAXBException;
import com.raytheon.uf.common.registry.RegistryException;
import com.raytheon.uf.common.registry.services.rest.response.RestCollectionResponse;
@ -40,6 +39,7 @@ import com.raytheon.uf.common.registry.services.rest.response.RestCollectionResp
* 7/29/2013 2191 bphillip Initial implementation
* 9/20/2013 2385 bphillip Added subscription backup functions
* 10/8/2013 1682 bphillip Added rest functions for use with the query web interface
* 10/23/2013 2385 bphillip restoreSubscriptions throws JAXBException
* </pre>
*
* @author bphillip
@ -111,25 +111,20 @@ public interface IRegistryDataAccessService {
* @param subscriptionName
* The subscription to be backed up
* @return Status message about whether the backup was successful
* @throws JAXBException
* If marshalling/unmarshalling errors are encountered
*/
@GET
@Path(DATA_ACCESS_PATH_PREFIX + "backupSubscription/{subscriptionName}")
public String backupSubscription(
@PathParam("subscriptionName") String subscriptionName)
throws JAXBException;
@PathParam("subscriptionName") String subscriptionName);
/**
* Backs up all subscriptions currently in the registry
*
* @return Status message about whether the backup was successful
* @throws JAXBException
* If marshalling/unmarshalling errors are encountered
*/
@GET
@Path(DATA_ACCESS_PATH_PREFIX + "backupAllSubscriptions/")
public String backupAllSubscriptions() throws JAXBException;
public String backupAllSubscriptions();
/**
* Restores the specified subscription
@ -137,13 +132,11 @@ public interface IRegistryDataAccessService {
* @param subscriptionName
* The name of the subscription to restore
* @return Status message about whether the backup was successful
* @throws JAXBException
*/
@GET
@Path(DATA_ACCESS_PATH_PREFIX + "restoreSubscription/{subscriptionName}")
public String restoreSubscription(
@PathParam("subscriptionName") String subscriptionName)
throws JAXBException;
@PathParam("subscriptionName") String subscriptionName);
/**
* Restores any subscriptions that were previously backed up

View file

@ -1,6 +1,7 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="propertyPlaceholderConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
@ -87,4 +88,14 @@
<property name="retrievalPlans" ref="retrievalPlans" />
</bean>
<camelContext id="datadelivery-bandwidth" xmlns="http://camel.apache.org/schema/spring"
errorHandlerRef="errorHandler">
<endpoint id="scheduleBandwidthQueue"
uri="vm://scheduleBandwidth" />
<route id="scheduleSubscription">
<from uri="scheduleBandwidthQueue" />
<bean ref="bandwidthManager" method="schedule"/>
</route>
</camelContext>
</beans>

View file

@ -122,14 +122,15 @@ import com.raytheon.uf.edex.registry.ebxml.exception.EbxmlRegistryException;
* case for no matching dataset metadata for an
* adhoc subscription.
* Sept 25, 2013 1797 dhladky separated time from gridded time
* 10/23/2013 2385 bphillip Change schedule method to scheduleAdhoc
* </pre>
*
* @author dhladky
* @version 1.0
*/
public abstract class BandwidthManager<T extends Time, C extends Coverage> extends
AbstractPrivilegedRequestHandler<IBandwidthRequest<T, C>> implements
IBandwidthManager<T, C> {
public abstract class BandwidthManager<T extends Time, C extends Coverage>
extends AbstractPrivilegedRequestHandler<IBandwidthRequest<T, C>>
implements IBandwidthManager<T, C> {
protected static final IUFStatusHandler statusHandler = UFStatus
.getHandler(BandwidthManager.class);
@ -141,7 +142,7 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
private BandwidthInitializer initializer;
protected final BandwidthDaoUtil<T,C> bandwidthDaoUtil;
protected final BandwidthDaoUtil<T, C> bandwidthDaoUtil;
private final IBandwidthDbInit dbInit;
@ -154,8 +155,9 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
final RetrievalManager retrievalManager;
public BandwidthManager(IBandwidthDbInit dbInit,
IBandwidthDao<T, C> bandwidthDao, RetrievalManager retrievalManager,
BandwidthDaoUtil<T,C> bandwidthDaoUtil) {
IBandwidthDao<T, C> bandwidthDao,
RetrievalManager retrievalManager,
BandwidthDaoUtil<T, C> bandwidthDaoUtil) {
this.dbInit = dbInit;
this.bandwidthDao = bandwidthDao;
this.retrievalManager = retrievalManager;
@ -244,8 +246,8 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
return unscheduled;
}
protected List<BandwidthAllocation> schedule(Subscription<T, C> subscription,
BandwidthSubscription dao) {
protected List<BandwidthAllocation> schedule(
Subscription<T, C> subscription, BandwidthSubscription dao) {
Calendar retrievalTime = dao.getBaseReferenceTime();
// Retrieve all the current subscriptions by provider, dataset name and
@ -440,7 +442,8 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
* @return
*/
@Override
public List<BandwidthAllocation> schedule(AdhocSubscription<T, C> subscription) {
public List<BandwidthAllocation> scheduleAdhoc(
AdhocSubscription<T, C> subscription) {
List<BandwidthSubscription> subscriptions = new ArrayList<BandwidthSubscription>();
Calendar now = BandwidthUtil.now();
@ -453,8 +456,7 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
* and time.
*/
AdhocSubscription<T, C> subscriptionUpdated = bandwidthDaoUtil
.setAdhocMostRecentUrlAndTime(
subscription, true);
.setAdhocMostRecentUrlAndTime(subscription, true);
if (subscriptionUpdated != null) {
subscription = subscriptionUpdated;
}
@ -558,7 +560,8 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
* the subscription
* @return the list of unscheduled subscriptions
*/
private List<BandwidthAllocation> handlePoint(Subscription<T, C> subscription) {
private List<BandwidthAllocation> handlePoint(
Subscription<T, C> subscription) {
return schedule(subscription,
((PointTime) subscription.getTime()).getInterval());
}
@ -570,8 +573,10 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
* the subscription
* @return the list of unscheduled subscriptions
*/
private List<BandwidthAllocation> handleGridded(Subscription<T, C> subscription) {
final List<Integer> cycles = ((GriddedTime)subscription.getTime()).getCycleTimes();
private List<BandwidthAllocation> handleGridded(
Subscription<T, C> subscription) {
final List<Integer> cycles = ((GriddedTime) subscription.getTime())
.getCycleTimes();
final boolean subscribedToCycles = !CollectionUtil
.isNullOrEmpty(cycles);
final boolean useMostRecentDataSetUpdate = !subscribedToCycles;
@ -599,7 +604,7 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
+ "No adhoc requested.",
subscription.getName()));
} else {
unscheduled = schedule(adhoc);
unscheduled = scheduleAdhoc(adhoc);
}
} else {
statusHandler
@ -614,10 +619,11 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
* @return
*/
@Override
public List<BandwidthAllocation> adhocSubscription(AdhocSubscription<T, C> adhoc) {
public List<BandwidthAllocation> adhocSubscription(
AdhocSubscription<T, C> adhoc) {
statusHandler.info("Scheduling adhoc subscription [" + adhoc.getName()
+ "]");
return schedule(adhoc);
return scheduleAdhoc(adhoc);
}
/**
@ -660,7 +666,8 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
* {@inheritDoc}
*/
@Override
public Object handleRequest(IBandwidthRequest<T, C> request) throws Exception {
public Object handleRequest(IBandwidthRequest<T, C> request)
throws Exception {
ITimer timer = TimeUtil.getTimer();
timer.start();
@ -670,7 +677,8 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
final Network requestNetwork = request.getNetwork();
final int bandwidth = request.getBandwidth();
final List<Subscription<T, C>> subscriptions = request.getSubscriptions();
final List<Subscription<T, C>> subscriptions = request
.getSubscriptions();
final RequestType requestType = request.getRequestType();
switch (requestType) {
case GET_ESTIMATED_COMPLETION:
@ -797,7 +805,8 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
* @throws SerializationException
*/
protected abstract Set<String> scheduleSbnSubscriptions(
List<Subscription<T, C>> subscriptions) throws SerializationException;
List<Subscription<T, C>> subscriptions)
throws SerializationException;
/**
* Proposes scheduling a list of subscriptions.
@ -808,7 +817,8 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
* @throws SerializationException
*/
protected ProposeScheduleResponse proposeScheduleSubscriptions(
List<Subscription<T, C>> subscriptions) throws SerializationException {
List<Subscription<T, C>> subscriptions)
throws SerializationException {
final ProposeScheduleResponse proposeResponse = proposeSchedule(subscriptions);
Set<String> subscriptionsUnscheduled = proposeResponse
.getUnscheduledSubscriptions();
@ -907,7 +917,8 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
* @return the set of subscription names unscheduled
* @throws SerializationException
*/
protected Set<String> scheduleSubscriptions(List<Subscription<T, C>> subscriptions)
protected Set<String> scheduleSubscriptions(
List<Subscription<T, C>> subscriptions)
throws SerializationException {
Set<String> unscheduledSubscriptions = new TreeSet<String>();
@ -993,7 +1004,8 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
* @throws SerializationException
*/
private ProposeScheduleResponse proposeSchedule(
List<Subscription<T, C>> subscriptions) throws SerializationException {
List<Subscription<T, C>> subscriptions)
throws SerializationException {
BandwidthMap copyOfCurrentMap = BandwidthMap
.load(EdexBandwidthContextFactory.getBandwidthMapConfig());
@ -1100,7 +1112,8 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
* @throws SerializationException
*/
@VisibleForTesting
BandwidthManager<T, C> startProposedBandwidthManager(BandwidthMap bandwidthMap) {
BandwidthManager<T, C> startProposedBandwidthManager(
BandwidthMap bandwidthMap) {
InMemoryBandwidthContextFactory
.setInMemoryBandwidthConfigFile(bandwidthMap);
@ -1137,8 +1150,8 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
* @param type
* @return the reference to the bandwidth manager
*/
private BandwidthManager<T, C> startBandwidthManager(final String[] springFiles,
boolean close, String type) {
private BandwidthManager<T, C> startBandwidthManager(
final String[] springFiles, boolean close, String type) {
ITimer timer = TimeUtil.getTimer();
timer.start();
@ -1146,8 +1159,8 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
try {
ctx = new ClassPathXmlApplicationContext(springFiles,
EDEXUtil.getSpringContext());
final BandwidthManager<T, C> bwManager = ctx.getBean("bandwidthManager",
BandwidthManager.class);
final BandwidthManager<T, C> bwManager = ctx.getBean(
"bandwidthManager", BandwidthManager.class);
try {
bwManager.initializer.executeAfterRegistryInit();
return bwManager;
@ -1218,11 +1231,11 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
/**
* {@inheritDoc}
*/
public List<BandwidthAllocation> copyState(BandwidthManager<T,C> copyFrom) {
public List<BandwidthAllocation> copyState(BandwidthManager<T, C> copyFrom) {
IPerformanceTimer timer = TimeUtil.getPerformanceTimer();
timer.start();
List<BandwidthAllocation> unscheduled = Collections.emptyList();
IBandwidthDao<T,C> fromDao = copyFrom.bandwidthDao;
IBandwidthDao<T, C> fromDao = copyFrom.bandwidthDao;
final boolean proposingBandwidthChange = retrievalManager
.isProposingBandwidthChanges(copyFrom.retrievalManager);
@ -1239,10 +1252,10 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
subscriptionNames.add(subscription.getName());
}
Set<Subscription<T,C>> actualSubscriptions = Sets.newHashSet();
Set<Subscription<T, C>> actualSubscriptions = Sets.newHashSet();
for (String subName : subscriptionNames) {
try {
Subscription<T,C> actualSubscription = DataDeliveryHandlers
Subscription<T, C> actualSubscription = DataDeliveryHandlers
.getSubscriptionHandler().getByName(subName);
actualSubscriptions.add(actualSubscription);
} catch (RegistryHandlerException e) {
@ -1332,7 +1345,8 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
* the subscription
* @return the required dataset size
*/
private long determineRequiredDataSetSize(final Subscription<T, C> subscription) {
private long determineRequiredDataSetSize(
final Subscription<T, C> subscription) {
return determineRequiredValue(subscription,
new FindSubscriptionRequiredDataSetSize());
}
@ -1430,7 +1444,8 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
* the subscription
* @return true if able to be cleanly scheduled, false otherwise
*/
private boolean isSchedulableWithoutConflict(final Subscription<T, C> subscription) {
private boolean isSchedulableWithoutConflict(
final Subscription<T, C> subscription) {
BandwidthMap copyOfCurrentMap = BandwidthMap
.load(EdexBandwidthContextFactory.getBandwidthMapConfig());
@ -1458,15 +1473,17 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage> exten
/**
* Special handling for Gridded Times with cycles and time indicies
*
* @param subTime
* @param dataSetMetaDataTime
* @return
*/
protected static Time handleCyclesAndSequences(Time subTime, Time dataSetMetaDataTime) {
protected static Time handleCyclesAndSequences(Time subTime,
Time dataSetMetaDataTime) {
if (subTime instanceof GriddedTime) {
GriddedTime time = (GriddedTime)subTime;
GriddedTime dsmTime = (GriddedTime)dataSetMetaDataTime;
GriddedTime time = (GriddedTime) subTime;
GriddedTime dsmTime = (GriddedTime) dataSetMetaDataTime;
dsmTime.setSelectedTimeIndices(time.getSelectedTimeIndices());
dsmTime.setCycleTimes(time.getCycleTimes());
}

View file

@ -96,13 +96,15 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
* Add throws to updatePointDataSetMetaData.
* Oct 1 2013 1797 dhladky Time and GriddedTime separation
* Oct 10, 2013 1797 bgonzale Refactored registry Time objects.
* 10/23/2013 2385 bphillip Change schedule method to scheduleAdhoc
*
* </pre>
*
* @author djohnson
* @version 1.0
*/
public abstract class EdexBandwidthManager<T extends Time, C extends Coverage> extends BandwidthManager<T, C> {
public abstract class EdexBandwidthManager<T extends Time, C extends Coverage>
extends BandwidthManager<T, C> {
private static final Pattern RAP_PATTERN = Pattern
.compile(".*rap_f\\d\\d$");
@ -135,8 +137,9 @@ public abstract class EdexBandwidthManager<T extends Time, C extends Coverage> e
* @param bandwidthDaoUtil
*/
public EdexBandwidthManager(IBandwidthDbInit dbInit,
IBandwidthDao<T,C> bandwidthDao, RetrievalManager retrievalManager,
BandwidthDaoUtil<T,C> bandwidthDaoUtil,
IBandwidthDao<T, C> bandwidthDao,
RetrievalManager retrievalManager,
BandwidthDaoUtil<T, C> bandwidthDaoUtil,
IDataSetMetaDataHandler dataSetMetaDataHandler,
ISubscriptionHandler subscriptionHandler) {
super(dbInit, bandwidthDao, retrievalManager, bandwidthDaoUtil);
@ -393,11 +396,11 @@ public abstract class EdexBandwidthManager<T extends Time, C extends Coverage> e
GriddedDataSetMetaData dataSetMetaData) throws ParseException {
// Daily/Hourly/Monthly datasets
if (dataSetMetaData.getCycle() == GriddedDataSetMetaData.NO_CYCLE) {
updateDataSetMetaDataWithoutCycle((DataSetMetaData<T>)dataSetMetaData);
updateDataSetMetaDataWithoutCycle((DataSetMetaData<T>) dataSetMetaData);
}
// Regular cycle containing datasets
else {
updateDataSetMetaDataWithCycle((DataSetMetaData<T>)dataSetMetaData);
updateDataSetMetaDataWithCycle((DataSetMetaData<T>) dataSetMetaData);
}
}
@ -465,7 +468,7 @@ public abstract class EdexBandwidthManager<T extends Time, C extends Coverage> e
try {
// Update the retrieval times on the subscription object
// which goes through the retrieval process
final SubscriptionRetrievalAttributes<T,C> subscriptionRetrievalAttributes = bandwidthDao
final SubscriptionRetrievalAttributes<T, C> subscriptionRetrievalAttributes = bandwidthDao
.getSubscriptionRetrievalAttributes(retrieval);
final Subscription<T, C> subscription = subscriptionRetrievalAttributes
.getSubscription();
@ -480,7 +483,8 @@ public abstract class EdexBandwidthManager<T extends Time, C extends Coverage> e
subTime.setRequestStart(earliestRetrievalDataTime);
subTime.setRequestEnd(latestRetrievalDataTime);
subTime.setTimes(time.getTimes());
subscriptionRetrievalAttributes.setSubscription(subscription);
subscriptionRetrievalAttributes
.setSubscription(subscription);
bandwidthDao.update(subscriptionRetrievalAttributes);
@ -533,13 +537,14 @@ public abstract class EdexBandwidthManager<T extends Time, C extends Coverage> e
dataSetMetaData.getUrl()));
// Create an adhoc for each one, and schedule it
for (Subscription<T,C> subscription : subscriptions) {
for (Subscription<T, C> subscription : subscriptions) {
@SuppressWarnings("unchecked")
Subscription<T,C> sub = updateSubscriptionWithDataSetMetaData(
Subscription<T, C> sub = updateSubscriptionWithDataSetMetaData(
subscription, dataSetMetaData);
if (sub instanceof SiteSubscription) {
schedule(new AdhocSubscription<T,C>((SiteSubscription<T,C>) sub));
scheduleAdhoc(new AdhocSubscription<T, C>(
(SiteSubscription<T, C>) sub));
} else {
statusHandler
.warn("Unable to create adhoc queries for shared subscriptions at this point. This functionality should be added in the future...");
@ -583,10 +588,10 @@ public abstract class EdexBandwidthManager<T extends Time, C extends Coverage> e
// SubscriptionRetrieval with the current DataSetMetaData
// URL and time Object
SubscriptionRetrievalAttributes<T,C> attributes = bandwidthDao
SubscriptionRetrievalAttributes<T, C> attributes = bandwidthDao
.getSubscriptionRetrievalAttributes(retrieval);
Subscription<T,C> sub;
Subscription<T, C> sub;
try {
sub = updateSubscriptionWithDataSetMetaData(
attributes.getSubscription(), dataSetMetaData);
@ -608,12 +613,12 @@ public abstract class EdexBandwidthManager<T extends Time, C extends Coverage> e
bandwidthDaoUtil.update(retrieval);
statusHandler
.info(String.format("Updated retrieval [%s] for "
statusHandler.info(String.format(
"Updated retrieval [%s] for "
+ "subscription [%s] to use "
+ "url [%s] and "
+ "base reference time [%s]", retrieval
.getIdentifier(), sub.getName(),
+ "base reference time [%s]",
retrieval.getIdentifier(), sub.getName(),
dataSetMetaData.getUrl(),
BandwidthUtil.format(sub.getTime().getStart())));
}
@ -647,14 +652,14 @@ public abstract class EdexBandwidthManager<T extends Time, C extends Coverage> e
}
}
Set<Subscription<T,C>> subscriptions = new HashSet<Subscription<T,C>>();
Set<Subscription<T, C>> subscriptions = new HashSet<Subscription<T, C>>();
for (SubscriptionRetrieval retrieval : retrievals) {
try {
final SubscriptionRetrievalAttributes<T,C> sra = bandwidthDao
final SubscriptionRetrievalAttributes<T, C> sra = bandwidthDao
.getSubscriptionRetrievalAttributes(retrieval);
if (sra != null) {
@SuppressWarnings("unchecked")
Subscription<T,C> sub = sra.getSubscription();
Subscription<T, C> sub = sra.getSubscription();
if (sub != null) {
subscriptions.add(sub);
}
@ -666,7 +671,7 @@ public abstract class EdexBandwidthManager<T extends Time, C extends Coverage> e
}
}
for (Subscription<T,C> subscription : subscriptions) {
for (Subscription<T, C> subscription : subscriptions) {
subscription.setUnscheduled(true);
subscriptionUpdated(subscription);
}
@ -700,7 +705,7 @@ public abstract class EdexBandwidthManager<T extends Time, C extends Coverage> e
* reinitialize operation.
*/
private void bandwidthMapConfigurationUpdated() {
IBandwidthRequest<T,C> request = new IBandwidthRequest<T,C>();
IBandwidthRequest<T, C> request = new IBandwidthRequest<T, C>();
request.setRequestType(RequestType.REINITIALIZE);
try {

View file

@ -41,6 +41,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.interfaces.ISubscriptionAggre
* ------------ ---------- ----------- --------------------------
* Oct 30, 2012 1286 djohnson Initial creation
* Jul 10, 2013 2106 djohnson Remove EDEX instance specific methods.
* 10/23/2013 2385 bphillip Change schedule method to scheduleAdhoc
*
* </pre>
*
@ -66,7 +67,7 @@ public interface IBandwidthManager<T extends Time, C extends Coverage> {
* @param b
* @return
*/
List<BandwidthAllocation> schedule(AdhocSubscription<T, C> subscription);
List<BandwidthAllocation> scheduleAdhoc(AdhocSubscription<T, C> subscription);
/**
* When a Subscription is updated in the Registry, update the retrieval plan
@ -76,8 +77,8 @@ public interface IBandwidthManager<T extends Time, C extends Coverage> {
* @return
* @throws SerializationException
*/
List<BandwidthAllocation> subscriptionUpdated(Subscription<T, C> subscription)
throws SerializationException;
List<BandwidthAllocation> subscriptionUpdated(
Subscription<T, C> subscription) throws SerializationException;
/**
*

View file

@ -34,7 +34,8 @@ Require-Bundle: com.raytheon.uf.common.registry.schemas.ebxml;bundle-version="1.
com.raytheon.uf.common.datadelivery.request;bundle-version="1.0.0",
javax.mail;bundle-version="1.0.0",
org.apache.commons.validator;bundle-version="1.2.0",
com.sun.xml.bind;bundle-version="1.0.0"
com.sun.xml.bind;bundle-version="1.0.0",
org.reflections;bundle-version="0.9.9"
Export-Package: com.raytheon.uf.edex.registry.ebxml.acp,
com.raytheon.uf.edex.registry.ebxml.dao,
com.raytheon.uf.edex.registry.ebxml.exception,

View file

@ -21,12 +21,14 @@ package com.raytheon.uf.edex.registry.ebxml.services.rest;
import java.io.File;
import java.util.List;
import java.util.Set;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.xml.bind.JAXB;
import javax.xml.bind.JAXBException;
import javax.xml.bind.annotation.XmlRootElement;
import oasis.names.tc.ebxml.regrep.wsdl.registry.services.v4.LifecycleManager;
import oasis.names.tc.ebxml.regrep.wsdl.registry.services.v4.MsgRegistryException;
@ -40,21 +42,29 @@ import oasis.names.tc.ebxml.regrep.xsd.rim.v4.RegistryObjectListType;
import oasis.names.tc.ebxml.regrep.xsd.rim.v4.RegistryObjectType;
import oasis.names.tc.ebxml.regrep.xsd.rim.v4.SubscriptionType;
import org.reflections.Reflections;
import org.reflections.scanners.TypeAnnotationsScanner;
import org.reflections.util.ClasspathHelper;
import org.reflections.util.ConfigurationBuilder;
import org.springframework.transaction.annotation.Transactional;
import com.raytheon.uf.common.registry.RegistryException;
import com.raytheon.uf.common.registry.services.rest.IRegistryDataAccessService;
import com.raytheon.uf.common.registry.services.rest.response.RestCollectionResponse;
import com.raytheon.uf.common.serialization.JAXBManager;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.util.CollectionUtil;
import com.raytheon.uf.common.util.StringUtil;
import com.raytheon.uf.edex.core.EDEXUtil;
import com.raytheon.uf.edex.core.EdexException;
import com.raytheon.uf.edex.registry.ebxml.dao.QueryDefinitionDao;
import com.raytheon.uf.edex.registry.ebxml.dao.RegistryObjectDao;
/**
*
* Implementation of the registry data access service interface
* Implementation of the registry data access service interface <br>
* TODO: This class really needs to be moved to a data delivery specific plugin
*
* <pre>
*
@ -66,6 +76,7 @@ import com.raytheon.uf.edex.registry.ebxml.dao.RegistryObjectDao;
* 9/20/2013 2385 bphillip Added subscription backup functions
* 10/2/2013 2385 bphillip Fixed subscription backup queries
* 10/8/2013 1682 bphillip Added query queries
* 10/23/2013 2385 bphillip Restored subscriptions are now scheduled in the bandwidth manager
* </pre>
*
* @author bphillip
@ -91,6 +102,8 @@ public class RegistryDataAccessService implements IRegistryDataAccessService {
+ "where obj.objectType like '%SiteSubscription' "
+ "OR obj.objectType like '%SharedSubscription' order by obj.id asc";
private static final JAXBManager subscriptionJaxbManager = initJaxbManager();
/** Data access object for registry objects */
private RegistryObjectDao registryObjectDao;
@ -234,8 +247,7 @@ public class RegistryDataAccessService implements IRegistryDataAccessService {
@GET
@Path(DATA_ACCESS_PATH_PREFIX + "backupSubscription/{subscriptionName}")
public String backupSubscription(
@PathParam("subscriptionName") String subscriptionName)
throws JAXBException {
@PathParam("subscriptionName") String subscriptionName) {
StringBuilder response = new StringBuilder();
List<RegistryObjectType> result = registryObjectDao.executeHQLQuery(
GET_SINGLE_SUBSCRIPTIONS_QUERY, "id", subscriptionName);
@ -277,7 +289,7 @@ public class RegistryDataAccessService implements IRegistryDataAccessService {
@Override
@GET
@Path(DATA_ACCESS_PATH_PREFIX + "backupAllSubscriptions/")
public String backupAllSubscriptions() throws JAXBException {
public String backupAllSubscriptions() {
StringBuilder response = new StringBuilder();
List<RegistryObjectType> subs = registryObjectDao
.executeHQLQuery(GET_SUBSCRIPTIONS_QUERY);
@ -300,16 +312,32 @@ public class RegistryDataAccessService implements IRegistryDataAccessService {
@GET
@Path(DATA_ACCESS_PATH_PREFIX + "restoreSubscription/{subscriptionName}")
public String restoreSubscription(
@PathParam("subscriptionName") String subscriptionName)
throws JAXBException {
@PathParam("subscriptionName") String subscriptionName) {
StringBuilder response = new StringBuilder();
File subscriptionFile = new File(SUBSCRIPTION_BACKUP_DIR
+ File.separator + subscriptionName);
if (subscriptionFile.exists()) {
SubmitObjectsRequest submitRequest = JAXB.unmarshal(
subscriptionFile, SubmitObjectsRequest.class);
String subscriptionXML = submitRequest.getRegistryObjects().get(0)
.getSlotByName("content").getSlotValue().getValue();
try {
Object subObj = subscriptionJaxbManager
.unmarshalFromXml(subscriptionXML);
EDEXUtil.getMessageProducer().sendSync("scheduleSubscription",
subObj);
lcm.submitObjects(submitRequest);
subscriptionFile.delete();
response.append(
"Subscription successfully restored from file [")
.append(subscriptionFile).append("]<br>");
} catch (EdexException e1) {
statusHandler.error("Error submitting subscription", e1);
response.append("Subscription from file [")
.append(subscriptionFile)
.append("] failed to be restored: ")
.append(e1.getLocalizedMessage()).append("<br>");
} catch (MsgRegistryException e) {
response.append("Error restoring subscription from file [")
.append(subscriptionFile).append("] ")
@ -317,10 +345,13 @@ public class RegistryDataAccessService implements IRegistryDataAccessService {
statusHandler.error("Error restoring subscription from file ["
+ subscriptionFile + "]", e);
return response.toString();
} catch (JAXBException e) {
response.append("Error restoring subscription from file [")
.append(subscriptionFile).append("] ")
.append(e.getMessage()).append("<br>");
statusHandler.error("Error restoring subscription from file ["
+ subscriptionFile + "]", e);
}
subscriptionFile.delete();
response.append("Subscription successfully restored from file [")
.append(subscriptionFile).append("]<br>");
} else {
response.append("No backup file exists for subscription[")
.append(subscriptionName).append("]<br>");
@ -345,18 +376,7 @@ public class RegistryDataAccessService implements IRegistryDataAccessService {
response.append("No subscriptions found to restore<br>");
} else {
for (File subscription : filesToRestore) {
try {
response.append(restoreSubscription(subscription
.getName()));
} catch (JAXBException e) {
statusHandler.error("Error restoring subscription ["
+ subscription + "]", e);
response.append("Error restoring subscription [")
.append(subscription).append("] ")
.append(e.getMessage()).append("<br>");
continue;
}
response.append(restoreSubscription(subscription.getName()));
}
}
} else {
@ -394,6 +414,28 @@ public class RegistryDataAccessService implements IRegistryDataAccessService {
return response.toString();
}
/**
* Initializes the JAXBManager for datadelivery classes.
*
* @return JAXBManager for datadelivery classes
*/
private static JAXBManager initJaxbManager() {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.addUrls(ClasspathHelper
.forPackage("com.raytheon.uf.common.datadelivery.registry"));
cb.setScanners(new TypeAnnotationsScanner());
Reflections reflecs = cb.build();
Set<Class<?>> classes = reflecs
.getTypesAnnotatedWith(XmlRootElement.class);
try {
return new JAXBManager(
classes.toArray(new Class<?>[classes.size()]));
} catch (JAXBException e) {
throw new RuntimeException(
"Error initializing subscription jaxb Manager!", e);
}
}
public void setRegistryObjectDao(RegistryObjectDao registryObjectDao) {
this.registryObjectDao = registryObjectDao;
}