use of com.sequenceiq.cloudbreak.domain.SmartSenseSubscription in project cloudbreak by hortonworks.
the class SmartSenseSubscriptionService method createSubscriptionFromIdentityUser.
@Nullable
private SmartSenseSubscription createSubscriptionFromIdentityUser(IdentityUser cbUser) {
SmartSenseSubscription newSubscription = null;
if (!StringUtils.isEmpty(defaultSmartsenseId)) {
LOGGER.info("Generating default SmartSense subscription");
newSubscription = new SmartSenseSubscription();
newSubscription.setSubscriptionId(defaultSmartsenseId);
newSubscription.setAccount(cbUser.getAccount());
newSubscription.setOwner(cbUser.getUserId());
newSubscription.setPublicInAccount(true);
repository.save(newSubscription);
}
return newSubscription;
}
use of com.sequenceiq.cloudbreak.domain.SmartSenseSubscription in project cloudbreak by hortonworks.
the class SmartSenseSubscriptionToSmartSenseSubscriptionJsonConverterTest method convertWithExampleDataSource.
@Test
public void convertWithExampleDataSource() {
SmartSenseSubscription source = mock(SmartSenseSubscription.class);
Long id = Long.MAX_VALUE;
String subscriptionId = "A-99900000-C-00000000";
String owner = "Johnny Bravo";
String account = "awesomeAccount";
when(source.getId()).thenReturn(id);
when(source.getSubscriptionId()).thenReturn(subscriptionId);
when(source.getOwner()).thenReturn(owner);
when(source.getAccount()).thenReturn(account);
when(source.isPublicInAccount()).thenReturn(true);
SmartSenseSubscriptionJson json = underTest.convert(source);
assertNotNull("The returning SmartSenseSubscriptionJson should not be null.", json);
assertEquals("The output ID from the json is not match for the expected.", id, json.getId());
assertEquals("The output subscription ID from the json is not match for the expected.", subscriptionId, json.getSubscriptionId());
assertEquals("The output owner from the json is not match for the expected.", owner, json.getOwner());
assertEquals("The output account from the json is not match for the expected.", account, json.getAccount());
assertEquals("The output public account value from the json is not match for the expected.", true, json.isPublicInAccount());
assertEquals("The autoGenerated value from the json is not match for the expected.", true, json.isAutoGenerated());
}
use of com.sequenceiq.cloudbreak.domain.SmartSenseSubscription in project cloudbreak by hortonworks.
the class SmartSenseSubscriptionControllerTest method testGetWhenSmartSenseSubscriptionIsValid.
@Test
public void testGetWhenSmartSenseSubscriptionIsValid() {
SmartSenseSubscription subscription = createSmartSenseSubscription();
when(authenticatedUserService.getCbUser()).thenReturn(identityUser);
when(smartSenseSubService.getDefaultForUser(identityUser)).thenReturn(subscription);
when(toJsonConverter.convert(subscription)).thenCallRealMethod();
SmartSenseSubscriptionJson json = underTest.get();
Assert.assertNotNull(json);
verify(authenticatedUserService, times(1)).getCbUser();
verify(smartSenseSubService, times(1)).getDefaultForUser(identityUser);
verify(toJsonConverter, times(1)).convert(subscription);
}
use of com.sequenceiq.cloudbreak.domain.SmartSenseSubscription in project cloudbreak by hortonworks.
the class FlexUsageGenerator method getFlexUsageControllerJson.
private FlexUsageControllerJson getFlexUsageControllerJson(List<CloudbreakUsage> usages, Optional<CloudbreakUsage> aUsage) {
Optional<SmartSenseSubscription> smartSenseSubscriptionOptional = smartSenseSubscriptionService.getDefault();
FlexUsageControllerJson controllerJson = new FlexUsageControllerJson();
String parentUuid = cloudbreakNodeConfig.getInstanceUUID();
controllerJson.setGuid(parentUuid);
controllerJson.setInstanceId(parentUuid);
controllerJson.setProvider(cbInstanceProvider);
controllerJson.setRegion(cbInstanceRegion);
aUsage.ifPresent(cloudbreakUsage -> controllerJson.setUserName(getUserEmail(cloudbreakUsage)));
smartSenseSubscriptionOptional.ifPresent(smartSenseSubscription -> controllerJson.setSmartSenseId(smartSenseSubscription.getSubscriptionId()));
return controllerJson;
}
Aggregations