/** * Check and return the bug tracker configuration attached to the given * subscription. */ private BugTrackerConfiguration getConfigurationBySubscription(final int subscription) { return repository.findByExpected("subscription", subscriptionResource.checkVisible(subscription)); }
/** * Get fresh status of given subscription. This fresh status is also stored in the data base. The project must be * visible to current user. * * @param id * Node identifier * @return Status of each subscription of given project. */ @Path("status/{id:\\d+}/refresh") @GET public SubscriptionStatusWithData refreshStatus(@PathParam("id") final int id) { return refreshSubscription(checkVisible(id)); }
/** * Return all parameters values related to the subscription. The attached project is validated against the current * user to check it is visible. Beware, these parameters must not be returned to user, since clear encrypted * parameters are present. * * @param id * The subscription identifier. * @return all associated parameters values. Key of returned map is the identifier of * {@link org.ligoj.app.model.Parameter} */ @org.springframework.transaction.annotation.Transactional(readOnly = true) public Map<String, String> getParameters(final int id) { checkVisible(id); return getParametersNoCheck(id); }
/** * Execute a {@link VmOperation} to the associated VM and checks its visibility against the current principal user. * This a synchronous call, but the effective execution is delayed. * * @param subscription * The {@link Subscription} identifier associated to the VM. * @param operation * the operation to execute. * @return The execution task information. */ @POST @Path("{operation}") @Consumes(MediaType.APPLICATION_JSON) public VmExecutionStatus execute(@PathParam("subscription") final int subscription, @PathParam("operation") final VmOperation operation) { return execute(subscriptionResource.checkVisible(subscription), operation); }
/** * Return non secured parameters values related to the subscription.The attached project is validated against the * current user to check it is visible. Secured parameters (even the encrypted ones) are not returned. The * visibility of this subscription is checked. * * @param id * The subscription identifier. * @return secured associated parameters values. Key of returned map is the identifier of * {@link org.ligoj.app.model.Parameter} */ @GET @Path("{id:\\d+}") @org.springframework.transaction.annotation.Transactional(readOnly = true) public Map<String, String> getNonSecuredParameters(@PathParam("id") final int id) { return parameterValueResource.getNonSecuredSubscriptionParameters(checkVisible(id).getId()); }
/** * Delete the schedule entity. Related subscription's visibility is checked. * * @param subscription * The target subscription. The subscription cannot be changed for a schedule. * @param schedule * The schedule identifier to delete. * @throws SchedulerException * When the schedule cannot be done by Quartz. */ @DELETE @Path("{id:\\d+}") @Transactional public void delete(@PathParam("subscription") final int subscription, @PathParam("id") final int schedule) throws SchedulerException { // Check the subscription is visible subscriptionResource.checkVisible(subscription); // Check the schedule is related to the subscription checkOwnership(subscription, schedule); // Clear the specific schedule unschedule(schedule); }
/** * Return the execution report of VM related to the given subscription. * * @param subscription * The related subscription. * @param file * The requested file name. * @return The download stream. */ @GET @Produces(MediaType.APPLICATION_OCTET_STREAM) @Path("{file:executions-.*.csv}") public Response downloadHistoryReport(@PathParam("subscription") final int subscription, @PathParam("file") final String file) { subscriptionResource.checkVisible(subscription); return AbstractToolPluginResource .download(o -> writeHistory(o, vmExecutionRepository.findAllBySusbsciption(subscription)), file) .build(); }
/** * Return all snapshots matching to the given criteria and also associated to the given subscription. * * @param subscription * The related subscription identifier. * @param criteria * The optional search criteria. Case is insensitive. May be the name or the identifier for this * snapshot. * @return Matching snapshots ordered by descending creation date. * @throws Exception * Any error while finding the snapshots. */ @GET public List<Snapshot> findAll(@PathParam("subscription") final int subscription, @PathParam("q") @DefaultValue("") final String criteria) throws Exception { // Check the visibility and get the contract implementation return getSnapshot(subscriptionResource.checkVisible(subscription).getNode()).findAllSnapshots(subscription, criteria); }
@GET @Path("{subscription:\\d+}") @Override @Transactional @org.springframework.transaction.annotation.Transactional(readOnly = true) public VmConfigurationVo getConfiguration(@PathParam("subscription") final int subscription) throws ParseException { // Check the subscription is visible final Subscription entity = subscriptionResource.checkVisible(subscription); // Get the details final VmConfigurationVo result = new VmConfigurationVo(); result.setSchedules(scheduleResource.findAll(subscription)); // Add snapshot capability result.setSupportSnapshot(locator.getResource(entity.getNode().getId(), Snapshotting.class) != null); return result; } }
/** * 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.checkVisible(subscription); final List<Subscription> subscriptions = subscriptionRepository.findAllOnSameProject(subscription); final Set<UserOrg> users = global ? getMembersOfAllSubscriptions(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; }
/** * Delete entity and cascaded associations : parameters, events then subscription. * * @param id * the entity identifier. * @param deleteRemoteData * When <code>true</code>, remote data will be also destroyed. * @throws Exception * When the delete fails. Managed at JAX-RS level. */ @Path("{id:\\d+}/{deleteRemoteData}") @DELETE public void delete(@PathParam("id") final int id, @PathParam("deleteRemoteData") final boolean deleteRemoteData) throws Exception { final Subscription entity = checkVisible(id); checkManagedProject(entity.getProject().getId()); // Delete the events eventRepository.deleteAllBy("subscription", entity); // Delegate the deletion deleteWithTasks(entity.getNode().getId(), id, deleteRemoteData); parameterValueResource.deleteBySubscription(id); repository.delete(entity); }
@PathParam("snapshot") final String snapshot) { final Snapshotting snap = getSnapshot(subscriptionResource.checkVisible(subscription).getNode()); log.info("Snapshot deletion requested for subscription {}, snapshot {}", subscription, snapshot); final VmSnapshotStatus task = startTask(subscription, t -> {
@QueryParam("stop") @DefaultValue("false") final boolean stop) { final Snapshotting snap = getSnapshot(subscriptionResource.checkVisible(subscription).getNode()); log.info("New snapshot requested for subscription {}", subscription); final VmSnapshotStatus task = startTask(subscription, t -> {
@Override public boolean isFinished(final VmSnapshotStatus task) { // Complete the status for the not completed tasks if (task.isFailed()) { task.setFinishedRemote(true); } else if (!task.isFinishedRemote()) { getSnapshot(subscriptionResource.checkVisible(task.getLocked().getId()).getNode()) .completeStatus(task); } return task.isFinishedRemote(); }
/** * Return tools specific configuration. Only non secured parameters are returned. * * @param id * The subscription identifier. * @return tools specific configuration. * @throws Exception * When the configuration gathering fails. Managed at JAX-RS level. */ @GET @Path("{id:\\d+}/configuration") @org.springframework.transaction.annotation.Transactional(readOnly = true) public ConfigurationVo getConfiguration(@PathParam("id") final int id) throws Exception { // Copy subscription details final Subscription entity = checkVisible(id); final ConfigurationVo vo = new ConfigurationVo(); vo.setNode(NodeResource.toVo(entity.getNode())); vo.setParameters(getNonSecuredParameters(id)); vo.setSubscription(id); vo.setProject(DescribedBean.clone(entity.getProject())); // Get specific configuration final ConfigurablePlugin servicePlugin = locator.getResource(vo.getNode().getId(), ConfigurablePlugin.class); if (servicePlugin != null) { // Specific configuration is available vo.setConfiguration(servicePlugin.getConfiguration(id)); } return vo; }
private VmSchedule checkAndSave(final int subscription, final VmScheduleVo schedule, final VmSchedule entity) { // Check the subscription is visible final Subscription subscriptionEntity = subscriptionResource.checkVisible(subscription); 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(subscriptionEntity); entity.setOperation(schedule.getOperation()); entity.setCron(schedule.getCron()); // Persist the new schedules for each provided CRON repository.saveAndFlush(entity); return entity; }