Merge "Issue #2506 BandwidthManagers now sends notifications for Subscription/BandwidthSubscription creates and deletes." into development

Former-commit-id: 9af1de07d4 [formerly 116b4409d4657b5dba8c9e3e52e2198661cb9691]
Former-commit-id: f12839a9e5
This commit is contained in:
Richard Peter 2013-11-12 13:47:04 -06:00 committed by Gerrit Code Review
commit c8ff79a7f5
13 changed files with 139 additions and 62 deletions

View file

@ -143,6 +143,7 @@ import com.raytheon.viz.ui.presenter.components.ComboBoxConf;
* Oct 23, 2013 2484 dhladky Unique ID for subscriptions updated.
* Oct 21, 2013 2292 mpduff Close dialog on OK.
* Nov 07, 2013 2291 skorolev Used showText() method for "Unable to Create Subscription" message.
* Nov 08, 2013 2506 bgonzale Removed send notification when a subscription is updated and created.
*
* </pre>
*
@ -1179,12 +1180,7 @@ public class CreateSubscriptionDlg extends CaveSWTDialog {
public void done(final IJobChangeEvent event) {
try {
final IStatus status = event.getResult();
final boolean subscriptionCreated = status.isOK();
if (subscriptionCreated) {
sendSubscriptionNotification(subscription,
username);
}
if (!Strings.isNullOrEmpty(status.getMessage())) {
guiThreadTaskExecutor.runAsync(new Runnable() {
@ -1286,10 +1282,6 @@ public class CreateSubscriptionDlg extends CaveSWTDialog {
return false;
}
subscriptionNotificationService
.sendUpdatedSubscriptionNotification(subscription,
username);
} catch (RegistryHandlerException e) {
statusHandler.handle(Priority.PROBLEM,
"Unable to update subscription.", e);

View file

@ -67,6 +67,7 @@ import com.raytheon.viz.ui.presenter.components.WidgetConf;
* Apr 08, 2013 1826 djohnson Remove delivery options.
* May 14, 2013 1040 mpduff Changed to add office Id rather than setting it.
* May 21, 2013 2020 mpduff Rename UserSubscription to SiteSubscription.
* Nov 08, 2013 2506 bgonzale Removed send notification when a subscription is created.
*
* </pre>
*
@ -279,9 +280,6 @@ public class GroupAddDlg extends CaveSWTDialog {
return false;
}
subscriptionNotificationService.sendCreatedSubscriptionNotification(
subscription, username);
// refresh table
callback.handleRefresh();

View file

@ -142,6 +142,7 @@ import com.raytheon.viz.ui.presenter.IDisplay;
* Sep 25. 2013 2409 mpduff Add check for widget disposed after calling configuration.
* Oct 25, 2013 2292 mpduff Move overlap checks to edex.
* Nov 06, 2013 2358 mpduff Resurrected file management code.
* Nov 08, 2013 2506 bgonzale Removed send notification when a subscription is deleted.
* </pre>
*
* @author mpduff
@ -1330,12 +1331,6 @@ public class SubscriptionManagerDlg extends CaveSWTDialog implements
.get(ISubscriptionHandler.class);
try {
handler.delete(username, subscriptions);
for (Subscription subscription : subscriptions) {
subscriptionNotificationService
.sendDeletedSubscriptionNotification(subscription,
username);
}
} catch (RegistryHandlerException e) {
exceptions.add(e);
}

View file

@ -34,6 +34,7 @@ import com.raytheon.uf.common.registry.ebxml.RegistryUtil;
* Dec 11, 2012 1403 djohnson Adhoc subscriptions no longer go to the registry.
* May 21, 2013 2020 mpduff Rename UserSubscription to SiteSubscription.
* Oct 11, 2013 2460 dhladky Restored Adhoc to registry store, WFO only.
* Nov 12, 2013 2506 bgonzale Added is recurring subscription method.
*
* </pre>
*
@ -65,4 +66,19 @@ public final class DataDeliveryRegistryObjectTypes {
public static final String PROVIDER = RegistryUtil
.getObjectType(Provider.class);
/**
* Is the object type a recurring subscription type, excluding adhoc
* subscriptions.
*
* @param objectType
* @return true if the objectType is a recurring subscription type; false
* otherwise.
*/
public static final boolean isRecurringSubscription(String objectType) {
return DataDeliveryRegistryObjectTypes.SHARED_SUBSCRIPTION
.equals(objectType)
|| DataDeliveryRegistryObjectTypes.SITE_SUBSCRIPTION
.equals(objectType);
}
}

View file

@ -9,3 +9,4 @@ Export-Package: com.raytheon.uf.common.registry.event
Require-Bundle: com.raytheon.uf.common.serialization;bundle-version="1.12.1174",
com.raytheon.uf.common.event;bundle-version="1.0.0",
com.raytheon.uf.common.stats;bundle-version="1.0.0"
Import-Package: oasis.names.tc.ebxml.regrep.xsd.rim.v4

View file

@ -20,6 +20,8 @@ package com.raytheon.uf.common.registry.event;
* further licensing information.
**/
import oasis.names.tc.ebxml.regrep.xsd.rim.v4.RegistryObjectType;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
/**
@ -33,7 +35,8 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Mar 16, 2012 jsanchez Initial creation
* Nov 08, 2013 2506 bgonzale Added constructors.
* Nov 08, 2013 2506 bgonzale Added constructors. Added object deleted field.
* Added RegistryObjectType field.
*
* </pre>
*
@ -47,13 +50,17 @@ public class RemoveRegistryEvent extends RegistryEvent {
private String username;
private RegistryObjectType removedObject;
public RemoveRegistryEvent() {
}
public RemoveRegistryEvent(String username, String id) {
public RemoveRegistryEvent(String username, String id,
RegistryObjectType removedObject) {
super(id, null, null, Action.DELETE);
this.username = username;
this.removedObject = removedObject;
}
public String getUsername() {
@ -64,6 +71,21 @@ public class RemoveRegistryEvent extends RegistryEvent {
this.username = username;
}
/**
* @return the removedObject
*/
public RegistryObjectType getRemovedObject() {
return removedObject;
}
/**
* @param removedObject
* the removedObject to set
*/
public void setRemovedObject(RegistryObjectType removedObject) {
this.removedObject = removedObject;
}
@Override
public String toString() {
return "Remove " + super.toString();

View file

@ -16,5 +16,6 @@ Require-Bundle: com.raytheon.uf.common.datadelivery.bandwidth;bundle-version="1.
com.raytheon.uf.common.status;bundle-version="1.12.1174",
com.google.guava;bundle-version="1.0.0",
com.raytheon.uf.edex.core;bundle-version="1.12.1174",
com.raytheon.uf.common.registry.ebxml;bundle-version="1.0.0"
com.raytheon.uf.common.registry.ebxml;bundle-version="1.0.0",
com.raytheon.uf.common.datadelivery.service;bundle-version="1.0.0"
Import-Package: com.raytheon.edex.site

View file

@ -19,6 +19,8 @@
**/
package com.raytheon.uf.edex.datadelivery.bandwidth;
import static com.raytheon.uf.common.registry.ebxml.encoder.RegistryEncoders.Type.JAXB;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
@ -37,6 +39,7 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe;
import com.raytheon.edex.site.SiteUtil;
import com.raytheon.uf.common.datadelivery.bandwidth.IBandwidthRequest;
import com.raytheon.uf.common.datadelivery.bandwidth.IBandwidthRequest.RequestType;
import com.raytheon.uf.common.datadelivery.registry.AdhocSubscription;
@ -53,8 +56,11 @@ import com.raytheon.uf.common.datadelivery.registry.handlers.IDataSetMetaDataHan
import com.raytheon.uf.common.datadelivery.registry.handlers.ISubscriptionHandler;
import com.raytheon.uf.common.datadelivery.service.ISubscriptionNotificationService;
import com.raytheon.uf.common.event.EventBus;
import com.raytheon.uf.common.registry.ebxml.encoder.RegistryEncoders;
import com.raytheon.uf.common.registry.event.InsertRegistryEvent;
import com.raytheon.uf.common.registry.event.RegistryEvent;
import com.raytheon.uf.common.registry.event.RemoveRegistryEvent;
import com.raytheon.uf.common.registry.event.UpdateRegistryEvent;
import com.raytheon.uf.common.registry.handler.IRegistryObjectHandler;
import com.raytheon.uf.common.registry.handler.RegistryHandlerException;
import com.raytheon.uf.common.serialization.SerializationException;
@ -100,6 +106,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
* 10/23/2013 2385 bphillip Change schedule method to scheduleAdhoc
* Nov 04, 2013 2506 bgonzale Added removeBandwidthSubscriptions method.
* Added subscriptionNotificationService field.
* Send notifications.
*
* </pre>
*
@ -325,6 +332,17 @@ public abstract class EdexBandwidthManager<T extends Time, C extends Coverage>
+ event.getId() + "]");
removeBandwidthSubscriptions(event.getId());
try {
Subscription<T, C> sub = (Subscription<T, C>) RegistryEncoders
.ofType(JAXB).decodeObject(
((RemoveRegistryEvent) event).getRemovedObject());
sendSubscriptionNotificationEvent(event, sub);
} catch (SerializationException e) {
statusHandler
.handle(Priority.PROBLEM,
"Failed to retrieve deleted object from RemoveRegistryEvent",
e);
}
}
}
}
@ -368,6 +386,59 @@ public abstract class EdexBandwidthManager<T extends Time, C extends Coverage>
+ "]");
}
}
Subscription<T, C> sub = getRegistryObjectById(subscriptionHandler,
re.getId());
sendSubscriptionNotificationEvent(re, sub);
}
/**
* Create a hook into the EDEX Notification sub-system to receive
* UpdateRegistryEvents. Filter for subscription specific events.
*
* @param event
*/
@Subscribe
@AllowConcurrentEvents
public void registryEventListener(UpdateRegistryEvent event) {
Subscription<T, C> sub = getRegistryObjectById(subscriptionHandler,
event.getId());
sendSubscriptionNotificationEvent(event, sub);
}
private void sendSubscriptionNotificationEvent(RegistryEvent event,
Subscription<T, C> sub) {
final String objectType = event.getObjectType();
if (DataDeliveryRegistryObjectTypes.isRecurringSubscription(objectType)) {
if (sub != null) {
boolean isApplicableForTheLocalSite = sub.getOfficeIDs()
.contains(SiteUtil.getSite());
if (isApplicableForTheLocalSite) {
switch (event.getAction()) {
case UPDATE:
subscriptionNotificationService
.sendUpdatedSubscriptionNotification(sub,
sub.getOwner());
break;
case INSERT:
subscriptionNotificationService
.sendCreatedSubscriptionNotification(sub,
sub.getOwner());
break;
case DELETE:
subscriptionNotificationService
.sendDeletedSubscriptionNotification(sub,
sub.getOwner());
break;
default:
statusHandler.handle(
Priority.PROBLEM,
"Invalid RegistryEvent action: "
+ event.getAction());
}
}
}
}
}
private DataSetMetaData<T> getDataSetMetaData(String id) {

View file

@ -18,7 +18,6 @@
<bean id="groupDefinitionServiceHandler"
class="com.raytheon.uf.edex.datadelivery.service.services.GroupDefinitionServiceHandler">
<constructor-arg ref="subscriptionNotificationService" />
</bean>
<bean factory-bean="handlerRegistry" factory-method="register">

View file

@ -29,7 +29,6 @@ import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.datadelivery.registry.handlers.DataDeliveryHandlers;
import com.raytheon.uf.common.datadelivery.registry.handlers.ISubscriptionHandler;
import com.raytheon.uf.common.datadelivery.service.IGroupDefinitionService;
import com.raytheon.uf.common.datadelivery.service.ISubscriptionNotificationService;
import com.raytheon.uf.common.registry.handler.RegistryHandlerException;
import com.raytheon.uf.common.util.CollectionUtil;
import com.raytheon.uf.edex.auth.req.AbstractPrivilegedRequestHandler;
@ -45,6 +44,7 @@ import com.raytheon.uf.edex.auth.resp.AuthorizationResponse;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 18, 2013 1441 djohnson Initial creation
* Nov 12, 2013 2506 bgonzale Refactored out notification service.
*
* </pre>
*
@ -55,17 +55,13 @@ import com.raytheon.uf.edex.auth.resp.AuthorizationResponse;
public class GroupDefinitionServiceHandler extends
AbstractPrivilegedRequestHandler<GroupDefinitionServiceRequest> {
private final ISubscriptionNotificationService notificationService;
/**
* Constructor.
*
* @param notificationService
* the subscription notification service
*/
public GroupDefinitionServiceHandler(
ISubscriptionNotificationService notificationService) {
this.notificationService = notificationService;
public GroupDefinitionServiceHandler() {
}
/**
@ -104,14 +100,6 @@ public class GroupDefinitionServiceHandler extends
for (Subscription sub : subsForGroup) {
sub.setGroupName(GroupDefinition.NO_GROUP);
handler.update(sub);
// TODO: Would be nice to use a subset of the
// SubscriptionService functionality here so we didn't have to
// manually send the subscription updated notification
String username = user != null ? user.uniqueId().toString()
: "none";
notificationService.sendUpdatedSubscriptionNotification(sub,
username);
}
}

View file

@ -65,6 +65,7 @@ import com.raytheon.uf.common.registry.event.InsertRegistryEvent;
import com.raytheon.uf.common.registry.event.RegistryEvent.Action;
import com.raytheon.uf.common.registry.event.RegistryStatisticsEvent;
import com.raytheon.uf.common.registry.event.RemoveRegistryEvent;
import com.raytheon.uf.common.registry.event.UpdateRegistryEvent;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.time.util.TimeUtil;
@ -103,6 +104,8 @@ import com.raytheon.uf.edex.registry.ebxml.util.xpath.RegistryXPathProcessor;
* 8/1/2013 1693 bphillip Added check references and refactored submit objects to conform to EBXML 4.0 spec
* 9/11/2013 2254 bphillip Cleaned up creation of auditable events
* 10/23/2013 1538 bphillip Changed QueryRequest constructor call
* Nov 08, 2013 2506 bgonzale Added RegistryObjectType to RemoveRegistryEvent.
* Separate update from create notifications.
*
*
* </pre>
@ -300,7 +303,7 @@ public class LifecycleManagerImpl implements LifecycleManager {
if (objectType != null
&& !objectType.equals(RegistryObjectTypes.ASSOCIATION)) {
RemoveRegistryEvent event = new RemoveRegistryEvent(
request.getUsername(), obj.getId());
request.getUsername(), obj.getId(), obj);
event.setAction(Action.DELETE);
event.setLid(obj.getLid());
event.setObjectType(objectType);
@ -485,10 +488,9 @@ public class LifecycleManagerImpl implements LifecycleManager {
// gives a close estimate to amount taken on each object
// individually, this will be millis in most cases, hopefully
long avTimePerRecord = 0;
if (!objs.isEmpty()) {
avTimePerRecord = totalTime / objs.size();
for (RegistryObjectType obj : objs) {
long avTimePerRecord = objs.isEmpty() ? 0 : totalTime / objs.size();
if (!objsCreated.isEmpty()) {
for (RegistryObjectType obj : objsCreated) {
EventBus.publish(new InsertRegistryEvent(obj.getId(), obj
.getLid(), obj.getObjectType()));
EventBus.publish(new RegistryStatisticsEvent(obj
@ -496,6 +498,15 @@ public class LifecycleManagerImpl implements LifecycleManager {
avTimePerRecord));
}
}
if (!objsUpdated.isEmpty()) {
for (RegistryObjectType obj : objsUpdated) {
EventBus.publish(new UpdateRegistryEvent(obj.getId(), obj
.getLid(), obj.getObjectType()));
EventBus.publish(new RegistryStatisticsEvent(obj
.getObjectType(), obj.getStatus(), obj.getOwner(),
avTimePerRecord));
}
}
return response;
}

View file

@ -107,6 +107,7 @@ import com.raytheon.uf.edex.datadelivery.retrieval.RetrievalManagerNotifyEvent;
* Sept 25, 2013 1797 dhladky separated time from gridded time
* Oct 10, 2013 1797 bgonzale Refactored registry Time objects.
* Oct 21, 2013 2292 mpduff Implement multiple data types
* Nov 08, 2013 2506 bgonzale Added RegistryObjectType to RemoveRegistryEvent.
*
* </pre>
*
@ -1000,7 +1001,7 @@ public class BandwidthManagerIntTest extends AbstractWfoBandwidthManagerIntTest
private void sendDeletedSubscriptionEvent(Subscription subscription) {
RemoveRegistryEvent event = new RemoveRegistryEvent(
subscription.getOwner(), subscription.getId());
subscription.getOwner(), subscription.getId(), null);
event.setObjectType(DataDeliveryRegistryObjectTypes.SITE_SUBSCRIPTION);
bandwidthManager.subscriptionRemoved(event);
}

View file

@ -23,11 +23,6 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.emptyCollectionOf;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.rmi.RemoteException;
@ -40,7 +35,6 @@ import com.raytheon.uf.common.datadelivery.registry.SiteSubscription;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.datadelivery.registry.SubscriptionBuilder;
import com.raytheon.uf.common.datadelivery.service.GroupDefinitionService;
import com.raytheon.uf.common.datadelivery.service.ISubscriptionNotificationService;
import com.raytheon.uf.common.registry.handler.RegistryHandlerException;
import com.raytheon.uf.common.registry.handler.RegistryObjectHandlersUtil;
import com.raytheon.uf.edex.datadelivery.service.services.GroupDefinitionServiceHandler;
@ -58,6 +52,7 @@ import com.raytheon.uf.edex.datadelivery.service.services.GroupDefinitionService
* Feb 26, 2013 1643 djohnson Change exception type thrown.
* Mar 28, 2013 1841 djohnson Subscription is now UserSubscription.
* Jun 24, 2013 2106 djohnson RegistryManager is gone.
* Nov 12, 2013 2506 bgonzale Refactored out notification service.
*
* </pre>
*
@ -73,14 +68,11 @@ public class GroupDefinitionServiceTest {
private IGroupDefinitionHandler groupHandler;
private final ISubscriptionNotificationService subscriptionNotificationService = mock(ISubscriptionNotificationService.class);
private final GroupDefinitionService service = new GroupDefinitionService() {
@Override
protected Object getResponseFromServer(
GroupDefinitionServiceRequest request) throws Exception {
return new GroupDefinitionServiceHandler(
subscriptionNotificationService).handleRequest(request);
return new GroupDefinitionServiceHandler().handleRequest(request);
}
};
@ -116,16 +108,6 @@ public class GroupDefinitionServiceTest {
is(emptyCollectionOf(Subscription.class)));
}
@Test
public void deletingAGroupNotifiesOfSubscriptionUpdates()
throws RemoteException, RegistryHandlerException {
service.deleteGroupDefinition(group);
verify(subscriptionNotificationService, times(2))
.sendUpdatedSubscriptionNotification(any(Subscription.class),
anyString());
}
@Test
public void deletingAGroupDeletesTheGroup() throws RemoteException,
RegistryHandlerException {