/** * Return <code>true</code> when this node is a service level. * * @return <code>true</code> when this node is a service level. */ @JsonIgnore public boolean isService() { return getId().split(":").length == 2; }
/** * Return <code>true</code> when this node is a service level. * * @return <code>true</code> when this node is a service level. */ @JsonIgnore public boolean isTool() { return getId().split(":").length == 3; }
/** * Return <code>true</code> when this node is a node/instance level. * * @return <code>true</code> when this node is a node/instance level. */ @JsonIgnore public boolean isInstance() { return getId().split(":").length == 4; }
/** * Add activities related to a single node. */ private void addUserActivities(final Map<String, Map<String, Activity>> activities, final Node node, final Entry<String, Activity> userActivity) { final String user = userActivity.getKey(); activities.computeIfAbsent(user, k -> new HashMap<>()).put(node.getId(), userActivity.getValue()); }
/** * Return the last part of the node identifier, excluding the part of the parent. Built like that : * <ul> * <li>node = 'service:id:ldap:ad1', fragment = 'ad1'</li> * <li>node = 'service:id:ldap', fragment = 'ldap'</li> * <li>node = 'service:id', fragment = 'service:id'</li> * </ul> * * @param node * The node to convert to a simple fragment String. * @return The simple fragment. */ private String toFragmentId(final Node node) { return node.isRefining() ? node.getId().substring(node.getRefined().getId().length() + 1) : node.getId(); } }
/** * Check the subscriptions of each subscription related to given node. */ private void checkNodeSubscriptions(final Node node, final Map<String, String> nodeParameters, final Map<Subscription, Map<String, String>> subscriptions) { int counter = 0; for (final Entry<Subscription, Map<String, String>> subscription : subscriptions.entrySet()) { // For each subscription, check status log.info("Check all subscriptions of node {} : {}/{} ...", node.getId(), counter + 1, subscriptions.size()); final Map<String, String> parameters = new HashMap<>(nodeParameters); parameters.putAll(subscription.getValue()); final NodeStatus subscriptionStatus = self.checkSubscriptionStatus(subscription.getKey(), parameters) .getStatus(); eventResource.registerEvent(subscription.getKey(), EventType.STATUS, subscriptionStatus.name()); counter++; } }
/** * Return members of given subscription. */ private Set<UserOrg> getMembersOfSubscription(final Subscription subscription) { final Set<UserOrg> users = new HashSet<>(); final ServicePlugin plugin = servicePluginLocator.getResource(subscription.getNode().getId()); if (plugin instanceof LdapPluginResource) { users.addAll(((LdapPluginResource) plugin).getMembers(subscription.getId())); } return users; }
/** * Update the given node parameter values. The old not updated values are deleted. * * @param values * the parameter values to persist. * @param node * The related node. */ public void update(final List<ParameterValueCreateVo> values, final Node node) { // Build the old parameter values final List<ParameterValue> oldList = repository.getParameterValues(node.getId()); final Map<String, ParameterValue> oldMap = oldList.stream() .collect(Collectors.toMap(v -> v.getParameter().getId(), Function.identity())); // Build the target parameter values final Set<String> newParam = values.stream().map(v -> saveOrUpdate(oldMap, v)).filter(Objects::nonNull) .peek(v -> v.setNode(node)).map(repository::saveAndFlush).map(v -> v.getParameter().getId()) .collect(Collectors.toSet()); // Delete the existing but not provided values CollectionUtils.removeAll(oldMap.keySet(), newParam).stream().map(oldMap::get).forEach(repository::delete); cacheManager.getCache("node-parameters").evict(node.getId()); }
/** * Check the node scoped object is related to the given node. Will fail with a {@link EntityNotFoundException} if * the related node if not a sub node of the required node. * * @param nodeScoped * The object related to a node. * @param requiredNode * The widest accepted node relationship. * @param <T> * The {@link Configurable} type. * @return the formal node coped object when the visibility has been checked. */ public <T extends NodeScoped> T checkVisibility(final T nodeScoped, final String requiredNode) { // Compare the node against the scoped entity if (!nodeScoped.getNode().getId().matches("^" + requiredNode + "(:.+)?$")) { // The expected node does not exists in the expected node scope throw new EntityNotFoundException(nodeScoped.getId().toString()); } // Checked return nodeScoped; }
/** * Check the status of a node. * * @param node * The node to check. * @return the new status. */ private NodeStatus checkNodeStatus(final Node node) { final Map<String, String> parameters = pvResource.getNodeParameters(node.getId()); final NodeStatus status = self.checkNodeStatus(node.getId(), parameters); if (eventResource.registerEvent(node, EventType.STATUS, status.name())) { checkSubscriptionStatus(node, status); } return status; }
@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; } }
/** * Create the given node parameter values. * * @param values * the parameter values to persist. * @param node * The related node. */ public void create(final List<ParameterValueCreateVo> values, final Node node) { create(values, v -> v.setNode(node)); cacheManager.getCache("node-parameters").evict(node.getId()); }
/** * Return all events related to a visible node of given user. * * @param user * The principal user requesting these events. * @return Events related to a visible {@link Node}. */ public List<EventVo> findAll(final String user) { final List<Event> events = repository.findLastEvents(user); final Map<String, EventVo> services = new HashMap<>(); final Map<String, EventVo> tools = new HashMap<>(); for (final Event event : events) { final Node parent = event.getNode().getRefined(); fillParentEvents(tools, parent, EventResource.toVo(event), event.getValue()); fillParentEvents(services, parent.getRefined(), tools.get(parent.getId()), event.getValue()); } return new ArrayList<>(services.values()); }
private void fillParentEvents(final Map<String, EventVo> parents, final Node parent, final EventVo eventVo, final String eventValue) { final EventVo service = parents.computeIfAbsent(parent.getId(), key -> { final EventVo result = new EventVo(); result.setNode(NodeResource.toVoLight(parent)); result.setValue(eventValue); result.setType(eventVo.getType()); return result; }); service.getSpecifics().add(eventVo); if ("DOWN".equals(eventValue)) { service.setValue(eventValue); } } }
/** * Check the parameter is related to the given node. * * @param parameter * The parameter to check. * @param node * The node scope the parameter must be related to. */ public void checkOwnership(final Parameter parameter, final Node node) { if (!equalsOrParentOf(parameter.getOwner(), node)) { // This parameter is detached from the node's hierarchy throw new BusinessException("invalid-parameter-node-ownership", "parameter", parameter.getId(), "node", node.getId()); } }
/** * 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 a {@link ParameterValue}. A value can be deleted only where there is no subscription on the related node, * or the related parameter is not mandatory. * * @param id * The entity's identifier. */ public void delete(final int id) { // Check the value exist and related to a visible writable node final ParameterValue value = findOneExpected(id); // Check the visible node can also be edited nodeResource.checkWritableNode(value.getNode().getId()); // A mandatory parameter can be deleted only when there is no // subscription to the same node checkUnusedValue(value); // Deletion can be performed repository.deleteById(id); }
@Override public BtConfigurationVo getConfiguration(final int subscription) throws Exception { final BtConfigurationVo result = new BtConfigurationVo(); final BugTrackerConfiguration configuration = getConfigurationBySubscription(subscription); result.setBusinessHours(new ArrayList<>(configuration.getBusinessHours())); final List<Sla> slas = configuration.getSlas(); result.setSlas(slaProcessor.toSlaConfiguration(slas)); result.setCalendar(configuration.getCalendar()); // Provider data final BugTrackerServicePlugin provider = servicePluginLocator.getResourceExpected(configuration.getSubscription().getNode().getId(), BugTrackerServicePlugin.class); result.setTypes(new ArrayList<>(provider.getTypes(subscription))); result.setStatuses(identifierHelper.normalize(provider.getStatuses(subscription))); result.setPriorities(new ArrayList<>(provider.getPriorities(subscription))); result.setResolutions(new ArrayList<>(provider.getResolutions(subscription))); return result; }
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; }