@Override
  public synchronized String getSchemaForCapability(String moduleName, Optional<String> revision) {

    Map<String, Map<String, String>> mappedModulesToRevisionToSchema = Maps.newHashMap();

    for (NetconfOperationService netconfOperationService :
        netconfOperationServiceSnapshot.getServices()) {
      final Set<Capability> caps = netconfOperationService.getCapabilities();

      for (Capability cap : caps) {
        if (cap.getModuleName().isPresent() == false) continue;
        if (cap.getRevision().isPresent() == false) continue;
        if (cap.getCapabilitySchema().isPresent() == false) continue;

        final String currentModuleName = cap.getModuleName().get();
        Map<String, String> revisionMap = mappedModulesToRevisionToSchema.get(currentModuleName);
        if (revisionMap == null) {
          revisionMap = Maps.newHashMap();
          mappedModulesToRevisionToSchema.put(currentModuleName, revisionMap);
        }

        String currentRevision = cap.getRevision().get();
        revisionMap.put(currentRevision, cap.getCapabilitySchema().get());
      }
    }

    Map<String, String> revisionMapRequest = mappedModulesToRevisionToSchema.get(moduleName);
    Preconditions.checkState(
        revisionMapRequest != null,
        "Capability for module %s not present, " + "" + "available modules : %s",
        moduleName,
        capabilityURIs);

    if (revision.isPresent()) {
      String schema = revisionMapRequest.get(revision.get());

      Preconditions.checkState(
          schema != null,
          "Capability for module %s:%s not present, available revisions for module: %s",
          moduleName,
          revision.get(),
          revisionMapRequest.keySet());

      return schema;
    } else {
      Preconditions.checkState(
          revisionMapRequest.size() == 1,
          "Expected 1 capability for module %s, available revisions : %s",
          moduleName,
          revisionMapRequest.keySet());
      return revisionMapRequest.values().iterator().next();
    }
  }
  private static Set<NetconfOperation> getAllNetconfOperations(
      Set<NetconfOperation> defaultNetconfOperations,
      NetconfOperationServiceSnapshot netconfOperationServiceSnapshot) {
    Set<NetconfOperation> result = new HashSet<>();
    result.addAll(defaultNetconfOperations);

    for (NetconfOperationService netconfOperationService :
        netconfOperationServiceSnapshot.getServices()) {
      final Set<NetconfOperation> netOpsFromService =
          netconfOperationService.getNetconfOperations();
      for (NetconfOperation netconfOperation : netOpsFromService) {
        Preconditions.checkState(
            result.contains(netconfOperation) == false,
            "Netconf operation %s already present",
            netconfOperation);
        result.add(netconfOperation);
      }
    }
    return Collections.unmodifiableSet(result);
  }
  private static Map<String, Capability> getCapabilitiesInternal(
      NetconfOperationServiceSnapshot netconfOperationServiceSnapshot) {
    Map<String, Capability> capabilityMap = Maps.newHashMap();

    for (NetconfOperationService netconfOperationService :
        netconfOperationServiceSnapshot.getServices()) {
      final Set<Capability> caps = netconfOperationService.getCapabilities();

      for (Capability cap : caps) {

        if (capabilityMap.containsKey(cap.getCapabilityUri())) {
          logger.debug(
              "Duplicate capability {} from service {}",
              cap.getCapabilityUri(),
              netconfOperationService);
        }

        capabilityMap.put(cap.getCapabilityUri(), cap);
      }
    }

    return capabilityMap;
  }