From 0905d6ffdd900d323b7ce351f7044a19b189a04f Mon Sep 17 00:00:00 2001 From: Benjamin Phillippe Date: Wed, 23 Oct 2013 16:15:13 -0500 Subject: [PATCH] Issue #2385 Fixed subscription backup web service. Restored subscriptions are now scheduled in the bandwidth manager Change-Id: I7e0e98517ff7d2213957004c6a94e38cf7063cce Former-commit-id: 40fec1c49a0a4aa2ecb4afdf4cf225e6359efd28 --- .../rest/IRegistryDataAccessService.java | 15 +-- .../res/spring/bandwidth-datadelivery.xml | 17 +++- .../bandwidth/BandwidthManager.java | 97 +++++++++++-------- .../bandwidth/EdexBandwidthManager.java | 47 +++++---- .../bandwidth/IBandwidthManager.java | 7 +- .../META-INF/MANIFEST.MF | 3 +- .../rest/RegistryDataAccessService.java | 84 ++++++++++++---- 7 files changed, 170 insertions(+), 100 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.common.registry.ebxml/src/com/raytheon/uf/common/registry/services/rest/IRegistryDataAccessService.java b/edexOsgi/com.raytheon.uf.common.registry.ebxml/src/com/raytheon/uf/common/registry/services/rest/IRegistryDataAccessService.java index 03af0aff27..8234045d26 100644 --- a/edexOsgi/com.raytheon.uf.common.registry.ebxml/src/com/raytheon/uf/common/registry/services/rest/IRegistryDataAccessService.java +++ b/edexOsgi/com.raytheon.uf.common.registry.ebxml/src/com/raytheon/uf/common/registry/services/rest/IRegistryDataAccessService.java @@ -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 * * * @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 diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery.xml b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery.xml index cdce5e7807..ae6fa98860 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery.xml +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery.xml @@ -1,7 +1,8 @@ - + 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 + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> + @@ -86,5 +87,15 @@ + + + + + + + + diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManager.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManager.java index c3968aee66..7ae9e3be38 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManager.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManager.java @@ -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 * * * @author dhladky * @version 1.0 */ -public abstract class BandwidthManager extends - AbstractPrivilegedRequestHandler> implements - IBandwidthManager { +public abstract class BandwidthManager + extends AbstractPrivilegedRequestHandler> + implements IBandwidthManager { protected static final IUFStatusHandler statusHandler = UFStatus .getHandler(BandwidthManager.class); @@ -141,7 +142,7 @@ public abstract class BandwidthManager exten private BandwidthInitializer initializer; - protected final BandwidthDaoUtil bandwidthDaoUtil; + protected final BandwidthDaoUtil bandwidthDaoUtil; private final IBandwidthDbInit dbInit; @@ -154,8 +155,9 @@ public abstract class BandwidthManager exten final RetrievalManager retrievalManager; public BandwidthManager(IBandwidthDbInit dbInit, - IBandwidthDao bandwidthDao, RetrievalManager retrievalManager, - BandwidthDaoUtil bandwidthDaoUtil) { + IBandwidthDao bandwidthDao, + RetrievalManager retrievalManager, + BandwidthDaoUtil bandwidthDaoUtil) { this.dbInit = dbInit; this.bandwidthDao = bandwidthDao; this.retrievalManager = retrievalManager; @@ -244,8 +246,8 @@ public abstract class BandwidthManager exten return unscheduled; } - protected List schedule(Subscription subscription, - BandwidthSubscription dao) { + protected List schedule( + Subscription 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 exten * @return */ @Override - public List schedule(AdhocSubscription subscription) { + public List scheduleAdhoc( + AdhocSubscription subscription) { List subscriptions = new ArrayList(); Calendar now = BandwidthUtil.now(); @@ -453,8 +456,7 @@ public abstract class BandwidthManager exten * and time. */ AdhocSubscription subscriptionUpdated = bandwidthDaoUtil - .setAdhocMostRecentUrlAndTime( - subscription, true); + .setAdhocMostRecentUrlAndTime(subscription, true); if (subscriptionUpdated != null) { subscription = subscriptionUpdated; } @@ -558,7 +560,8 @@ public abstract class BandwidthManager exten * the subscription * @return the list of unscheduled subscriptions */ - private List handlePoint(Subscription subscription) { + private List handlePoint( + Subscription subscription) { return schedule(subscription, ((PointTime) subscription.getTime()).getInterval()); } @@ -570,8 +573,10 @@ public abstract class BandwidthManager exten * the subscription * @return the list of unscheduled subscriptions */ - private List handleGridded(Subscription subscription) { - final List cycles = ((GriddedTime)subscription.getTime()).getCycleTimes(); + private List handleGridded( + Subscription subscription) { + final List cycles = ((GriddedTime) subscription.getTime()) + .getCycleTimes(); final boolean subscribedToCycles = !CollectionUtil .isNullOrEmpty(cycles); final boolean useMostRecentDataSetUpdate = !subscribedToCycles; @@ -599,7 +604,7 @@ public abstract class BandwidthManager exten + "No adhoc requested.", subscription.getName())); } else { - unscheduled = schedule(adhoc); + unscheduled = scheduleAdhoc(adhoc); } } else { statusHandler @@ -614,10 +619,11 @@ public abstract class BandwidthManager exten * @return */ @Override - public List adhocSubscription(AdhocSubscription adhoc) { + public List adhocSubscription( + AdhocSubscription adhoc) { statusHandler.info("Scheduling adhoc subscription [" + adhoc.getName() + "]"); - return schedule(adhoc); + return scheduleAdhoc(adhoc); } /** @@ -660,7 +666,8 @@ public abstract class BandwidthManager exten * {@inheritDoc} */ @Override - public Object handleRequest(IBandwidthRequest request) throws Exception { + public Object handleRequest(IBandwidthRequest request) + throws Exception { ITimer timer = TimeUtil.getTimer(); timer.start(); @@ -670,7 +677,8 @@ public abstract class BandwidthManager exten final Network requestNetwork = request.getNetwork(); final int bandwidth = request.getBandwidth(); - final List> subscriptions = request.getSubscriptions(); + final List> subscriptions = request + .getSubscriptions(); final RequestType requestType = request.getRequestType(); switch (requestType) { case GET_ESTIMATED_COMPLETION: @@ -797,7 +805,8 @@ public abstract class BandwidthManager exten * @throws SerializationException */ protected abstract Set scheduleSbnSubscriptions( - List> subscriptions) throws SerializationException; + List> subscriptions) + throws SerializationException; /** * Proposes scheduling a list of subscriptions. @@ -808,7 +817,8 @@ public abstract class BandwidthManager exten * @throws SerializationException */ protected ProposeScheduleResponse proposeScheduleSubscriptions( - List> subscriptions) throws SerializationException { + List> subscriptions) + throws SerializationException { final ProposeScheduleResponse proposeResponse = proposeSchedule(subscriptions); Set subscriptionsUnscheduled = proposeResponse .getUnscheduledSubscriptions(); @@ -907,7 +917,8 @@ public abstract class BandwidthManager exten * @return the set of subscription names unscheduled * @throws SerializationException */ - protected Set scheduleSubscriptions(List> subscriptions) + protected Set scheduleSubscriptions( + List> subscriptions) throws SerializationException { Set unscheduledSubscriptions = new TreeSet(); @@ -993,7 +1004,8 @@ public abstract class BandwidthManager exten * @throws SerializationException */ private ProposeScheduleResponse proposeSchedule( - List> subscriptions) throws SerializationException { + List> subscriptions) + throws SerializationException { BandwidthMap copyOfCurrentMap = BandwidthMap .load(EdexBandwidthContextFactory.getBandwidthMapConfig()); @@ -1100,7 +1112,8 @@ public abstract class BandwidthManager exten * @throws SerializationException */ @VisibleForTesting - BandwidthManager startProposedBandwidthManager(BandwidthMap bandwidthMap) { + BandwidthManager startProposedBandwidthManager( + BandwidthMap bandwidthMap) { InMemoryBandwidthContextFactory .setInMemoryBandwidthConfigFile(bandwidthMap); @@ -1137,8 +1150,8 @@ public abstract class BandwidthManager exten * @param type * @return the reference to the bandwidth manager */ - private BandwidthManager startBandwidthManager(final String[] springFiles, - boolean close, String type) { + private BandwidthManager startBandwidthManager( + final String[] springFiles, boolean close, String type) { ITimer timer = TimeUtil.getTimer(); timer.start(); @@ -1146,8 +1159,8 @@ public abstract class BandwidthManager exten try { ctx = new ClassPathXmlApplicationContext(springFiles, EDEXUtil.getSpringContext()); - final BandwidthManager bwManager = ctx.getBean("bandwidthManager", - BandwidthManager.class); + final BandwidthManager bwManager = ctx.getBean( + "bandwidthManager", BandwidthManager.class); try { bwManager.initializer.executeAfterRegistryInit(); return bwManager; @@ -1218,11 +1231,11 @@ public abstract class BandwidthManager exten /** * {@inheritDoc} */ - public List copyState(BandwidthManager copyFrom) { + public List copyState(BandwidthManager copyFrom) { IPerformanceTimer timer = TimeUtil.getPerformanceTimer(); timer.start(); List unscheduled = Collections.emptyList(); - IBandwidthDao fromDao = copyFrom.bandwidthDao; + IBandwidthDao fromDao = copyFrom.bandwidthDao; final boolean proposingBandwidthChange = retrievalManager .isProposingBandwidthChanges(copyFrom.retrievalManager); @@ -1239,10 +1252,10 @@ public abstract class BandwidthManager exten subscriptionNames.add(subscription.getName()); } - Set> actualSubscriptions = Sets.newHashSet(); + Set> actualSubscriptions = Sets.newHashSet(); for (String subName : subscriptionNames) { try { - Subscription actualSubscription = DataDeliveryHandlers + Subscription actualSubscription = DataDeliveryHandlers .getSubscriptionHandler().getByName(subName); actualSubscriptions.add(actualSubscription); } catch (RegistryHandlerException e) { @@ -1332,7 +1345,8 @@ public abstract class BandwidthManager exten * the subscription * @return the required dataset size */ - private long determineRequiredDataSetSize(final Subscription subscription) { + private long determineRequiredDataSetSize( + final Subscription subscription) { return determineRequiredValue(subscription, new FindSubscriptionRequiredDataSetSize()); } @@ -1430,7 +1444,8 @@ public abstract class BandwidthManager exten * the subscription * @return true if able to be cleanly scheduled, false otherwise */ - private boolean isSchedulableWithoutConflict(final Subscription subscription) { + private boolean isSchedulableWithoutConflict( + final Subscription subscription) { BandwidthMap copyOfCurrentMap = BandwidthMap .load(EdexBandwidthContextFactory.getBandwidthMapConfig()); @@ -1455,22 +1470,24 @@ public abstract class BandwidthManager exten * Provide implementation specific shutdown. */ protected abstract void shutdownInternal(); - + /** * 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()); } - + return dataSetMetaDataTime; } } diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/EdexBandwidthManager.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/EdexBandwidthManager.java index 138fa918c8..b953de7833 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/EdexBandwidthManager.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/EdexBandwidthManager.java @@ -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 * * * * @author djohnson * @version 1.0 */ -public abstract class EdexBandwidthManager extends BandwidthManager { +public abstract class EdexBandwidthManager + extends BandwidthManager { private static final Pattern RAP_PATTERN = Pattern .compile(".*rap_f\\d\\d$"); @@ -135,8 +137,9 @@ public abstract class EdexBandwidthManager e * @param bandwidthDaoUtil */ public EdexBandwidthManager(IBandwidthDbInit dbInit, - IBandwidthDao bandwidthDao, RetrievalManager retrievalManager, - BandwidthDaoUtil bandwidthDaoUtil, + IBandwidthDao bandwidthDao, + RetrievalManager retrievalManager, + BandwidthDaoUtil bandwidthDaoUtil, IDataSetMetaDataHandler dataSetMetaDataHandler, ISubscriptionHandler subscriptionHandler) { super(dbInit, bandwidthDao, retrievalManager, bandwidthDaoUtil); @@ -393,11 +396,11 @@ public abstract class EdexBandwidthManager e GriddedDataSetMetaData dataSetMetaData) throws ParseException { // Daily/Hourly/Monthly datasets if (dataSetMetaData.getCycle() == GriddedDataSetMetaData.NO_CYCLE) { - updateDataSetMetaDataWithoutCycle((DataSetMetaData)dataSetMetaData); + updateDataSetMetaDataWithoutCycle((DataSetMetaData) dataSetMetaData); } // Regular cycle containing datasets else { - updateDataSetMetaDataWithCycle((DataSetMetaData)dataSetMetaData); + updateDataSetMetaDataWithCycle((DataSetMetaData) dataSetMetaData); } } @@ -465,7 +468,7 @@ public abstract class EdexBandwidthManager e try { // Update the retrieval times on the subscription object // which goes through the retrieval process - final SubscriptionRetrievalAttributes subscriptionRetrievalAttributes = bandwidthDao + final SubscriptionRetrievalAttributes subscriptionRetrievalAttributes = bandwidthDao .getSubscriptionRetrievalAttributes(retrieval); final Subscription subscription = subscriptionRetrievalAttributes .getSubscription(); @@ -480,7 +483,8 @@ public abstract class EdexBandwidthManager 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 e dataSetMetaData.getUrl())); // Create an adhoc for each one, and schedule it - for (Subscription subscription : subscriptions) { + for (Subscription subscription : subscriptions) { @SuppressWarnings("unchecked") - Subscription sub = updateSubscriptionWithDataSetMetaData( + Subscription sub = updateSubscriptionWithDataSetMetaData( subscription, dataSetMetaData); if (sub instanceof SiteSubscription) { - schedule(new AdhocSubscription((SiteSubscription) sub)); + scheduleAdhoc(new AdhocSubscription( + (SiteSubscription) 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 e // SubscriptionRetrieval with the current DataSetMetaData // URL and time Object - SubscriptionRetrievalAttributes attributes = bandwidthDao + SubscriptionRetrievalAttributes attributes = bandwidthDao .getSubscriptionRetrievalAttributes(retrieval); - Subscription sub; + Subscription sub; try { sub = updateSubscriptionWithDataSetMetaData( attributes.getSubscription(), dataSetMetaData); @@ -608,12 +613,12 @@ public abstract class EdexBandwidthManager 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 e } } - Set> subscriptions = new HashSet>(); + Set> subscriptions = new HashSet>(); for (SubscriptionRetrieval retrieval : retrievals) { try { - final SubscriptionRetrievalAttributes sra = bandwidthDao + final SubscriptionRetrievalAttributes sra = bandwidthDao .getSubscriptionRetrievalAttributes(retrieval); if (sra != null) { @SuppressWarnings("unchecked") - Subscription sub = sra.getSubscription(); + Subscription sub = sra.getSubscription(); if (sub != null) { subscriptions.add(sub); } @@ -666,7 +671,7 @@ public abstract class EdexBandwidthManager e } } - for (Subscription subscription : subscriptions) { + for (Subscription subscription : subscriptions) { subscription.setUnscheduled(true); subscriptionUpdated(subscription); } @@ -700,7 +705,7 @@ public abstract class EdexBandwidthManager e * reinitialize operation. */ private void bandwidthMapConfigurationUpdated() { - IBandwidthRequest request = new IBandwidthRequest(); + IBandwidthRequest request = new IBandwidthRequest(); request.setRequestType(RequestType.REINITIALIZE); try { diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/IBandwidthManager.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/IBandwidthManager.java index aeacbaa41b..11e708c7c2 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/IBandwidthManager.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/IBandwidthManager.java @@ -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 * * * @@ -66,7 +67,7 @@ public interface IBandwidthManager { * @param b * @return */ - List schedule(AdhocSubscription subscription); + List scheduleAdhoc(AdhocSubscription subscription); /** * When a Subscription is updated in the Registry, update the retrieval plan @@ -76,8 +77,8 @@ public interface IBandwidthManager { * @return * @throws SerializationException */ - List subscriptionUpdated(Subscription subscription) - throws SerializationException; + List subscriptionUpdated( + Subscription subscription) throws SerializationException; /** * diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/META-INF/MANIFEST.MF b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/META-INF/MANIFEST.MF index b867831290..1a9b10b1ff 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/META-INF/MANIFEST.MF +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/META-INF/MANIFEST.MF @@ -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, diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/rest/RegistryDataAccessService.java b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/rest/RegistryDataAccessService.java index 3c5b4067b8..09ffd01fb7 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/rest/RegistryDataAccessService.java +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/rest/RegistryDataAccessService.java @@ -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
+ * TODO: This class really needs to be moved to a data delivery specific plugin * *
  * 
@@ -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
  * 
* * @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 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 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("]
"); + } 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("
"); } 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("
"); + statusHandler.error("Error restoring subscription from file [" + + subscriptionFile + "]", e); } - subscriptionFile.delete(); - response.append("Subscription successfully restored from file [") - .append(subscriptionFile).append("]
"); } else { response.append("No backup file exists for subscription[") .append(subscriptionName).append("]
"); @@ -345,18 +376,7 @@ public class RegistryDataAccessService implements IRegistryDataAccessService { response.append("No subscriptions found to restore
"); } 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("
"); - 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> 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; }