Search in sources :

Example 41 with ImmutablePair

use of org.apache.commons.lang3.tuple.ImmutablePair in project azure-tools-for-java by Microsoft.

the class StorageModule method refreshItems.

@Override
protected void refreshItems() throws AzureCmdException {
    List<Pair<String, String>> failedSubscriptions = new ArrayList<>();
    try {
        AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
        // not signed in
        if (azureManager == null) {
            return;
        }
        SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager();
        Set<String> sidList = subscriptionManager.getAccountSidList();
        for (String sid : sidList) {
            try {
                Azure azure = azureManager.getAzure(sid);
                List<com.microsoft.azure.management.storage.StorageAccount> storageAccounts = azure.storageAccounts().list();
                for (StorageAccount sm : storageAccounts) {
                    addChildNode(new StorageNode(this, sid, sm));
                }
            } catch (Exception ex) {
                failedSubscriptions.add(new ImmutablePair<>(sid, ex.getMessage()));
                continue;
            }
        }
    } catch (Exception ex) {
        DefaultLoader.getUIHelper().logError("An error occurred when trying to load Storage Accounts\n\n" + ex.getMessage(), ex);
    }
    // load External Accounts
    for (ClientStorageAccount clientStorageAccount : ExternalStorageHelper.getList(getProject())) {
        ClientStorageAccount storageAccount = StorageClientSDKManager.getManager().getStorageAccount(clientStorageAccount.getConnectionString());
    //            addChildNode(new ExternalStorageNode(this, storageAccount));
    }
    if (!failedSubscriptions.isEmpty()) {
        StringBuilder errorMessage = new StringBuilder("An error occurred when trying to load Storage Accounts for the subscriptions:\n\n");
        for (Pair error : failedSubscriptions) {
            errorMessage.append(error.getKey()).append(": ").append(error.getValue()).append("\n");
        }
        DefaultLoader.getUIHelper().logError("An error occurred when trying to load Storage Accounts\n\n" + errorMessage.toString(), null);
    }
}
Also used : Azure(com.microsoft.azure.management.Azure) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) ArrayList(java.util.ArrayList) ClientStorageAccount(com.microsoft.tooling.msservices.model.storage.ClientStorageAccount) SubscriptionManager(com.microsoft.azuretools.authmanage.SubscriptionManager) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) StorageAccount(com.microsoft.azure.management.storage.StorageAccount) ClientStorageAccount(com.microsoft.tooling.msservices.model.storage.ClientStorageAccount) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Pair(org.apache.commons.lang3.tuple.Pair)

Example 42 with ImmutablePair

use of org.apache.commons.lang3.tuple.ImmutablePair in project asterixdb by apache.

the class LicenseMojo method addDependencyToLicenseMap.

private void addDependencyToLicenseMap(MavenProject depProject, List<Pair<String, String>> depLicenses, String depLocation) {
    final String depGav = toGav(depProject);
    getLog().debug("adding " + depGav + ", location: " + depLocation);
    final MutableBoolean usedMetric = new MutableBoolean(false);
    if (depLicenses.size() > 1) {
        Collections.sort(depLicenses, (o1, o2) -> {
            final int metric1 = getLicenseMetric(o1.getLeft());
            final int metric2 = getLicenseMetric(o2.getLeft());
            usedMetric.setValue(usedMetric.booleanValue() || metric1 != LicenseSpec.UNDEFINED_LICENSE_METRIC || metric2 != LicenseSpec.UNDEFINED_LICENSE_METRIC);
            return Integer.compare(metric1, metric2);
        });
        if (usedMetric.booleanValue()) {
            getLog().info("Multiple licenses for " + depGav + ": " + depLicenses + "; taking lowest metric: " + depLicenses.get(0));
        } else {
            getLog().warn("Multiple licenses for " + depGav + ": " + depLicenses + "; taking first listed: " + depLicenses.get(0));
        }
    } else if (depLicenses.isEmpty()) {
        getLog().info("no license defined in model for " + depGav);
        depLicenses.add(new ImmutablePair<>("MISSING_LICENSE", null));
    }
    Pair<String, String> key = depLicenses.get(0);
    String licenseUrl = key.getLeft();
    final String displayName = key.getRight();
    if (!urlToLicenseMap.containsKey(licenseUrl)) {
        // assuming we've not already mapped it, annotate the URL with artifact info, if not an actual URL
        try {
            getLog().debug("- URL: " + new URL(licenseUrl));
        // life is good
        } catch (MalformedURLException e) {
            // we encounter this a lot.  Log a warning, and use an annotated key
            final String fakeLicenseUrl = depGav.replaceAll(":", "--") + "_" + licenseUrl;
            getLog().info("- URL for " + depGav + " is malformed: " + licenseUrl + "; using: " + fakeLicenseUrl);
            licenseUrl = fakeLicenseUrl;
        }
    }
    addProject(new Project(depProject, depLocation, depProject.getArtifact().getFile()), new LicenseSpec(licenseUrl, displayName), true);
}
Also used : Project(org.apache.hyracks.maven.license.project.Project) MavenProject(org.apache.maven.project.MavenProject) MalformedURLException(java.net.MalformedURLException) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) URL(java.net.URL)

Example 43 with ImmutablePair

use of org.apache.commons.lang3.tuple.ImmutablePair in project asterixdb by apache.

the class LicenseMojo method gatherProjectDependencies.

private void gatherProjectDependencies(MavenProject project, Map<MavenProject, List<Pair<String, String>>> dependencyLicenseMap, Map<String, MavenProject> dependencyGavMap) throws ProjectBuildingException {
    final Set dependencyArtifacts = project.getArtifacts();
    if (dependencyArtifacts != null) {
        for (Object depArtifactObj : dependencyArtifacts) {
            final Artifact depArtifact = (Artifact) depArtifactObj;
            if (!excludedScopes.contains(depArtifact.getScope())) {
                MavenProject dep = resolveDependency(depArtifact);
                dep.setArtifact(depArtifact);
                dependencyGavMap.put(toGav(dep), dep);
                List<Pair<String, String>> licenseUrls = new ArrayList<>();
                for (Object license : dep.getLicenses()) {
                    final License license1 = (License) license;
                    String url = license1.getUrl() != null ? license1.getUrl() : (license1.getName() != null ? license1.getName() : "LICENSE_EMPTY_NAME_URL");
                    licenseUrls.add(new ImmutablePair<>(url, license1.getName()));
                }
                dependencyLicenseMap.put(dep, licenseUrls);
            }
        }
    }
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) MavenProject(org.apache.maven.project.MavenProject) ArrayList(java.util.ArrayList) License(org.apache.maven.model.License) Artifact(org.apache.maven.artifact.Artifact) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Example 44 with ImmutablePair

use of org.apache.commons.lang3.tuple.ImmutablePair in project asterixdb by apache.

the class ZookeeperUtil method getProcessStreams.

private Pair<CharSequence, CharSequence> getProcessStreams(Process process) throws IOException {
    StringWriter stdout = new StringWriter();
    StringWriter stderr = new StringWriter();
    IOUtils.copy(process.getInputStream(), stdout, Charset.defaultCharset());
    IOUtils.copy(process.getErrorStream(), stderr, Charset.defaultCharset());
    return new ImmutablePair<>(stdout.getBuffer(), stderr.getBuffer());
}
Also used : StringWriter(java.io.StringWriter) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Example 45 with ImmutablePair

use of org.apache.commons.lang3.tuple.ImmutablePair in project disunity by ata4.

the class BundleHeader method read.

@Override
public void read(DataReader in) throws IOException {
    signature = in.readStringNull();
    streamVersion = in.readInt();
    unityVersion = new UnityVersion(in.readStringNull());
    unityRevision = new UnityVersion(in.readStringNull());
    if (signature.equals(SIGNATURE_FS)) {
        // FS signature
        // Expect streamVersion == 6
        completeFileSize = in.readLong();
        compressedDataHeaderSize = in.readInt();
        dataHeaderSize = in.readInt();
        flags = in.readInt();
        headerSize = (int) in.position();
        if ((flags & 0x80) == 0) {
            // The data header is part of the bundle header
            headerSize += compressedDataHeaderSize;
        }
    // else it's at the end of the file
    } else {
        // Web or Raw signature
        minimumStreamedBytes = in.readUnsignedInt();
        headerSize = in.readInt();
        numberOfLevelsToDownload = in.readInt();
        int numberOfLevels = in.readInt();
        levelByteEnd.clear();
        for (int i = 0; i < numberOfLevels; i++) {
            levelByteEnd.add(new ImmutablePair(in.readUnsignedInt(), in.readUnsignedInt()));
        }
        if (streamVersion >= 2) {
            completeFileSize = in.readUnsignedInt();
        }
        if (streamVersion >= 3) {
            dataHeaderSize = in.readUnsignedInt();
        }
        in.readByte();
    }
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) UnityVersion(info.ata4.junity.UnityVersion)

Aggregations

ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)415 ProcessResult (org.asqatasun.entity.audit.ProcessResult)125 Pair (org.apache.commons.lang3.tuple.Pair)65 ArrayList (java.util.ArrayList)64 Map (java.util.Map)39 HashMap (java.util.HashMap)36 List (java.util.List)35 Collectors (java.util.stream.Collectors)34 IOException (java.io.IOException)30 Test (org.junit.Test)27 ElementChecker (org.asqatasun.rules.elementchecker.ElementChecker)21 IntStream (java.util.stream.IntStream)20 File (java.io.File)19 java.util (java.util)18 ElementPresenceChecker (org.asqatasun.rules.elementchecker.element.ElementPresenceChecker)18 Set (java.util.Set)16 VisibleForTesting (com.google.common.annotations.VisibleForTesting)14 INDArray (org.nd4j.linalg.api.ndarray.INDArray)14 Collections (java.util.Collections)13 UserException (org.broadinstitute.hellbender.exceptions.UserException)11