nifi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From olegz <...@git.apache.org>
Subject [GitHub] nifi pull request: NIFI-1727: Refactored logic for merging HTTP Re...
Date Sun, 17 Apr 2016 18:01:09 GMT
Github user olegz commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/338#discussion_r59989329
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/coordination/http/endpoints/ControllerServiceEndpointMerger.java
---
    @@ -0,0 +1,145 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.nifi.cluster.coordination.http.endpoints;
    +
    +import java.net.URI;
    +import java.util.HashMap;
    +import java.util.Map;
    +import java.util.Set;
    +import java.util.regex.Pattern;
    +
    +import org.apache.nifi.cluster.manager.NodeResponse;
    +import org.apache.nifi.cluster.protocol.NodeIdentifier;
    +import org.apache.nifi.controller.service.ControllerServiceState;
    +import org.apache.nifi.web.api.dto.ControllerServiceDTO;
    +import org.apache.nifi.web.api.dto.ControllerServiceReferencingComponentDTO;
    +import org.apache.nifi.web.api.entity.ControllerServiceEntity;
    +
    +public class ControllerServiceEndpointMerger extends AbstractSingleEntityEndpoint<ControllerServiceEntity,
ControllerServiceDTO> {
    +    public static final String CONTROLLER_SERVICES_URI = "/nifi-api/controller/controller-services/node";
    +    public static final Pattern CONTROLLER_SERVICE_URI_PATTERN = Pattern.compile("/nifi-api/controller/controller-services/node/[a-f0-9\\-]{36}");
    +
    +    @Override
    +    public boolean canHandle(URI uri, String method) {
    +        if (("GET".equalsIgnoreCase(method) || "PUT".equalsIgnoreCase(method)) &&
CONTROLLER_SERVICE_URI_PATTERN.matcher(uri.getPath()).matches()) {
    +            return true;
    +        } else if ("POST".equalsIgnoreCase(method) && CONTROLLER_SERVICES_URI.equals(uri.getPath()))
{
    +            return true;
    +        }
    +
    +        return false;
    +    }
    +
    +    @Override
    +    protected Class<ControllerServiceEntity> getEntityClass() {
    +        return ControllerServiceEntity.class;
    +    }
    +
    +    @Override
    +    protected ControllerServiceDTO getDto(ControllerServiceEntity entity) {
    +        return entity.getControllerService();
    +    }
    +
    +    @Override
    +    protected void mergeResponses(ControllerServiceDTO clientDto, Map<NodeIdentifier,
ControllerServiceDTO> dtoMap, Set<NodeResponse> successfulResponses, Set<NodeResponse>
problematicResponses) {
    +        final Map<String, Set<NodeIdentifier>> validationErrorMap = new HashMap<>();
    +        final Set<ControllerServiceReferencingComponentDTO> referencingComponents
= clientDto.getReferencingComponents();
    +        final Map<NodeIdentifier, Set<ControllerServiceReferencingComponentDTO>>
nodeReferencingComponentsMap = new HashMap<>();
    +
    +        String state = null;
    +        for (final Map.Entry<NodeIdentifier, ControllerServiceDTO> nodeEntry :
dtoMap.entrySet()) {
    +            final NodeIdentifier nodeId = nodeEntry.getKey();
    +            final ControllerServiceDTO nodeControllerService = nodeEntry.getValue();
    +
    +            if (state == null) {
    +                if (ControllerServiceState.DISABLING.name().equals(nodeControllerService.getState()))
{
    +                    state = ControllerServiceState.DISABLING.name();
    +                } else if (ControllerServiceState.ENABLING.name().equals(nodeControllerService.getState()))
{
    +                    state = ControllerServiceState.ENABLING.name();
    +                }
    +            }
    --- End diff --
    
    Also, regardless of the answer on the previous comment, wouldn't the above be the same
as
    ```
    if (state == null) {
        state = nodeControllerService.getState().name();
    }
    ```
    Also, just noticed; Are you performing _equals_ on String vs ControllerServiceState? I
mean the above IF has no chance to be true


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message