Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
7bc15c3
api,server,ui: weebhoks feature
shwstppr Jan 16, 2024
8442350
fix
shwstppr Feb 12, 2024
a69192c
fix
shwstppr Feb 13, 2024
af388a0
changes
shwstppr Feb 13, 2024
d17ded0
registry of message busses
DaanHoogland Sep 21, 2023
fa874ed
test bus
shwstppr Feb 13, 2024
75a56f7
refactor
shwstppr Feb 13, 2024
0c2a5c7
test
shwstppr Feb 13, 2024
d82863b
fix and refactor
shwstppr Feb 13, 2024
d273921
Merge branch 'message-buses' into add-feature-webhooks
shwstppr Feb 13, 2024
f74ffee
changes for webhook dispatch history
shwstppr Feb 14, 2024
a06b8f6
changes, initial ui
shwstppr Feb 14, 2024
d2c3d40
improvements
shwstppr Feb 15, 2024
23621eb
changes for account webhook cleanup
shwstppr Feb 16, 2024
d4bd086
fix remaining event bus usage
shwstppr Feb 16, 2024
3821fac
changes for testing webhook dispatch
shwstppr Feb 16, 2024
e8f4c1c
wip
shwstppr Feb 16, 2024
291ead5
fix test
shwstppr Feb 16, 2024
8a88be7
make element
shwstppr Feb 19, 2024
1072909
missing
shwstppr Feb 19, 2024
4952ac2
Merge remote-tracking branch 'apache/main' into add-feature-webhooks
shwstppr Feb 19, 2024
a1a10ec
buid fix
shwstppr Feb 19, 2024
cf2eb1f
fix lint
shwstppr Feb 19, 2024
e7911a8
Merge remote-tracking branch 'apache/main' into add-feature-webhooks
shwstppr Feb 19, 2024
684f6d6
changes for project delete check
shwstppr Feb 19, 2024
2d097dd
fix
shwstppr Feb 19, 2024
02a1196
add collapse in create
shwstppr Feb 19, 2024
30f4c48
ui fix and refactor for eventditributor publish
shwstppr Feb 19, 2024
a89a428
update org.json and add json validation
shwstppr Feb 19, 2024
2debb85
schema fixes
shwstppr Feb 20, 2024
c7caf30
wordings
shwstppr Feb 21, 2024
5c04e87
ui: improve progress button
shwstppr Feb 21, 2024
e4e5ff0
ui improvements
shwstppr Feb 23, 2024
05f0590
remove unrelated change
shwstppr Feb 23, 2024
ac651e2
search and count
shwstppr Feb 23, 2024
3e3ca82
add payloadurl in info
shwstppr Feb 23, 2024
8dc662d
Merge branch 'main' into add-feature-webhooks
DaanHoogland Feb 26, 2024
85059c5
positive progress
shwstppr Feb 26, 2024
10a5e32
fix hmac key
shwstppr Feb 26, 2024
5cde6e8
create webhook form fixes
shwstppr Feb 26, 2024
819eb47
refactor, address feedback
shwstppr Feb 27, 2024
c70df5c
indentation
shwstppr Feb 27, 2024
64b52bf
fix filters
shwstppr Feb 28, 2024
07eae2f
remove test eventbus
shwstppr Feb 28, 2024
85edf96
default scope be Local
shwstppr Feb 28, 2024
fcd161d
add lifecycle smoke test
shwstppr Feb 28, 2024
dd522ca
add test for webhook deliveries
shwstppr Feb 28, 2024
7bc36ae
refactor
shwstppr Feb 29, 2024
3a739d4
fix lint
shwstppr Feb 29, 2024
27e683e
refactor - losgs and others
shwstppr Mar 4, 2024
38f3adc
unit tests
shwstppr Mar 4, 2024
31d85ef
Merge remote-tracking branch 'apache/main' into add-feature-webhooks
shwstppr Mar 4, 2024
2a4226a
fix lint
shwstppr Mar 4, 2024
dc79745
build fix
shwstppr Mar 4, 2024
e40d7ac
smoke test fix, log refactor
shwstppr Mar 5, 2024
398bc10
get bean from all components
shwstppr Mar 6, 2024
980dfb5
ui: missing label
shwstppr Mar 7, 2024
256f7a6
Merge remote-tracking branch 'apache/main' into add-feature-webhooks
shwstppr Mar 8, 2024
52b4fc3
address review comments
shwstppr Mar 14, 2024
4353a69
Merge remote-tracking branch 'apache/main' into add-feature-webhooks
shwstppr Mar 14, 2024
b054e0c
Merge remote-tracking branch 'apache/main' into add-feature-webhooks
shwstppr Apr 2, 2024
6a3949a
add some more tests
shwstppr Apr 8, 2024
ca83c0a
lint
shwstppr Apr 8, 2024
623496c
rename setting
shwstppr Apr 8, 2024
9bd4f1e
upgrade: move 4.19.0->4.20.0 to 4.19.1->4.20.0
weizhouapache Apr 8, 2024
426c120
fix test delivery layout
shwstppr Apr 15, 2024
ddadf22
fix webhook secret display
shwstppr Apr 15, 2024
54ad344
add http to payloadurl when no scheme
shwstppr Apr 15, 2024
9956375
allow removing secretkey for webhook
shwstppr Apr 15, 2024
8c5f2a6
fix update sslverification
shwstppr Apr 18, 2024
8a9039a
disallow same payload url for same account
shwstppr Apr 18, 2024
5c7b33e
fix delivery with url w/o scheme
shwstppr Apr 18, 2024
4f245b8
api: listApis should return params based on caller
shwstppr Apr 24, 2024
2748743
Merge branch 'main' into add-feature-webhooks
shwstppr Apr 29, 2024
e26432b
wip changes
shwstppr Apr 29, 2024
ef00a8c
Update engine/schema/src/main/resources/META-INF/db/schema-41900to420…
shwstppr Apr 30, 2024
8e1d53e
remove unique constraint for now
shwstppr Apr 30, 2024
3c9cca9
fixes
shwstppr May 1, 2024
7f54693
ui: add option to delete multiple deliveries
shwstppr May 1, 2024
21e051e
add filter for deliveries, delete api start/endtime support
shwstppr May 5, 2024
0497c5c
do not throw error when no deliveries removed
shwstppr May 5, 2024
36d0cad
Merge branch 'main' into 4.20-fix-upgrade-path-from-4191
weizhouapache May 7, 2024
67498fc
ui: fix deliveries table column sorting, time filter cancel
shwstppr May 7, 2024
12baadc
Merge remote-tracking branch 'apache/main' into add-feature-webhooks
shwstppr May 28, 2024
a75e138
Merge remote-tracking branch 'wei/4.20-fix-upgrade-path-from-4191' in…
shwstppr May 29, 2024
c67bf4c
Merge remote-tracking branch 'apache/main' into add-feature-webhooks
shwstppr Jun 3, 2024
757d113
remove isDebugEnabled wrapping
shwstppr Jun 5, 2024
4e72012
Merge remote-tracking branch 'apache/main' into add-feature-webhooks
shwstppr Jun 7, 2024
b15bba5
merge fix
shwstppr Jun 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix remaining event bus usage
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
  • Loading branch information
shwstppr committed Feb 16, 2024
commit d4bd0865cf13f37252400327b9fad0edd7d592c5
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.apache.commons.collections.MapUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;

import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.framework.events.Event;
import org.apache.cloudstack.framework.events.EventBus;
import org.apache.cloudstack.framework.events.EventBusException;
import org.apache.cloudstack.framework.events.EventDistributor;
import org.apache.commons.collections.MapUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;

import com.cloud.dc.DataCenterVO;
import com.cloud.dc.dao.DataCenterDao;
Expand All @@ -49,6 +48,7 @@ public class UsageEventUtils {
private static final Logger s_logger = Logger.getLogger(UsageEventUtils.class);
protected static EventBus s_eventBus = null;
protected static ConfigurationDao s_configDao;
private static EventDistributor eventDistributor;

@Inject
UsageEventDao usageEventDao;
Expand Down Expand Up @@ -206,9 +206,9 @@ private static void publishUsageEvent(String usageEventType, Long accountId, Lon
if( !configValue)
return;
try {
s_eventBus = ComponentContext.getComponent(EventBus.class);
eventDistributor = ComponentContext.getComponent(EventDistributor.class);
} catch (NoSuchBeanDefinitionException nbe) {
return; // no provider is configured to provide events bus, so just return
return; // no provider is configured to provide events distributor, so just return
}

Account account = s_accountDao.findById(accountId);
Expand Down Expand Up @@ -237,11 +237,7 @@ private static void publishUsageEvent(String usageEventType, Long accountId, Lon

event.setDescription(eventDescription);

try {
s_eventBus.publish(event);
} catch (EventBusException e) {
s_logger.warn("Failed to publish usage event on the event bus.");
}
eventDistributor.publish(event);
}

static final String Name = "management-server";
Expand Down
23 changes: 12 additions & 11 deletions server/src/main/java/com/cloud/event/AlertGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.framework.events.EventBusException;
import org.apache.cloudstack.framework.events.EventDistributor;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.stereotype.Component;

import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.framework.events.EventBus;
import org.apache.cloudstack.framework.events.EventBusException;

import com.cloud.configuration.Config;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
Expand All @@ -47,8 +47,8 @@ public class AlertGenerator {
private static final Logger s_logger = Logger.getLogger(AlertGenerator.class);
private static DataCenterDao s_dcDao;
private static HostPodDao s_podDao;
protected static EventBus s_eventBus = null;
protected static ConfigurationDao s_configDao;
protected static EventDistributor eventDistributor;

@Inject
DataCenterDao dcDao;
Expand All @@ -75,9 +75,9 @@ public static void publishAlertOnEventBus(String alertType, long dataCenterId, L
if(!configValue)
return;
try {
s_eventBus = ComponentContext.getComponent(EventBus.class);
eventDistributor = ComponentContext.getComponent(EventDistributor.class);
} catch (NoSuchBeanDefinitionException nbe) {
return; // no provider is configured to provide events bus, so just return
return; // no provider is configured to provide events distributor, so just return
}

org.apache.cloudstack.framework.events.Event event =
Expand Down Expand Up @@ -106,10 +106,11 @@ public static void publishAlertOnEventBus(String alertType, long dataCenterId, L

event.setDescription(eventDescription);

try {
s_eventBus.publish(event);
} catch (EventBusException e) {
s_logger.warn("Failed to publish alert on the event bus.");

List<EventBusException> exceptions = eventDistributor.publish(event);
for (EventBusException ex : exceptions) {
String errMsg = "Failed to publish event.";
s_logger.warn(errMsg, ex);
}
}
}
11 changes: 5 additions & 6 deletions server/src/main/java/com/cloud/vm/UserVmStateListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.framework.events.EventDistributor;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;

public class UserVmStateListener implements StateListener<State, VirtualMachine.Event, VirtualMachine> {

Expand All @@ -66,10 +67,6 @@ public UserVmStateListener(UsageEventDao usageEventDao, NetworkDao networkDao, N
this._configDao = configDao;
}

public void setEventDistributor(EventDistributor eventDistributor) {
this.eventDistributor = eventDistributor;
}

@Override
public boolean preStateTransitionEvent(State oldState, Event event, State newState, VirtualMachine vo, boolean status, Object opaque) {
pubishOnEventBus(event.name(), "preStateTransitionEvent", vo, oldState, newState);
Expand Down Expand Up @@ -127,8 +124,10 @@ private void pubishOnEventBus(String event, String status, VirtualMachine vo, Vi
boolean configValue = Boolean.parseBoolean(value);
if(!configValue)
return;
if (eventDistributor == null) {
setEventDistributor(ComponentContext.getComponent(EventDistributor.class));
try {
eventDistributor = ComponentContext.getComponent(EventDistributor.class);
} catch (NoSuchBeanDefinitionException nbe) {
return; // no provider is configured to provide events distributor, so just return
}

String resourceName = getEntityFromClassName(VirtualMachine.class.getName());
Expand Down
19 changes: 8 additions & 11 deletions server/src/test/java/com/cloud/event/ActionEventUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.framework.events.Event;
import org.apache.cloudstack.framework.events.EventBus;
import org.apache.cloudstack.framework.events.EventDistributor;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -97,7 +97,7 @@ public class ActionEventUtilsTest {
protected ConfigurationDao configDao;

@Mock
protected EventBus eventBus;
protected EventDistributor eventDistributor;

private AccountVO account;
private UserVO user;
Expand Down Expand Up @@ -149,7 +149,7 @@ public void setupCommonMocks() throws Exception {
//Some basic mocks.
Mockito.when(configDao.getValue(Config.PublishActionEvent.key())).thenReturn("true");
componentContextMocked = Mockito.mockStatic(ComponentContext.class);
componentContextMocked.when(() -> ComponentContext.getComponent(EventBus.class)).thenReturn(eventBus);
componentContextMocked.when(() -> ComponentContext.getComponent(EventDistributor.class)).thenReturn(eventDistributor);

//Needed for persist to actually set an ID that can be returned from the ActionEventUtils
//methods.
Expand All @@ -166,14 +166,11 @@ public EventVO answer(InvocationOnMock invocation) throws Throwable {
});

//Needed to record events published on the bus.
Mockito.doAnswer(new Answer<Void>() {
@Override public Void answer(InvocationOnMock invocation) throws Throwable {
Event event = (Event)invocation.getArguments()[0];
publishedEvents.add(event);
return null;
}

}).when(eventBus).publish(Mockito.any(Event.class));
Mockito.doAnswer((Answer<Void>) invocation -> {
Event event = (Event)invocation.getArguments()[0];
publishedEvents.add(event);
return null;
}).when(eventDistributor).publish(Mockito.any(Event.class));

account = new AccountVO("testaccount", 1L, "networkdomain", Account.Type.NORMAL, "uuid");
account.setId(ACCOUNT_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@

package com.cloud.template;

import com.cloud.dc.DataCenterVO;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.event.EventTypes;
import com.cloud.event.UsageEventUtils;
import com.cloud.event.UsageEventVO;
import com.cloud.event.dao.UsageEventDao;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.org.Grouping;
import com.cloud.server.StatsCollector;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.TemplateProfile;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.dao.VMTemplateZoneDao;
import com.cloud.test.TestAppender;
import com.cloud.user.AccountVO;
import com.cloud.user.ResourceLimitService;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.exception.CloudRuntimeException;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyLong;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.regex.Pattern;

import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
Expand All @@ -47,8 +47,8 @@
import org.apache.cloudstack.framework.async.AsyncCallFuture;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.framework.events.Event;
import org.apache.cloudstack.framework.events.EventBus;
import org.apache.cloudstack.framework.events.EventBusException;
import org.apache.cloudstack.framework.events.EventDistributor;
import org.apache.cloudstack.framework.messagebus.MessageBus;
import org.apache.cloudstack.secstorage.heuristics.HeuristicType;
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
Expand All @@ -71,30 +71,31 @@
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.regex.Pattern;

import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyLong;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.event.EventTypes;
import com.cloud.event.UsageEventUtils;
import com.cloud.event.UsageEventVO;
import com.cloud.event.dao.UsageEventDao;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.org.Grouping;
import com.cloud.server.StatsCollector;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.TemplateProfile;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.dao.VMTemplateZoneDao;
import com.cloud.test.TestAppender;
import com.cloud.user.AccountVO;
import com.cloud.user.ResourceLimitService;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.exception.CloudRuntimeException;

@RunWith(MockitoJUnitRunner.class)
public class HypervisorTemplateAdapterTest {
@Mock
EventBus _bus;
EventDistributor eventDistributor;
List<Event> events = new ArrayList<>();

@Mock
Expand Down Expand Up @@ -176,16 +177,14 @@ public UsageEventUtils setupUsageUtils() throws EventBusException {

Mockito.when(_usageEventDao.listAll()).thenReturn(usageEvents);

doAnswer(new Answer<Void>() {
@Override public Void answer(InvocationOnMock invocation) throws Throwable {
Event event = (Event)invocation.getArguments()[0];
events.add(event);
return null;
}
}).when(_bus).publish(any(Event.class));
doAnswer((Answer<Void>) invocation -> {
Event event = (Event)invocation.getArguments()[0];
events.add(event);
return null;
}).when(eventDistributor).publish(any(Event.class));

componentContextMocked = Mockito.mockStatic(ComponentContext.class);
when(ComponentContext.getComponent(eq(EventBus.class))).thenReturn(_bus);
when(ComponentContext.getComponent(eq(EventDistributor.class))).thenReturn(eventDistributor);

UsageEventUtils utils = new UsageEventUtils();

Expand Down