コード例 #1
0
 protected void validateLinks(final Map<String, ServiceLink> newServiceLinks) {
   for (ServiceLink link : newServiceLinks.values()) {
     Service targetService = objMgr.loadResource(Service.class, link.getServiceId());
     if (targetService == null
         || targetService.getRemoved() != null
         || targetService.getState().equalsIgnoreCase(CommonStatesConstants.REMOVING)) {
       Object obfuscatedId = idFormatter.formatId("service", link.getServiceId());
       String obfuscatedIdStr = obfuscatedId != null ? obfuscatedId.toString() : null;
       String svcName = targetService != null ? targetService.getName() : obfuscatedIdStr;
       ValidationErrorCodes.throwValidationError(
           ValidationErrorCodes.INVALID_REFERENCE, "Service " + svcName + " is removed");
     }
   }
 }
コード例 #2
0
  protected Map<String, ServiceLink> populateNewServiceLinks(ApiRequest request) {
    Map<String, ServiceLink> newServiceLinks = new HashMap<>();
    List<? extends ServiceLink> serviceLinks =
        DataAccessor.fromMap(request.getRequestObject())
            .withKey(ServiceConstants.FIELD_SERVICE_LINKS)
            .withDefault(Collections.EMPTY_LIST)
            .asList(jsonMapper, ServiceLink.class);

    if (serviceLinks != null) {
      for (ServiceLink serviceLink : serviceLinks) {
        newServiceLinks.put(serviceLink.getUuid(), serviceLink);
      }
    }

    return newServiceLinks;
  }
コード例 #3
0
  private void removeOldServiceMaps(Service service, Map<String, ServiceLink> newServiceLinks) {
    List<? extends ServiceConsumeMap> existingMaps =
        consumeMapDao.findConsumedMapsToRemove(service.getId());
    List<ServiceLink> linksToRemove = new ArrayList<>();

    for (ServiceConsumeMap existingMap : existingMaps) {
      ServiceLink existingLink =
          new ServiceLink(existingMap.getConsumedServiceId(), existingMap.getName());
      if (!newServiceLinks.containsKey(existingLink.getUuid())) {
        linksToRemove.add(existingLink);
      }
    }

    for (ServiceLink linkToRemove : linksToRemove) {
      sdService.removeServiceLink(service, linkToRemove);
    }
  }
  @Override
  public void removeServiceLink(Service service, ServiceLink serviceLink) {
    ServiceConsumeMap map =
        consumeMapDao.findMapToRemove(service.getId(), serviceLink.getServiceId());

    if (map != null) {
      objectProcessManager.scheduleProcessInstance(
          ServiceDiscoveryConstants.PROCESS_SERVICE_CONSUME_MAP_REMOVE, map, null);
    }
  }
コード例 #5
0
  @Override
  public void cloneConsumingServices(Service fromService, Service toService) {
    List<ServiceLink> linksToCreate = new ArrayList<>();

    for (ServiceConsumeMap map : consumeMapDao.findConsumingServices(fromService.getId())) {
      ServiceLink link;
      List<String> ports =
          DataAccessor.fieldStringList(map, LoadBalancerConstants.FIELD_LB_TARGET_PORTS);
      if (ports == null) {
        link = new ServiceLink(toService.getId(), map.getName());
      } else {
        link = new LoadBalancerServiceLink(toService.getId(), map.getName(), ports);
      }

      link.setConsumingServiceId(map.getServiceId());
      linksToCreate.add(link);
    }

    consumeMapDao.createServiceLinks(linksToCreate);
  }