/** * 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)); }
@Override public void link(final int subscription) { final Map<String, String> parameters = subscriptionResource.getParameters(subscription); // Validate the job settings validateGroup(parameters); // There is no additional step since the group is already created in // LDAP }
/** * 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); }
/** * 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)); }
final Project project = checkVisibleProject(vo.getProject()); checkManagedProject(vo.getProject()); final Node node = checkManagedNodeForSubscription(vo.getNode()); final List<Parameter> acceptedParameters = checkInputParameters(vo); final Subscription entity = toEntity(vo, project, node); delegateToPlugin(vo, entity); checkMandatoryParameters(vo.getParameters(), acceptedParameters, SubscriptionMode.CREATE); log.info("Subscription of project {} to service {}", vo.getProject(), vo.getNode());
/** * 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); }
/** * 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 boolean completeStatus(final VmExecutionStatus task) { if (task.isFailed()) { task.setFinishedRemote(true); } if (!task.isFinishedRemote() && task.isFinished()) { // Complete the status for the uncompleted tasks final int subscription = task.getLocked().getId(); final String node = task.getLocked().getNode().getId(); try { final Vm vm = getTool(node).getVmDetails(subscriptionResource.getParametersNoCheck(subscription)); task.setVm(vm); task.setFinishedRemote(!vm.isBusy()); return true; } catch (final Exception e) { // Unable to get the VM details log.info("Unable to retrive VM information of subscription {}, node {}", subscription, node); } } return false; }
/** * Extract the distinct nodes from the subscriptions. */ private Map<String, SubscribedNodeVo> toNodes(final Map<String, NodeVo> nodes, final Collection<SubscriptionLightVo> subscriptions) { final Map<String, SubscribedNodeVo> filteredNodes = new TreeMap<>(); // Add the related node of each subscription subscriptions.stream().map(SubscriptionLightVo::getNode).map(nodes::get) .forEach(n -> addNodeAsNeeded(filteredNodes, nodes, n)); return filteredNodes; }
/** * Add a node to the filtered nodes, and also add recursively the parent. */ private void addNodeAsNeeded(final Map<String, SubscribedNodeVo> filteredNodes, final Map<String, NodeVo> allNodes, final NodeVo node) { if (!filteredNodes.containsKey(node.getId())) { // Build the node wrapper final SubscribedNodeVo subscribedNode = new SubscribedNodeVo(); NamedBean.copy(node, subscribedNode); subscribedNode.setTag(node.getTag()); subscribedNode.setTagUiClasses(node.getTagUiClasses()); filteredNodes.put(node.getId(), subscribedNode); // Now check the parent exists or not and add it to the target // filtered nodes if (node.isRefining()) { // Completed the previous link subscribedNode.setRefined(node.getRefined().getId()); // Add the parent too (as needed addNodeAsNeeded(filteredNodes, allNodes, allNodes.get(subscribedNode.getRefined())); } } }
/** * 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 the version of tool or <code>null</code> if not available/found. * * @param subscription * the subscription's identifier to use to locate the target instance. * @return the version of tool or <code>null</code> if not available/found. * @throws Exception * When version cannot be be retrieved. */ @GET @Path("version/{subscription:\\d+}") public String getVersion(@PathParam("subscription") final int subscription) throws Exception { // Return the version from the subscription parameters return getVersion(subscriptionResource.getParameters(subscription)); }
/** * 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()); }
/** * Return users member of associated subscription. * * @param subscription * The subscription identifier used to get the related group and members. * @return The members of related groups of the subscription. */ public Collection<UserOrg> getMembers(final int subscription) { // Get current subscription parameters final Map<String, String> parameters = subscriptionResource.getParameters(subscription); final String group = parameters.get(IdentityResource.PARAMETER_GROUP); return userResource.findAllNotSecure(null, group); }
/** * 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(); }
@Override public void delete(final int subscription, final boolean deleteRemoteData) { if (deleteRemoteData) { // Data are removed from the LDAP final Map<String, String> parameters = subscriptionResource.getParameters(subscription); final String group = parameters.get(IdentityResource.PARAMETER_GROUP); // Check the group exists, but is not required to continue the // process final GroupLdapRepository repository = getGroup(); final GroupOrg groupLdap = repository.findById(group); if (groupLdap != null) { // Perform the deletion repository.delete(groupLdap); } } }
/** * 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); }
@Override public void create(final int subscription) { final Map<String, String> parameters = subscriptionResource.getParameters(subscription); final String group = parameters.get(IdentityResource.PARAMETER_GROUP); final String parentGroup = parameters.get(IdentityResource.PARAMETER_PARENT_GROUP); final String ou = parameters.get(IdentityResource.PARAMETER_OU); final Project project = subscriptionRepository.findOne(subscription).getProject(); final String pkey = project.getPkey(); // Check the relationship between group, OU and project validateGroup(group, ou, pkey); // Check the relationship between group, and parent final String parentDn = validateAndCreateParent(group, parentGroup, ou, pkey); // Create the group inside the parent (OU or parent CN) final String groupDn = "cn=" + group + "," + parentDn; log.info("New Group CN would be created {} project {} and subscription {}", group, pkey); final GroupLdapRepository repository = getGroup(); final GroupOrg groupLdap = repository.create(groupDn, group); // Complete as needed the relationship between parent and this new group if (StringUtils.isNotBlank(parentGroup)) { // This group will be added as "uniqueMember" of its parent repository.addGroup(groupLdap, parentGroup); } // Associate the project to this group in the cache final CacheProjectGroup projectGroup = new CacheProjectGroup(); projectGroup.setProject(project); projectGroup.setGroup(repository.getCacheRepository().findOneExpected(groupLdap.getId())); cacheProjectGroupRepository.saveAndFlush(projectGroup); }
/** * 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); }
/** * Refresh given subscriptions and return their status. */ private SubscriptionStatusWithData refreshSubscription(final Subscription subscription) { final Map<String, String> parameters = getParameters(subscription.getId()); final SubscriptionStatusWithData statusWithData = nodeResource.checkSubscriptionStatus(subscription, parameters); statusWithData.setId(subscription.getId()); statusWithData.setProject(subscription.getProject().getId()); statusWithData.setParameters(parameterValueResource.getNonSecuredSubscriptionParameters(subscription.getId())); // Update the last event with fresh data eventResource.registerEvent(subscription, EventType.STATUS, statusWithData.getStatus().name()); // Return the fresh statuses return statusWithData; }