本文整理汇总了Java中org.ligoj.app.model.Subscription类的典型用法代码示例。如果您正苦于以下问题:Java Subscription类的具体用法?Java Subscription怎么用?Java Subscription使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Subscription类属于org.ligoj.app.model包,在下文中一共展示了Subscription类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getActivities
import org.ligoj.app.model.Subscription; //导入依赖的package包/类
/**
* Return activities associates by given a subscription.
*/
private ActivitiesComputations getActivities(final int subscription, final boolean global) throws Exception {
// Get users from other LDAP subscriptions
final Subscription main = subscriptionResource.checkVisibleSubscription(subscription);
final List<Subscription> subscriptions = subscriptionRepository.findAllOnSameProject(subscription);
final Set<UserOrg> users = global ? getMembersOfAllSubscription(subscriptions) : getMembersOfSubscription(main);
// Get the activities from each subscription of the same project,
final ActivitiesComputations result = new ActivitiesComputations();
result.setUsers(users);
final List<String> userLogins = users.stream().map(UserOrg::getId).collect(Collectors.toList());
final Map<String, Map<String, Activity>> activities = new HashMap<>();
final Set<INamableBean<String>> nodes = new LinkedHashSet<>();
for (final Subscription projectSubscription : subscriptions) {
final ServicePlugin resource = servicePluginLocator.getResource(projectSubscription.getNode().getId());
addSubscriptionActivities(activities, userLogins, projectSubscription, resource, nodes);
}
result.setNodes(nodes);
result.setActivities(activities);
return result;
}
示例2: deleteNoMoreGroup
import org.ligoj.app.model.Subscription; //导入依赖的package包/类
@Test
public void deleteNoMoreGroup() throws Exception {
final Subscription subscription = new Subscription();
subscription.setProject(projectRepository.findByName("gStack"));
subscription.setNode(nodeRepository.findOneExpected("service:id:ldap:dig"));
em.persist(subscription);
// Attach the wrong group
setGroup(subscription, "any");
initSpringSecurityContext("fdaugan");
final Map<String, String> parameters = subscriptionResource.getParametersNoCheck(subscription.getId());
Assert.assertFalse(resource.checkSubscriptionStatus(parameters).getStatus().isUp());
resource.delete(subscription.getId(), true);
em.flush();
em.clear();
Assert.assertFalse(resource.checkSubscriptionStatus(parameters).getStatus().isUp());
subscriptionResource.getParametersNoCheck(subscription.getId()).isEmpty();
}
示例3: createAlreadyExist
import org.ligoj.app.model.Subscription; //导入依赖的package包/类
/**
* Create a group with the same name.
*/
@Test
public void createAlreadyExist() throws Exception {
thrown.expect(ValidationJsonException.class);
thrown.expect(MatcherUtil.validationMatcher(IdentityResource.PARAMETER_GROUP, "already-exist"));
// Attach the new group
final Subscription subscription = em.find(Subscription.class, this.subscription);
final Subscription subscription2 = new Subscription();
subscription2.setProject(newProject("sea-octopus"));
subscription2.setNode(subscription.getNode());
em.persist(subscription2);
// Add parameters
setGroup(subscription2, "sea-octopus");
setOu(subscription2, "sea");
basicCreate(subscription2);
}
示例4: createNotCompliantGroupForProject
import org.ligoj.app.model.Subscription; //导入依赖的package包/类
/**
* Create a group for an existing project, but without reusing the pkey of this project.
*/
@Test
public void createNotCompliantGroupForProject() throws Exception {
thrown.expect(ValidationJsonException.class);
thrown.expect(MatcherUtil.validationMatcher(IdentityResource.PARAMETER_GROUP, "pattern"));
// Preconditions
Assert.assertNotNull(getGroup().findById("sea-octopus"));
Assert.assertNull(getGroup().findById("sea-octopusZZ"));
Assert.assertNotNull(projectCustomerLdapRepository.findAll("ou=project,dc=sample,dc=com").get("sea"));
// Attach the new group
final Subscription subscription = em.find(Subscription.class, this.subscription);
final Subscription subscription2 = new Subscription();
subscription2.setProject(newProject("sea-octopus"));
subscription2.setNode(subscription.getNode());
em.persist(subscription2);
// Add parameters
setGroup(subscription2, "sea-octopusZZ");
setOu(subscription2, "sea");
// Invoke link for an already linked entity, since for now
basicCreate(subscription2);
}
示例5: createNotCompliantGroupForProject2
import org.ligoj.app.model.Subscription; //导入依赖的package包/类
/**
* Create a group for an existing project, reusing the pkey of this project and without suffix.
*/
@Test
public void createNotCompliantGroupForProject2() throws Exception {
thrown.expect(ValidationJsonException.class);
thrown.expect(MatcherUtil.validationMatcher(IdentityResource.PARAMETER_GROUP, "pattern"));
// Preconditions
Assert.assertNotNull(getGroup().findById("sea-octopus"));
Assert.assertNull(getGroup().findById("sea-octopus-"));
Assert.assertNotNull(projectCustomerLdapRepository.findAll("ou=project,dc=sample,dc=com").get("sea"));
// Attach the new group
final Subscription subscription = em.find(Subscription.class, this.subscription);
final Subscription subscription2 = new Subscription();
subscription2.setProject(newProject("sea-octopus"));
subscription2.setNode(subscription.getNode());
em.persist(subscription2);
// Add parameters
setGroup(subscription2, "sea-octopus-");
setOu(subscription2, "sea");
// Invoke link for an already linked entity, since for now
basicCreate(subscription2);
}
示例6: createNotCompliantGroupForOu
import org.ligoj.app.model.Subscription; //导入依赖的package包/类
/**
* Create a group for an existing project, perfect match with the pkey, but without reusing the OU of this project.
*/
@Test
public void createNotCompliantGroupForOu() throws Exception {
thrown.expect(ValidationJsonException.class);
thrown.expect(MatcherUtil.validationMatcher(IdentityResource.PARAMETER_GROUP, "pattern"));
// Preconditions
Assert.assertNull(getGroup().findById("sea-invalid-ou"));
Assert.assertNotNull(projectCustomerLdapRepository.findAll("ou=project,dc=sample,dc=com").get("sea"));
// Attach the new group
final Subscription subscription = em.find(Subscription.class, this.subscription);
final Subscription subscription2 = new Subscription();
subscription2.setProject(newProject("sea-invalid-ou"));
subscription2.setNode(subscription.getNode());
em.persist(subscription2);
// Add parameters
setGroup(subscription2, "sea-invalid-ou");
setOu(subscription2, "gfi");
// Invoke link for an already linked entity, since for now
basicCreate(subscription2);
}
示例7: createNotExistingParentGroup
import org.ligoj.app.model.Subscription; //导入依赖的package包/类
/**
* Create a group inside an existing group without reusing the name of the parent.
*/
@Test
public void createNotExistingParentGroup() throws Exception {
thrown.expect(ValidationJsonException.class);
thrown.expect(MatcherUtil.validationMatcher(IdentityResource.PARAMETER_PARENT_GROUP, "unknown-id"));
// Preconditions
Assert.assertNotNull(getGroup().findById("sea-octopus"));
Assert.assertNull(getGroup().findById("sea-octopus-client"));
Assert.assertNotNull(projectCustomerLdapRepository.findAll("ou=project,dc=sample,dc=com").get("sea"));
// Attach the new group
final Subscription subscription = em.find(Subscription.class, this.subscription);
final Subscription subscription2 = new Subscription();
subscription2.setProject(newProject("sea-orpahn"));
subscription2.setNode(subscription.getNode());
em.persist(subscription2);
// Add parameters
setGroup(subscription2, "sea-orpahn-any");
setParentGroup(subscription2, "sea-orpahn");
setOu(subscription2, "sea");
// Invoke link for an already linked entity, since for now
basicCreate(subscription2);
}
示例8: addSubscriptionActivities
import org.ligoj.app.model.Subscription; //导入依赖的package包/类
@Test
public void addSubscriptionActivities() throws Exception {
final LdapPluginResource resource = new LdapPluginResource();
final Map<String, Map<String, Activity>> activities = new HashMap<>();
final Subscription susbscription = new Subscription();
final Node service = new Node();
service.setId("J1");
susbscription.setNode(service);
susbscription.setId(1);
final SampleActivityProvider plugin = Mockito.mock(SampleActivityProvider.class);
final Map<String, Activity> activities1 = new HashMap<>();
final Activity activity2 = new Activity();
activities1.put(DEFAULT_USER, activity2);
Mockito.when(plugin.getActivities(1, null)).thenReturn(activities1);
final Set<INamableBean<String>> nodes = new HashSet<>();
resource.addSubscriptionActivities(activities, null, susbscription, plugin, nodes);
Assert.assertEquals(1, activities.size());
Assert.assertTrue(activities.containsKey(DEFAULT_USER));
Assert.assertEquals(1, activities.get(DEFAULT_USER).size());
Assert.assertTrue(activities.get(DEFAULT_USER).containsKey("J1"));
Assert.assertEquals(activity2, activities.get(DEFAULT_USER).get("J1"));
}
示例9: addSubscriptionActivitiesDuplicateUser
import org.ligoj.app.model.Subscription; //导入依赖的package包/类
@Test
public void addSubscriptionActivitiesDuplicateUser() throws Exception {
final LdapPluginResource resource = new LdapPluginResource();
final Map<String, Map<String, Activity>> activities = new HashMap<>();
activities.put(DEFAULT_USER, new HashMap<>());
final Activity activity1 = new Activity();
activities.get(DEFAULT_USER).put("J0", activity1);
final Subscription susbscription = new Subscription();
final Node service = new Node();
service.setId("J1");
susbscription.setNode(service);
susbscription.setId(1);
final SampleActivityProvider plugin = Mockito.mock(SampleActivityProvider.class);
final Map<String, Activity> activities1 = new HashMap<>();
final Activity activity2 = new Activity();
activities1.put(DEFAULT_USER, activity2);
Mockito.when(plugin.getActivities(1, null)).thenReturn(activities1);
final Set<INamableBean<String>> nodes = new HashSet<>();
resource.addSubscriptionActivities(activities, null, susbscription, plugin, nodes);
Assert.assertEquals(1, activities.size());
Assert.assertTrue(activities.containsKey(DEFAULT_USER));
Assert.assertEquals(2, activities.get(DEFAULT_USER).size());
Assert.assertTrue(activities.get(DEFAULT_USER).containsKey("J1"));
Assert.assertEquals(activity1, activities.get(DEFAULT_USER).get("J0"));
Assert.assertEquals(activity2, activities.get(DEFAULT_USER).get("J1"));
}
示例10: checkAndSaveSchedule
import org.ligoj.app.model.Subscription; //导入依赖的package包/类
private VmSchedule checkAndSaveSchedule(final VmScheduleVo schedule, final VmSchedule entity) {
// Check the subscription is visible
final Subscription subscription = subscriptionResource.checkVisibleSubscription(schedule.getSubscription());
if (schedule.getCron().split(" ").length == 6) {
// Add the missing "seconds" part
schedule.setCron(schedule.getCron() + " *");
}
// Check expressions first
if (!CronExpression.isValidExpression(schedule.getCron())) {
throw new ValidationJsonException("cron", "vm-cron");
}
// Every second is not accepted
if (schedule.getCron().startsWith("* ")) {
throw new ValidationJsonException("cron", "vm-cron-second");
}
entity.setSubscription(subscription);
entity.setOperation(schedule.getOperation());
entity.setCron(schedule.getCron());
// Persist the new schedules for each provided CRON
vmScheduleRepository.saveAndFlush(entity);
return entity;
}
示例11: delete
import org.ligoj.app.model.Subscription; //导入依赖的package包/类
@Test
public void delete() throws SchedulerException {
final Project project = new Project();
project.setName("TEST");
project.setPkey("test");
em.persist(project);
final Subscription subscription = new Subscription();
subscription.setProject(project);
subscription.setNode(nodeRepository.findOneExpected("service:vm"));
em.persist(subscription);
Assert.assertEquals(1, subscriptionRepository.findAllByProject(project.getId()).size());
em.flush();
em.clear();
resource.delete(subscription.getId(), false);
subscriptionRepository.delete(subscription);
em.flush();
em.clear();
Assert.assertEquals(0, subscriptionRepository.findAllByProject(project.getId()).size());
Assert.assertEquals(0, vmScheduleRepository.findBySubscription(subscription.getId()).size());
Assert.assertEquals(0, vmExecutionRepository.findAllBy("subscription.id", subscription.getId()).size());
}
示例12: getTerraformLog
import org.ligoj.app.model.Subscription; //导入依赖的package包/类
/**
* Get the log of the current or last Terraform execution of a given
* subscription.
*
* @param subscription
* The related subscription.
* @return the streaming {@link Response} with output.
* @throws IOException
* When Terraform content cannot be written.
*/
@GET
@Produces(MediaType.TEXT_HTML)
@Path("{subscription:\\d+}/terraform.log")
public Response getTerraformLog(@PathParam("subscription") final int subscription) throws IOException {
final Subscription entity = subscriptionResource.checkVisibleSubscription(subscription);
final File log = toFile(entity, MAIN_LOG);
// Check there is a log file
if (log.exists()) {
final StreamingOutput so = o -> FileUtils.copyFile(toFile(entity, MAIN_LOG), o);
return Response.ok().entity(so).build();
}
// No log file for now
return Response.status(Status.NOT_FOUND).build();
}
示例13: createNoCatalog
import org.ligoj.app.model.Subscription; //导入依赖的package包/类
@Test(expected = BusinessException.class)
public void createNoCatalog() throws Exception {
final Subscription subscription = new Subscription();
subscription.setNode(em.find(Subscription.class, this.subscription).getNode());
subscription.setProject(em.find(Subscription.class, this.subscription).getProject());
em.persist(subscription);
qsRepository.deleteAll();
qiRepository.deleteAll();
ipRepository.deleteAll();
iptRepository.deleteAll();
itRepository.deleteAll();
spRepository.deleteAll();
stRepository.deleteAll();
icsRepository.deleteAll();
repository.deleteAll();
locationRepository.deleteAll();
em.flush();
em.clear();
resource.create(subscription.getId());
}
示例14: applyTerraformError
import org.ligoj.app.model.Subscription; //导入依赖的package包/类
/**
* IOException during the asynchronous execution
*/
@Test
public void applyTerraformError() {
final TerraformResource resource = new TerraformResource() {
@Override
protected File applyTerraform(final Subscription entity, final Terraforming terra, final QuoteVo configuration)
throws IOException, InterruptedException {
throw new IOException();
}
};
super.applicationContext.getAutowireCapableBeanFactory().autowireBean(resource);
// Mock to disable inner transactions for this test
resource.resource = Mockito.mock(ProvResource.class);
final ServicePluginLocator locator = Mockito.mock(ServicePluginLocator.class);
// Replace the plugin locator
resource.locator = locator;
Mockito.when(locator.getResource("service:prov:test:account", Terraforming.class)).thenReturn(Mockito.mock(Terraforming.class));
resource.applyTerraform(subscription);
}
示例15: toFile
import org.ligoj.app.model.Subscription; //导入依赖的package包/类
@Test
public void toFile() throws IOException {
ThreadClassLoaderScope scope = null;
try {
final PluginsClassLoader classLoader = Mockito.mock(PluginsClassLoader.class);
scope = new ThreadClassLoaderScope(new URLClassLoader(new URL[0], classLoader));
final File file = new File("");
final Subscription entity = new Subscription();
entity.setId(15);
Mockito.when(classLoader.toFile(entity, "15", "some")).thenReturn(file);
Assert.assertSame(file, resource.toFile(entity, "some"));
Assert.assertNotNull(PluginsClassLoader.getInstance());
} finally {
IOUtils.closeQuietly(scope);
}
}