Verifies metadata versions for all the cluster nodes

@param adminClient An instance of AdminClient points to given cluster
514509
public static void doMetaCheckVersion(AdminClient adminClient) {
            Map<Properties, List<Integer>> versionsNodeMap = new HashMap<Properties, List<Integer>>();

            for(Integer nodeId: adminClient.getAdminClientCluster().getNodeIds()) {
                Versioned<Properties> versionedProp = doMetaGetVersionsForNode_ExitOnError(adminClient,
                                                                                           nodeId);
                Properties props = versionedProp.getValue();
                if(versionsNodeMap.containsKey(props) == false) {
                    versionsNodeMap.put(props, new ArrayList<Integer>());
                }
                versionsNodeMap.get(props).add(nodeId);
            }

            if(versionsNodeMap.keySet().size() <= 0) {
                System.err.println("No Versions found in the system store... something seriously wrong");
            } else if(versionsNodeMap.keySet().size() == 1) {
                System.err.println("All the nodes have the same metadata versions.");
                printProperties(versionsNodeMap.keySet().iterator().next());
            } else {
                System.err.println("Mismatching versions detected !!! . All are supposed to be written by the same client "
                                   + ""
                                   + " and hence they should exactly match but something different, let us analyze deeper ");
                Map<String, Map<String, List<Integer>>> propertyValueMap = new HashMap<String, Map<String, List<Integer>>>();
                for(Entry<Properties, List<Integer>> entry: versionsNodeMap.entrySet()) {
                    System.out.println("**************************** Node(s): "
                                       + Arrays.toString(entry.getValue().toArray())
                                       + " ****************************");
                    Properties props = entry.getKey();
                    printProperties(props);

                    for(String propName: props.stringPropertyNames()) {
                        String propValue = props.getProperty(propName);

                        if(propertyValueMap.containsKey(propName) == false) {
                            propertyValueMap.put(propName, new HashMap<String, List<Integer>>());
                        }
                        Map<String, List<Integer>> valuetoNodeMap = propertyValueMap.get(propName);
                        if(valuetoNodeMap.containsKey(propValue) == false) {
                            valuetoNodeMap.put(propValue, new ArrayList<Integer>());
                        }
                        valuetoNodeMap.get(propValue).addAll(entry.getValue());
                    }
                }
                
                System.out.println("########## Properties discrepancy report ########");
                for(Entry<String, Map<String, List<Integer>>> entry: propertyValueMap.entrySet()) {
                    Map<String, List<Integer>> valueToNodeMap = entry.getValue();
                    String propName = entry.getKey();
                    List<Integer> allNodeIds = new ArrayList<Integer>();
                    allNodeIds.addAll(adminClient.getAdminClientCluster().getNodeIds());
                    
                    List<Integer> nodesWithValues = new ArrayList<Integer>();
                    if(valueToNodeMap.size() != 1) {
                        System.out.println("Properties with multiple values");
                        for(Entry<String, List<Integer>> valueToNodeEntry: valueToNodeMap
                                                                              .entrySet()) {
                            String propValue = valueToNodeEntry.getKey();
                            nodesWithValues.addAll(valueToNodeEntry.getValue());
                            printProperty(propName, propValue, valueToNodeEntry.getValue());
                        }
                    } else  {
                        Map.Entry<String, List<Integer>> valueToNodeEntry = valueToNodeMap.entrySet()
                                                                                          .iterator()
                                                                                          .next();

                        nodesWithValues.addAll(valueToNodeEntry.getValue());
                        if(nodesWithValues.size() < allNodeIds.size()) {
                            String propValue = valueToNodeEntry.getKey();
                            printProperty(propName, propValue, valueToNodeEntry.getValue());
                        }
                    }

                    allNodeIds.removeAll(nodesWithValues);
                    if(allNodeIds.size() > 0) {
                        System.out.println("The Property " + propName + " is present in the nodes "
                                           + Arrays.toString(nodesWithValues.toArray())
                                           + " but missing from the nodes "
                                           + Arrays.toString(allNodeIds.toArray()));
                    }
                }
            }
        }
1256803
public static boolean hasMetadata(@NonNull final Context context, @NonNull final String metadataKey) {
        if (TextUtils.isEmpty(metadataKey)) {
            throw new IllegalArgumentException("Meta data key can't be null or empty.");
        }

        try {
            final PackageInfo info = context.getPackageManager()
                    .getPackageInfo(context.getPackageName(), PackageManager.GET_META_DATA);
            final Bundle metaData = info.applicationInfo.metaData;
            if (metaData != null && metaData.get(metadataKey) != null) {
                return true;
            }
        } catch (PackageManager.NameNotFoundException e) {
            //ignore
        }
        return false;
    }
1050909
public static void verifyVersion(int reportedVersion,
      int expectedVersion, String annotation) throws IOException {
    if ((reportedVersion ^ expectedVersion) < 0) {
      throw new IOException("reportedVersion and expectedVersion have" +
          " different signs : " + reportedVersion + ", " + expectedVersion);
    }
    // layout_version is negative and data_transfer is positive, so we need to
    // look at the absolute.
    if (Math.abs(reportedVersion) < Math.abs(expectedVersion))
      throw new IncorrectVersionException(
          reportedVersion, "data node " + annotation, expectedVersion);
  }
81641
private Pair<Cluster, List<StoreDefinition>> getCurrentClusterState() {

        // Retrieve the latest cluster metadata from the existing nodes
        Versioned<Cluster> currentVersionedCluster = adminClient.rebalanceOps.getLatestCluster(Utils.nodeListToNodeIdList(Lists.newArrayList(adminClient.getAdminClientCluster()
                                                                                                                                                        .getNodes())));
        Cluster cluster = currentVersionedCluster.getValue();
        List<StoreDefinition> storeDefs = adminClient.rebalanceOps.getCurrentStoreDefinitions(cluster);
        return new Pair<Cluster, List<StoreDefinition>>(cluster, storeDefs);
    }
1112417
public static Map<String, StoreDefinition> getUserStoreDefMapOnNode(AdminClient adminClient,
                                                                        Integer nodeId) {
        List<StoreDefinition> storeDefinitionList = adminClient.metadataMgmtOps.getRemoteStoreDefList(nodeId)
                                                                               .getValue();
        Map<String, StoreDefinition> storeDefinitionMap = Maps.newHashMap();
        for(StoreDefinition storeDefinition: storeDefinitionList) {
            storeDefinitionMap.put(storeDefinition.getName(), storeDefinition);
        }
        return storeDefinitionMap;
    }
1130562
private void verifyClusterState() {
        NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
        ClusterState clusterState = nodeEngine.getClusterService().getClusterState();
        if (!clusterState.isMigrationAllowed()) {
            throw new IllegalStateException("Cluster state does not allow migrations! " + clusterState);
        }
    }
371691
@GET
  @Path("/check")
  @Produces(APPLICATION_JSON)
  @Timed
  @ExceptionMetered
  public VersionCheckResponse versionCheck(
      @QueryParam("client") @DefaultValue("") final String client) {
    final PomVersion serverVersion = PomVersion.parse(Version.POM_VERSION);
    final VersionCompatibility.Status status;

    if (isNullOrEmpty(client)) {
      return new VersionCheckResponse(VersionCompatibility.Status.MISSING,
          serverVersion, Version.RECOMMENDED_VERSION);
    }

    final PomVersion clientVersion = PomVersion.parse(client);
    status = VersionCompatibility.getStatus(serverVersion, clientVersion);
    return new VersionCheckResponse(status, serverVersion, Version.RECOMMENDED_VERSION);
  }
585466
def es_version_check(f):
    """"""
    @wraps(f)
    def inner(*args, **kwargs):
        cluster_ver = current_search.cluster_version[0]
        client_ver = ES_VERSION[0]
        if cluster_ver != client_ver:
            raise click.ClickException(
                'Elasticsearch version mismatch. Invenio was installed with '
                'Elasticsearch v{client_ver}.x support, but the cluster runs '
                'Elasticsearch v{cluster_ver}.x.'.format(
                    client_ver=client_ver,
                    cluster_ver=cluster_ver,
                ))
        return f(*args, **kwargs)
    return inner
1297077
protected ClientVersionBean createClientVersionInternal(NewClientVersionBean bean,
            ClientBean client) throws StorageException {
        if (!BeanUtils.isValidVersion(bean.getVersion())) {
            throw new StorageException("Invalid/illegal client version: " + bean.getVersion()); //$NON-NLS-1$
        }

        ClientVersionBean newVersion = new ClientVersionBean();
        newVersion.setClient(client);
        newVersion.setCreatedBy(securityContext.getCurrentUser());
        newVersion.setCreatedOn(new Date());
        newVersion.setModifiedBy(securityContext.getCurrentUser());
        newVersion.setModifiedOn(new Date());
        newVersion.setStatus(ClientStatus.Created);
        newVersion.setVersion(bean.getVersion());
        newVersion.setApikey(bean.getApiKey());
        if (newVersion.getApikey() == null) {
            newVersion.setApikey(apiKeyGenerator.generate());
        }

        storage.createClientVersion(newVersion);
        storage.createAuditEntry(AuditUtils.clientVersionCreated(newVersion, securityContext));

        log.debug(String.format("Created new client version %s: %s", newVersion.getClient().getName(), newVersion)); //$NON-NLS-1$
        return newVersion;
    }
316488
protected Collection<FileSystemDatasetVersion> listQualifiedRawFileSystemDatasetVersions(Collection<FileSystemDatasetVersion> allVersions) {
    return Lists.newArrayList(Collections2.filter(allVersions, new Predicate<FileSystemDatasetVersion>() {
      @Override
      public boolean apply(FileSystemDatasetVersion version) {
        Iterable<Path> refinedDatasetPaths = getRefinedDatasetPaths(version);
        try {
          Optional<Long> latestRawDatasetModTime = getLatestModTime(version.getPaths());
          Optional<Long> latestRefinedDatasetModTime = getLatestModTime(refinedDatasetPaths);
          return latestRawDatasetModTime.isPresent() && latestRefinedDatasetModTime.isPresent()
              && latestRawDatasetModTime.get() <= latestRefinedDatasetModTime.get();
        } catch (IOException e) {
          throw new RuntimeException("Failed to get modification time", e);
        }
      }
    }));
  }
265417
@SuppressWarnings("unchecked")
    @Override
    protected List<Object> recursivelyPopulateEntities(EntityMetadata m, Client client) {
        List<EnhanceEntity> ls = null;
        ApplicationMetadata appMetadata = kunderaMetadata.getApplicationMetadata();
        externalProperties = ((CassandraClientBase) client).getExternalProperties();
        MetamodelImpl metaModel =
            (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(m.getPersistenceUnit());

        String query = appMetadata.getQuery(getJPAQuery());
        boolean isNative = kunderaQuery.isNative();

        if (isNative) {
            ls = (List<EnhanceEntity>) ((CassandraClientBase) client).executeQuery(m.getEntityClazz(),
                m.getRelationNames(), isNative, query != null ? query : getJPAQuery());
        } else if (!isNative && ((CassandraClientBase) client).isCql3Enabled(m)) {
            // edited
            // check if lucene or indexer are enabled then populate
            if (MetadataUtils.useSecondryIndex(((ClientBase) client).getClientMetadata())) {
                ls = ((CassandraClientBase) client).executeQuery(m.getEntityClazz(), m.getRelationNames(), isNative,

                    onQueryOverCQL3(m, client, metaModel, m.getRelationNames()));
            } else {
                ls = populateUsingLucene(m, client, null, getKunderaQuery().getResult());
            }
        } else {
            // Index in Inverted Index table if applicable
            boolean useInvertedIndex = CassandraIndexHelper.isInvertedIndexingApplicable(m,
                MetadataUtils.useSecondryIndex(((ClientBase) client).getClientMetadata()));
            Map<Boolean, List<IndexClause>> ixClause =
                MetadataUtils.useSecondryIndex(((ClientBase) client).getClientMetadata())
                    ? prepareIndexClause(m, useInvertedIndex) : null;

            if (useInvertedIndex && !getKunderaQuery().getFilterClauseQueue().isEmpty()) {
                ls = ((CassandraEntityReader) getReader()).readFromIndexTable(m, client, ixClause);
            } else {
                ((CassandraEntityReader) getReader()).setConditions(ixClause);
                ls = reader.populateRelation(m, client, isSingleResult ? 1 : this.maxResult);
            }
        }
        return setRelationEntities(ls, client, m);
    }
694054
private static boolean isMappingExist(RestHighLevelClient client, String index) throws Exception {
        GetMappingsResponse mapping = client.indices().getMapping(new GetMappingsRequest().indices(index), RequestOptions.DEFAULT);
        // Let's get the default mapping
        if (mapping.mappings().isEmpty()) {
            return false;
        }
        MappingMetaData doc = mapping.mappings().values().iterator().next();
        return !doc.getSourceAsMap().isEmpty();
    }
837920
public static final ClientVersionAlreadyExistsException clientVersionAlreadyExistsException(String clientName, String version) {
        return new ClientVersionAlreadyExistsException(Messages.i18n.format("clientVersionAlreadyExists", clientName, version)); //$NON-NLS-1$
    }
1321547
def check_dataset_metadata(client):
    """"""
    # Find pre 0.3.4 metadata files.
    old_metadata = list(_dataset_metadata_pre_0_3_4(client))

    if not old_metadata:
        return True

    click.secho(
        WARNING + 'There are metadata files in the old location.'
        '\n  (use "renku migrate datasets" to move them)\n\n\t' + '\n\t'.join(
            click.style(str(path.relative_to(client.path)), fg='yellow')
            for path in old_metadata
        ) + '\n'
    )

    return False
855795
@Nonnull
  public static ClientCertificateValidationResult verifyClientCertificate (@Nonnull final HttpServletRequest aHttpRequest,
                                                                           @Nonnull final String sLogPrefix)
  {
    if (s_bIsCheckDisabled.get ())
    {
      if (LOGGER.isDebugEnabled ())
        LOGGER.debug (sLogPrefix + "Client certificate is considered valid because the 'allow all' for tests is set!");
      return ClientCertificateValidationResult.createSuccess (INSECURE_DEBUG_CLIENT);
    }

    // This is how to get client certificate from request
    final Object aValue = aHttpRequest.getAttribute ("javax.servlet.request.X509Certificate");
    if (aValue == null)
    {
      if (LOGGER.isWarnEnabled ())
        LOGGER.warn (sLogPrefix + "No client certificates present in the request");
      return ClientCertificateValidationResult.createFailure ();
    }

    // type check
    if (!(aValue instanceof X509Certificate []))
      throw new IllegalStateException ("Request value is not of type X509Certificate[] but of " + aValue.getClass ());

    // Main checking
    final X509Certificate [] aRequestCerts = (X509Certificate []) aValue;
    if (ArrayHelper.isEmpty (aRequestCerts))
    {
      // Empty array
      if (LOGGER.isWarnEnabled ())
        LOGGER.warn (sLogPrefix + "No client certificates passed for validation");
      return ClientCertificateValidationResult.createFailure ();
    }

    // OK, we have a non-empty, type checked Certificate array

    // TODO: determine CRLs
    final ICommonsList <CRL> aCRLs = new CommonsArrayList <> ();

    // Verify for "now"
    final LocalDateTime aVerificationDate = PDTFactory.getCurrentLocalDateTime ();

    // Search the certificate from the request matching our required issuers
    X509Certificate aClientCertToVerify = null;
    {
      for (final X509Certificate aCert : aRequestCerts)
      {
        final X500Principal aIssuer = aCert.getIssuerX500Principal ();
        if (s_aSearchIssuers.contains (aIssuer))
        {
          if (LOGGER.isInfoEnabled ())
            LOGGER.info (sLogPrefix +
                         "  Using the following client certificate issuer for verification: '" +
                         aIssuer +
                         "'");
          aClientCertToVerify = aCert;
          break;
        }
      }
      // Do we have a certificate to verify?
      if (aClientCertToVerify == null)
      {
        throw new IllegalStateException ("Found no client certificate that was issued by one of the " +
                                         s_aSearchIssuers.size () +
                                         " required issuers. Provided certs are: " +
                                         Arrays.toString (aRequestCerts));
      }
    }

    final String sClientID = getClientUniqueID (aClientCertToVerify);

    // This is the main verification process against the PEPPOL SMP root
    // certificate
    for (final X509Certificate aRootCert : s_aPeppolSMPRootCerts)
    {
      final String sVerifyErrorMsg = _verifyCertificate (aClientCertToVerify, aRootCert, aCRLs, aVerificationDate);
      if (sVerifyErrorMsg == null)
      {
        if (LOGGER.isInfoEnabled ())
          LOGGER.info (sLogPrefix + "  Passed client certificate is valid");
        return ClientCertificateValidationResult.createSuccess (sClientID);
      }
    }

    if (LOGGER.isWarnEnabled ())
      LOGGER.warn ("Client certificate is invalid: " + sClientID);
    return ClientCertificateValidationResult.createFailure ();
  }
1283481
public static void assertValidNode(MetadataStore metadataStore, Integer nodeId) {
        if(!metadataStore.getCluster().hasNodeWithId(nodeId)) {
            throw new InvalidMetadataException("NodeId " + nodeId + " is not or no longer in this cluster");
        }
    }
317958
public static void validateMetadata(Map<String, String> metadata) throws ServiceException {
        for ( String key : metadata.keySet()){
            if (!validateRequiredField(key, metaKeyRegEx)){
               throw new ServiceException(
                    ErrorCode.SERVICE_INSTANCE_METAKEY_FORMAT_ERROR,
                    ErrorCode.SERVICE_INSTANCE_METAKEY_FORMAT_ERROR.getMessageTemplate(),key
               );
            }
        }

    }