use of com.ctrip.framework.apollo.biz.entity.ReleaseMessage in project apollo by ctripcorp.
the class ReleaseMessageService method findLatestReleaseMessagesGroupByMessages.
public List<ReleaseMessage> findLatestReleaseMessagesGroupByMessages(Collection<String> messages) {
if (CollectionUtils.isEmpty(messages)) {
return Collections.emptyList();
}
List<Object[]> result = releaseMessageRepository.findLatestReleaseMessagesGroupByMessages(messages);
List<ReleaseMessage> releaseMessages = Lists.newArrayList();
for (Object[] o : result) {
try {
ReleaseMessage releaseMessage = new ReleaseMessage((String) o[0]);
releaseMessage.setId((Long) o[1]);
releaseMessages.add(releaseMessage);
} catch (Exception ex) {
Tracer.logError("Parsing LatestReleaseMessagesGroupByMessages failed", ex);
}
}
return releaseMessages;
}
use of com.ctrip.framework.apollo.biz.entity.ReleaseMessage in project apollo by ctripcorp.
the class GrayReleaseRulesHolderTest method assembleReleaseMessage.
private ReleaseMessage assembleReleaseMessage(String appId, String clusterName, String namespaceName) {
String message = STRING_JOINER.join(appId, clusterName, namespaceName);
ReleaseMessage releaseMessage = new ReleaseMessage(message);
return releaseMessage;
}
use of com.ctrip.framework.apollo.biz.entity.ReleaseMessage in project apollo by ctripcorp.
the class ConfigServiceWithCache method initialize.
@PostConstruct
void initialize() {
configCache = CacheBuilder.newBuilder().expireAfterAccess(DEFAULT_EXPIRED_AFTER_ACCESS_IN_MINUTES, TimeUnit.MINUTES).build(new CacheLoader<String, ConfigCacheEntry>() {
@Override
public ConfigCacheEntry load(String key) throws Exception {
List<String> namespaceInfo = STRING_SPLITTER.splitToList(key);
if (namespaceInfo.size() != 3) {
Tracer.logError(new IllegalArgumentException(String.format("Invalid cache load key %s", key)));
return nullConfigCacheEntry;
}
Transaction transaction = Tracer.newTransaction(TRACER_EVENT_CACHE_LOAD, key);
try {
ReleaseMessage latestReleaseMessage = releaseMessageService.findLatestReleaseMessageForMessages(Lists.newArrayList(key));
Release latestRelease = releaseService.findLatestActiveRelease(namespaceInfo.get(0), namespaceInfo.get(1), namespaceInfo.get(2));
transaction.setStatus(Transaction.SUCCESS);
long notificationId = latestReleaseMessage == null ? ConfigConsts.NOTIFICATION_ID_PLACEHOLDER : latestReleaseMessage.getId();
if (notificationId == ConfigConsts.NOTIFICATION_ID_PLACEHOLDER && latestRelease == null) {
return nullConfigCacheEntry;
}
return new ConfigCacheEntry(notificationId, latestRelease);
} catch (Throwable ex) {
transaction.setStatus(ex);
throw ex;
} finally {
transaction.complete();
}
}
});
configIdCache = CacheBuilder.newBuilder().expireAfterAccess(DEFAULT_EXPIRED_AFTER_ACCESS_IN_MINUTES, TimeUnit.MINUTES).build(new CacheLoader<Long, Optional<Release>>() {
@Override
public Optional<Release> load(Long key) throws Exception {
Transaction transaction = Tracer.newTransaction(TRACER_EVENT_CACHE_LOAD_ID, String.valueOf(key));
try {
Release release = releaseService.findActiveOne(key);
transaction.setStatus(Transaction.SUCCESS);
return Optional.ofNullable(release);
} catch (Throwable ex) {
transaction.setStatus(ex);
throw ex;
} finally {
transaction.complete();
}
}
});
}
use of com.ctrip.framework.apollo.biz.entity.ReleaseMessage in project apollo by ctripcorp.
the class NotificationControllerTest method testPollNotificationWithDefaultNamespaceWithNotificationIdOutDated.
@Test
public void testPollNotificationWithDefaultNamespaceWithNotificationIdOutDated() throws Exception {
long notificationId = someNotificationId + 1;
ReleaseMessage someReleaseMessage = mock(ReleaseMessage.class);
String someWatchKey = "someKey";
Set<String> watchKeys = Sets.newHashSet(someWatchKey);
when(watchKeysUtil.assembleAllWatchKeys(someAppId, someCluster, defaultNamespace, someDataCenter)).thenReturn(watchKeys);
when(someReleaseMessage.getId()).thenReturn(notificationId);
when(releaseMessageService.findLatestReleaseMessageForMessages(watchKeys)).thenReturn(someReleaseMessage);
DeferredResult<ResponseEntity<ApolloConfigNotification>> deferredResult = controller.pollNotification(someAppId, someCluster, defaultNamespace, someDataCenter, someNotificationId, someClientIp);
ResponseEntity<ApolloConfigNotification> result = (ResponseEntity<ApolloConfigNotification>) deferredResult.getResult();
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals(defaultNamespace, result.getBody().getNamespaceName());
assertEquals(notificationId, result.getBody().getNotificationId());
}
use of com.ctrip.framework.apollo.biz.entity.ReleaseMessage in project apollo by ctripcorp.
the class NotificationControllerTest method testPollNotificationWithDefaultNamespaceAndHandleMessage.
@Test
public void testPollNotificationWithDefaultNamespaceAndHandleMessage() throws Exception {
String someWatchKey = "someKey";
String anotherWatchKey = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR).join(someAppId, someCluster, defaultNamespace);
Set<String> watchKeys = Sets.newHashSet(someWatchKey, anotherWatchKey);
when(watchKeysUtil.assembleAllWatchKeys(someAppId, someCluster, defaultNamespace, someDataCenter)).thenReturn(watchKeys);
DeferredResult<ResponseEntity<ApolloConfigNotification>> deferredResult = controller.pollNotification(someAppId, someCluster, defaultNamespace, someDataCenter, someNotificationId, someClientIp);
long someId = 1;
ReleaseMessage someReleaseMessage = new ReleaseMessage(anotherWatchKey);
someReleaseMessage.setId(someId);
controller.handleMessage(someReleaseMessage, Topics.APOLLO_RELEASE_TOPIC);
ResponseEntity<ApolloConfigNotification> response = (ResponseEntity<ApolloConfigNotification>) deferredResult.getResult();
ApolloConfigNotification notification = response.getBody();
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(defaultNamespace, notification.getNamespaceName());
assertEquals(someId, notification.getNotificationId());
}
Aggregations