Search in sources :

Example 11 with StringUtils.isEmpty

use of org.apache.commons.lang3.StringUtils.isEmpty in project azure-gradle-plugins by lenala.

the class AnnotationHandlerImpl method patchStorageBinding.

private void patchStorageBinding(final Method method, final List<BaseBinding> bindings) {
    final Optional<Annotation> storageAccount = Arrays.stream(method.getAnnotations()).filter(a -> a instanceof StorageAccount).findFirst();
    if (storageAccount.isPresent()) {
        logger.quiet("StorageAccount annotation found.");
        final String connectionString = ((StorageAccount) storageAccount.get()).value();
        bindings.stream().forEach(b -> {
            if (b instanceof StorageBaseBinding) {
                final StorageBaseBinding sb = (StorageBaseBinding) b;
                // Override storage bindings with empty connection
                if (StringUtils.isEmpty(sb.getConnection())) {
                    sb.setConnection(connectionString);
                }
            }
        });
    } else {
        logger.quiet("No StorageAccount annotation found.");
    }
}
Also used : StorageBaseBinding(com.microsoft.azure.gradle.functions.bindings.StorageBaseBinding) Arrays(java.util.Arrays) URL(java.net.URL) HttpBinding(com.microsoft.azure.gradle.functions.bindings.HttpBinding) HashMap(java.util.HashMap) Reflections(org.reflections.Reflections) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Logger(org.gradle.api.logging.Logger) ArrayList(java.util.ArrayList) StorageAccount(com.microsoft.azure.serverless.functions.annotation.StorageAccount) URLClassLoader(java.net.URLClassLoader) HttpTrigger(com.microsoft.azure.serverless.functions.annotation.HttpTrigger) Parameter(java.lang.reflect.Parameter) Map(java.util.Map) MethodAnnotationsScanner(org.reflections.scanners.MethodAnnotationsScanner) Method(java.lang.reflect.Method) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) BaseBinding(com.microsoft.azure.gradle.functions.bindings.BaseBinding) FunctionConfiguration(com.microsoft.azure.gradle.functions.configuration.FunctionConfiguration) Set(java.util.Set) List(java.util.List) FunctionName(com.microsoft.azure.serverless.functions.annotation.FunctionName) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) BindingFactory(com.microsoft.azure.gradle.functions.bindings.BindingFactory) StorageAccount(com.microsoft.azure.serverless.functions.annotation.StorageAccount) StorageBaseBinding(com.microsoft.azure.gradle.functions.bindings.StorageBaseBinding) Annotation(java.lang.annotation.Annotation)

Example 12 with StringUtils.isEmpty

use of org.apache.commons.lang3.StringUtils.isEmpty in project mule by mulesoft.

the class DefaultArtifactClassLoaderFilter method exportsClass.

@Override
public boolean exportsClass(String className) {
    checkArgument(!StringUtils.isEmpty(className), "Class name cannot be empty");
    final String packageName = getPackageName(className);
    return exportedClassPackages.contains(packageName);
}
Also used : ToStringBuilder.reflectionToString(org.apache.commons.lang3.builder.ToStringBuilder.reflectionToString)

Example 13 with StringUtils.isEmpty

use of org.apache.commons.lang3.StringUtils.isEmpty in project cloudbreak by hortonworks.

the class AmbariStackDetailsJsonToStackRepoDetailsConverter method convert.

@Override
public StackRepoDetails convert(AmbariStackDetailsJson source) {
    StackRepoDetails repo = new StackRepoDetails();
    Map<String, String> stack = new HashMap<>();
    Map<String, String> util = new HashMap<>();
    boolean baseRepoRequiredFieldsExists = Stream.of(source.getStackRepoId(), source.getStackBaseURL(), source.getUtilsRepoId(), source.getUtilsBaseURL()).noneMatch(StringUtils::isEmpty);
    if (!isVdfRequiredFieldsExists(source) && !baseRepoRequiredFieldsExists) {
        String msg = "The 'repositoryVersion', 'versionDefinitionFileUrl' or " + "'stackBaseURL', 'stackRepoId', 'utilsBaseUrl', 'utilsRepoId' fields must be specified!";
        throw new BadRequestException(msg);
    }
    stack.put("repoid", source.getStackRepoId());
    util.put("repoid", source.getUtilsRepoId());
    if (baseRepoRequiredFieldsExists) {
        String stackBaseURL = source.getStackBaseURL();
        String utilsBaseURL = source.getUtilsBaseURL();
        if (source.getOs() == null) {
            stack.put(REDHAT_6, stackBaseURL);
            stack.put(REDHAT_7, stackBaseURL);
            stack.put(DEBIAN_9, stackBaseURL);
            stack.put(UBUNTU_16, stackBaseURL);
            util.put(REDHAT_6, utilsBaseURL);
            util.put(REDHAT_7, utilsBaseURL);
            util.put(DEBIAN_9, utilsBaseURL);
            util.put(UBUNTU_16, utilsBaseURL);
        } else {
            stack.put(source.getOs(), stackBaseURL);
            util.put(source.getOs(), utilsBaseURL);
        }
    }
    if (!StringUtils.isEmpty(source.getRepositoryVersion())) {
        stack.put(StackRepoDetails.REPOSITORY_VERSION, source.getRepositoryVersion());
        stack.put("repoid", source.getStack());
    }
    if (!StringUtils.isEmpty(source.getVersionDefinitionFileUrl())) {
        stack.put(StackRepoDetails.CUSTOM_VDF_REPO_KEY, source.getVersionDefinitionFileUrl());
    }
    if (!StringUtils.isEmpty(source.getMpackUrl())) {
        stack.put(StackRepoDetails.MPACK_TAG, source.getMpackUrl());
    }
    repo.setStack(stack);
    repo.setUtil(util);
    repo.setEnableGplRepo(source.isEnableGplRepo());
    repo.setVerify(source.getVerify());
    repo.setHdpVersion(source.getVersion());
    return repo;
}
Also used : StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Example 14 with StringUtils.isEmpty

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

the class CreateDeploymentForm method doOKAction.

@Override
protected void doOKAction() {
    deploymentName = deploymentNameTextField.getText();
    final AzureString title = AzureOperationBundle.title("arm|deployment.deploy", deploymentName);
    AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
        EventUtil.executeWithLog(TelemetryConstants.ARM, TelemetryConstants.CREATE_DEPLOYMENT, (operation -> {
            Subscription subs = (Subscription) subscriptionCb.getSelectedItem();
            com.microsoft.azure.management.Azure azure = AuthMethodManager.getInstance().getAzureClient(subs.getId());
            WithTemplate template;
            if (createNewRgButton.isSelected()) {
                rgName = rgNameTextFiled.getText();
                final Region region = (Region) regionCb.getSelectedItem();
                template = azure.deployments().define(deploymentName).withNewResourceGroup(rgNameTextFiled.getText(), com.microsoft.azure.management.resources.fluentcore.arm.Region.fromName(region.getName()));
            } else {
                ResourceGroup rg = (ResourceGroup) rgNameCb.getSelectedItem();
                List<ResourceEx<Deployment>> deployments = AzureMvpModel.getInstance().getDeploymentByRgName(subs.getId(), rg.getName());
                boolean isExist = deployments.parallelStream().anyMatch(deployment -> deployment.getResource().name().equals(deploymentName));
                if (isExist) {
                    throw new RuntimeException(DUPLICATED_DEPLOYMENT_NAME);
                }
                rgName = rg.getName();
                template = azure.deployments().define(deploymentName).withExistingResourceGroup(rg.getName());
            }
            String fileText = templateTextField.getText();
            String content = IOUtils.toString(new FileReader(fileText));
            String parametersPath = parametersTextField.getText();
            String parameters = StringUtils.isEmpty(parametersPath) ? "{}" : IOUtils.toString(new FileReader(parametersPath));
            parameters = DeploymentUtils.parseParameters(parameters);
            template.withTemplate(content).withParameters(parameters).withMode(DeploymentMode.INCREMENTAL).create();
            UIUtils.showNotification(statusBar, NOTIFY_CREATE_DEPLOYMENT_SUCCESS, MessageType.INFO);
            updateUI();
        }), (ex) -> {
            UIUtils.showNotification(statusBar, NOTIFY_CREATE_DEPLOYMENT_FAIL + ", " + ex.getMessage(), MessageType.ERROR);
            updateUI();
        });
    }));
    close(DialogWrapper.OK_EXIT_CODE, true);
}
Also used : AuthMethodManager(com.microsoft.azuretools.authmanage.AuthMethodManager) Azure(com.microsoft.azure.toolkit.lib.Azure) NOTIFY_CREATE_DEPLOYMENT_FAIL(com.microsoft.azure.toolkit.intellij.arm.action.CreateDeploymentAction.NOTIFY_CREATE_DEPLOYMENT_FAIL) MessageType(com.intellij.openapi.ui.MessageType) SimpleListCellRenderer(com.intellij.ui.SimpleListCellRenderer) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) StringUtils(org.apache.commons.lang3.StringUtils) HyperlinkLabel(com.intellij.ui.HyperlinkLabel) NOTIFY_CREATE_DEPLOYMENT_SUCCESS(com.microsoft.azure.toolkit.intellij.arm.action.CreateDeploymentAction.NOTIFY_CREATE_DEPLOYMENT_SUCCESS) StatusBar(com.intellij.openapi.wm.StatusBar) WithTemplate(com.microsoft.azure.management.resources.Deployment.DefinitionStages.WithTemplate) ResourceManagementNode(com.microsoft.tooling.msservices.serviceexplorer.azure.arm.ResourceManagementNode) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) JComboBox(javax.swing.JComboBox) ResourceEx(com.microsoft.azuretools.core.mvp.model.ResourceEx) WindowManager(com.intellij.openapi.wm.WindowManager) JRadioButton(javax.swing.JRadioButton) RegionComboBox(com.microsoft.azure.toolkit.intellij.common.component.RegionComboBox) IOUtils(org.apache.commons.io.IOUtils) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) AzureMvpModel(com.microsoft.azuretools.core.mvp.model.AzureMvpModel) EventUtil(com.microsoft.azuretools.telemetrywrapper.EventUtil) JPanel(javax.swing.JPanel) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) FileChooserDescriptorFactory(com.intellij.openapi.fileChooser.FileChooserDescriptorFactory) JTextField(javax.swing.JTextField) AzureUIRefreshCore(com.microsoft.azuretools.utils.AzureUIRefreshCore) AzureOperationBundle(com.microsoft.azure.toolkit.lib.common.operation.AzureOperationBundle) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) Region(com.microsoft.azure.toolkit.lib.common.model.Region) DeploymentMode(com.microsoft.azure.management.resources.DeploymentMode) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Project(com.intellij.openapi.project.Project) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) JComponent(javax.swing.JComponent) Deployment(com.microsoft.azure.management.resources.Deployment) ButtonGroup(javax.swing.ButtonGroup) UIUtils(com.microsoft.intellij.ui.util.UIUtils) AzureUIRefreshEvent(com.microsoft.azuretools.utils.AzureUIRefreshEvent) JList(javax.swing.JList) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup) EventType(com.microsoft.azuretools.telemetrywrapper.EventType) TelemetryConstants(com.microsoft.azuretools.telemetry.TelemetryConstants) JLabel(javax.swing.JLabel) FileReader(java.io.FileReader) SubscriptionComboBox(com.microsoft.azure.toolkit.intellij.common.component.SubscriptionComboBox) BROWSE_TEMPLATE_SAMPLES(com.microsoft.azuretools.telemetry.TelemetryConstants.BROWSE_TEMPLATE_SAMPLES) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) WithTemplate(com.microsoft.azure.management.resources.Deployment.DefinitionStages.WithTemplate) Region(com.microsoft.azure.toolkit.lib.common.model.Region) FileReader(java.io.FileReader) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) ResourceEx(com.microsoft.azuretools.core.mvp.model.ResourceEx) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)

Example 15 with StringUtils.isEmpty

use of org.apache.commons.lang3.StringUtils.isEmpty in project storm by apache.

the class LogviewerLogSearchHandler method deepSearchLogsForTopology.

/**
 * Advanced search across worker log files in a topology.
 *
 * @param topologyId topology ID
 * @param user username
 * @param search search string
 * @param numMatchesStr the count of maximum matches. Note that this number is with respect to each port, not to each log or each search
 *     request
 * @param portStr worker port, null or '*' if the request wants to search from all worker logs
 * @param fileOffsetStr index (offset) of the log files
 * @param offsetStr start offset for log file
 * @param searchArchived true if the request wants to search also archived files, false if not
 * @param callback callbackParameterName for JSONP
 * @param origin origin
 * @return Response containing JSON content representing search result
 */
public Response deepSearchLogsForTopology(String topologyId, String user, String search, String numMatchesStr, String portStr, String fileOffsetStr, String offsetStr, Boolean searchArchived, String callback, String origin) throws IOException {
    int numMatchedFiles = 0;
    int numScannedFiles = 0;
    Path rootDir = logRoot;
    Path absTopoDir = rootDir.resolve(topologyId).toAbsolutePath().normalize();
    Object returnValue;
    if (StringUtils.isEmpty(search) || !absTopoDir.toFile().exists() || !absTopoDir.startsWith(rootDir)) {
        returnValue = new ArrayList<>();
    } else {
        int fileOffset = ObjectReader.getInt(fileOffsetStr, 0);
        int offset = ObjectReader.getInt(offsetStr, 0);
        int numMatches = ObjectReader.getInt(numMatchesStr, 1);
        if (StringUtils.isEmpty(portStr) || portStr.equals("*")) {
            try (Stream<Path> topoDir = Files.list(absTopoDir)) {
                // check for all ports
                Stream<List<Path>> portsOfLogs = topoDir.map(portDir -> logsForPort(user, portDir)).filter(logs -> logs != null && !logs.isEmpty());
                if (BooleanUtils.isNotTrue(searchArchived)) {
                    portsOfLogs = portsOfLogs.map(fl -> Collections.singletonList(first(fl)));
                }
                final List<Matched> matchedList = portsOfLogs.map(logs -> findNMatches(logs, numMatches, 0, 0, search)).collect(toList());
                numMatchedFiles = matchedList.stream().mapToInt(match -> match.getMatches().size()).sum();
                numScannedFiles = matchedList.stream().mapToInt(match -> match.openedFiles).sum();
                returnValue = matchedList;
            }
        } else {
            int port = Integer.parseInt(portStr);
            // check just the one port
            @SuppressWarnings("unchecked") List<Integer> slotsPorts = SupervisorUtils.getSlotsPorts(stormConf);
            boolean containsPort = slotsPorts.stream().anyMatch(slotPort -> slotPort != null && (slotPort == port));
            if (!containsPort) {
                returnValue = new ArrayList<>();
            } else {
                Path absPortDir = absTopoDir.resolve(Integer.toString(port)).toAbsolutePath().normalize();
                if (!absPortDir.toFile().exists() || !absPortDir.startsWith(absTopoDir)) {
                    returnValue = new ArrayList<>();
                } else {
                    List<Path> filteredLogs = logsForPort(user, absPortDir);
                    if (BooleanUtils.isNotTrue(searchArchived)) {
                        filteredLogs = Collections.singletonList(first(filteredLogs));
                        fileOffset = 0;
                    }
                    returnValue = findNMatches(filteredLogs, numMatches, fileOffset, offset, search);
                    numMatchedFiles = ((Matched) returnValue).getMatches().size();
                    numScannedFiles = ((Matched) returnValue).openedFiles;
                }
            }
        }
    }
    if (numMatchedFiles == 0) {
        numDeepSearchNoResult.mark();
    }
    numFileScanned.update(numScannedFiles);
    return LogviewerResponseBuilder.buildSuccessJsonResponse(returnValue, callback, origin);
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) GZIPInputStream(java.util.zip.GZIPInputStream) StringUtils(org.apache.commons.lang.StringUtils) BufferedInputStream(java.io.BufferedInputStream) PathUtil.truncatePathToLastElements(org.apache.storm.daemon.utils.PathUtil.truncatePathToLastElements) ListFunctionalSupport.rest(org.apache.storm.daemon.utils.ListFunctionalSupport.rest) LoggerFactory(org.slf4j.LoggerFactory) FileTime(java.nio.file.attribute.FileTime) LogviewerConstant(org.apache.storm.daemon.logviewer.LogviewerConstant) ByteBuffer(java.nio.ByteBuffer) BooleanUtils(org.apache.commons.lang.BooleanUtils) Pair(org.apache.commons.lang3.tuple.Pair) DaemonConfig(org.apache.storm.DaemonConfig) Map(java.util.Map) ListFunctionalSupport.drop(org.apache.storm.daemon.utils.ListFunctionalSupport.drop) ExceptionMeterNames(org.apache.storm.daemon.logviewer.utils.ExceptionMeterNames) Path(java.nio.file.Path) UrlBuilder(org.apache.storm.daemon.utils.UrlBuilder) Unchecked(org.jooq.lambda.Unchecked) LogviewerResponseBuilder(org.apache.storm.daemon.logviewer.utils.LogviewerResponseBuilder) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) Pattern(java.util.regex.Pattern) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidRequestException(org.apache.storm.daemon.ui.InvalidRequestException) Histogram(com.codahale.metrics.Histogram) ListFunctionalSupport.last(org.apache.storm.daemon.utils.ListFunctionalSupport.last) JSONAware(org.json.simple.JSONAware) HashMap(java.util.HashMap) SupervisorUtils(org.apache.storm.daemon.supervisor.SupervisorUtils) ArrayList(java.util.ArrayList) Meter(com.codahale.metrics.Meter) DirectoryCleaner(org.apache.storm.daemon.logviewer.utils.DirectoryCleaner) ServerUtils(org.apache.storm.utils.ServerUtils) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) ResourceAuthorizer(org.apache.storm.daemon.logviewer.utils.ResourceAuthorizer) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) Logger(org.slf4j.Logger) ListFunctionalSupport.first(org.apache.storm.daemon.utils.ListFunctionalSupport.first) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Utils(org.apache.storm.utils.Utils) UnknownHostException(java.net.UnknownHostException) WorkerLogs(org.apache.storm.daemon.logviewer.utils.WorkerLogs) StreamUtil(org.apache.storm.daemon.utils.StreamUtil) Collectors.toList(java.util.stream.Collectors.toList) ObjectReader(org.apache.storm.utils.ObjectReader) JsonResponseBuilder(org.apache.storm.daemon.common.JsonResponseBuilder) Paths(java.nio.file.Paths) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Collections(java.util.Collections) InputStream(java.io.InputStream) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList)

Aggregations

StringUtils (org.apache.commons.lang3.StringUtils)76 List (java.util.List)53 Collectors (java.util.stream.Collectors)40 ArrayList (java.util.ArrayList)39 Map (java.util.Map)39 HashMap (java.util.HashMap)28 IOException (java.io.IOException)26 Collections (java.util.Collections)25 Set (java.util.Set)25 Logger (org.slf4j.Logger)25 Arrays (java.util.Arrays)24 LoggerFactory (org.slf4j.LoggerFactory)24 Optional (java.util.Optional)22 HashSet (java.util.HashSet)18 Collection (java.util.Collection)14 Autowired (org.springframework.beans.factory.annotation.Autowired)13 Objects (java.util.Objects)12 UUID (java.util.UUID)11 java.util (java.util)10 Component (org.springframework.stereotype.Component)10