Skip to content

Commit

Permalink
# This is a combination of 8 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:
nifi-toolkit-upgrade - shell scripts and classes to support upgrade and rollback of standalone and clustered nifi.

# This is the commit message apache#2:

nifi-toolkit-update - Refactored node manager to combine disconnect and delete function using other nodes when needed to submit request.

# This is the commit message apache#3:

nifi-toolkit-update - Refactored to use FileManagerTool

# This is the commit message apache#4:

nifi-toolkit-update - additional messaging, ensure any previous upgrade install is cleared before extracting

# This is the commit message apache#5:

nifi-toolkit-update - copy entire state directory to prevent disconnected "ghost" instances after upgrade

# This is the commit message apache#6:

nifi-toolkit-update - created bat files for windows support, migrated upgrade coordination to groovy class. you'll thank me later.

# This is the commit message apache#7:

nifi-toolkit-update - changed obtaining file permissions based on file type during extraction, updates to messaging in node manager, ensured that if server is not available when notification is sent then exception is logged yet upgrade/downgrade proceeds.

# This is the commit message apache#8:

nifi-toolkit-update - added -m flag to move repositories for install. catch excpeeptions from notification tool to allow to proceed.

# This is the commit message apache#9:

nifi-toolkit-update - changed version rule directory value, updated how rules are obtained for a given upgrade

# This is the commit message apache#10:

nifi-toolkit-update - fixes for windows

# This is the commit message apache#1:

nifi-toolkit-update - fixes for windows and to ensure directory copying works properly

# This is the commit message apache#2:

nifi-toolkit-update - so many fixes it's exhausting. I stay grinding

# This is the commit message apache#3:

nifi-toolkit-update - cluster testing changes

# This is the commit message apache#4:

nifi-toolkit-update - code cleanup, slight refactor to use abstract class

# This is the commit message apache#5:

nifi-toolkit-update - fix weird groovy package from build

# This is the commit message apache#6:

nifi-toolkit-update - lots of changes around versions and changes to fix logger

# This is the commit message apache#7:

nifi-toolkit-update - added supported versions consistently for all tools

# This is the commit message apache#8:

nifi-toolkit-update - added level support for notifications
  • Loading branch information
YolandaMDavis committed Apr 11, 2017
1 parent 7c19796 commit 088a884
Show file tree
Hide file tree
Showing 89 changed files with 6,909 additions and 1 deletion.
Expand Up @@ -21,12 +21,14 @@
import org.apache.nifi.web.api.dto.ReadablePermission;
import org.apache.nifi.web.api.dto.util.TimeAdapter;

import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.Date;

/**
* A serialized representation of this class can be placed in the entity body of a request or response to or from the API. This particular entity holds a reference to a BulletinDTO.
*/
@XmlRootElement(name = "bulletinEntity")
public class BulletinEntity extends Entity implements ReadablePermission {

private Long id;
Expand Down
Expand Up @@ -361,6 +361,10 @@ private void populateNodes(Authorizations authorizations, Tenants tenants) {
// grant access to the proxy resource
addAccessPolicy(authorizations, ResourceType.Proxy.getValue(), jaxbNodeUser.getIdentifier(), WRITE_CODE);

//grant access to controller resource
addAccessPolicy(authorizations, ResourceType.Controller.getValue(), jaxbNodeUser.getIdentifier(), READ_CODE);
addAccessPolicy(authorizations, ResourceType.Controller.getValue(), jaxbNodeUser.getIdentifier(), WRITE_CODE);

// grant the user read/write access data of the root group
if (rootGroupId != null) {
addAccessPolicy(authorizations, ResourceType.Data.getValue() + ResourceType.ProcessGroup.getValue() + "/" + rootGroupId, jaxbNodeUser.getIdentifier(), READ_CODE);
Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.apache.nifi.groups.ProcessGroup;
import org.apache.nifi.web.api.dto.AccessPolicyDTO;
import org.apache.nifi.web.api.dto.BulletinBoardDTO;
import org.apache.nifi.web.api.dto.BulletinDTO;
import org.apache.nifi.web.api.dto.BulletinQueryDTO;
import org.apache.nifi.web.api.dto.ClusterDTO;
import org.apache.nifi.web.api.dto.ComponentHistoryDTO;
Expand Down Expand Up @@ -66,6 +67,7 @@
import org.apache.nifi.web.api.dto.status.ControllerStatusDTO;
import org.apache.nifi.web.api.entity.AccessPolicyEntity;
import org.apache.nifi.web.api.entity.ActionEntity;
import org.apache.nifi.web.api.entity.BulletinEntity;
import org.apache.nifi.web.api.entity.ConnectionEntity;
import org.apache.nifi.web.api.entity.ConnectionStatusEntity;
import org.apache.nifi.web.api.entity.ControllerBulletinsEntity;
Expand Down Expand Up @@ -1049,6 +1051,15 @@ Set<DocumentedTypeDTO> getControllerServiceTypes(final String serviceType, final
*/
RemoteProcessGroupEntity deleteRemoteProcessGroup(Revision revision, String remoteProcessGroupId);


/**
* Create a system bulletin
*
* @param bulletinDTO bulletin to send to users
* @param canRead allow users to read bulletin
*/
BulletinEntity createBulletin(final BulletinDTO bulletinDTO, final Boolean canRead);

// ----------------------------------------
// Funnel methods
// ----------------------------------------
Expand Down
Expand Up @@ -78,6 +78,7 @@
import org.apache.nifi.controller.service.ControllerServiceState;
import org.apache.nifi.controller.status.ProcessGroupStatus;
import org.apache.nifi.diagnostics.SystemDiagnostics;
import org.apache.nifi.events.BulletinFactory;
import org.apache.nifi.groups.ProcessGroup;
import org.apache.nifi.groups.ProcessGroupCounts;
import org.apache.nifi.groups.RemoteProcessGroup;
Expand Down Expand Up @@ -1380,6 +1381,12 @@ private <D, C> RevisionUpdate<D> createComponent(final Revision revision, final
});
}

@Override
public BulletinEntity createBulletin(final BulletinDTO bulletinDTO, final Boolean canRead){
final Bulletin bulletin = BulletinFactory.createBulletin(bulletinDTO.getCategory(),bulletinDTO.getLevel(),bulletinDTO.getMessage());
bulletinRepository.addBulletin(bulletin);
return entityFactory.createBulletinEntity(dtoFactory.createBulletinDto(bulletin),canRead);
}

@Override
public FunnelEntity createFunnel(final Revision revision, final String groupId, final FunnelDTO funnelDTO) {
Expand Down
Expand Up @@ -40,10 +40,12 @@
import org.apache.nifi.web.IllegalClusterResourceRequestException;
import org.apache.nifi.web.NiFiServiceFacade;
import org.apache.nifi.web.Revision;
import org.apache.nifi.web.api.dto.BulletinDTO;
import org.apache.nifi.web.api.dto.ClusterDTO;
import org.apache.nifi.web.api.dto.ControllerServiceDTO;
import org.apache.nifi.web.api.dto.NodeDTO;
import org.apache.nifi.web.api.dto.ReportingTaskDTO;
import org.apache.nifi.web.api.entity.BulletinEntity;
import org.apache.nifi.web.api.entity.ClusterEntity;
import org.apache.nifi.web.api.entity.ControllerConfigurationEntity;
import org.apache.nifi.web.api.entity.ControllerServiceEntity;
Expand Down Expand Up @@ -261,6 +263,7 @@ public Response updateControllerConfig(
@ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.")
}
)

public Response createReportingTask(
@Context final HttpServletRequest httpServletRequest,
@ApiParam(
Expand Down Expand Up @@ -330,6 +333,71 @@ public Response createReportingTask(
);
}

/**
* Creates a Bulletin.
*
* @param httpServletRequest request
* @param requestBulletinEntity A bulletinEntity.
* @return A bulletinEntity.
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("bulletin")
@ApiOperation(
value = "Creates a new bulletin",
response = BulletinEntity.class,
authorizations = {
@Authorization(value = "Write - /controller", type = "")
}
)
@ApiResponses(
value = {
@ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."),
@ApiResponse(code = 401, message = "Client could not be authenticated."),
@ApiResponse(code = 403, message = "Client is not authorized to make this request."),
@ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.")
}
)
public Response createBulletin(
@Context final HttpServletRequest httpServletRequest,
@ApiParam(
value = "The reporting task configuration details.",
required = true
) final BulletinEntity requestBulletinEntity) {

if (requestBulletinEntity == null || requestBulletinEntity.getBulletin() == null) {
throw new IllegalArgumentException("Bulletin details must be specified.");
}

final BulletinDTO requestBulletin = requestBulletinEntity.getBulletin();
if (requestBulletin.getId() != null) {
throw new IllegalArgumentException("A bulletin ID cannot be specified.");
}

if (StringUtils.isBlank(requestBulletin.getMessage())) {
throw new IllegalArgumentException("The bulletin message must be specified.");
}

if (isReplicateRequest()) {
return replicate(HttpMethod.POST, requestBulletinEntity);
}

return withWriteLock(
serviceFacade,
requestBulletinEntity,
lookup -> {
authorizeController(RequestAction.WRITE);
},
null,
(bulletinEntity) -> {
final BulletinDTO bulletin = bulletinEntity.getBulletin();
final BulletinEntity entity = serviceFacade.createBulletin(bulletin,true);
return generateOkResponse(entity).build();
}
);
}

// -------------------
// controller services
// -------------------
Expand Down
Expand Up @@ -23,7 +23,11 @@ import org.apache.nifi.authorization.user.NiFiUser
import org.apache.nifi.authorization.user.StandardNiFiUser
import org.apache.nifi.authorization.user.NiFiUserDetails
import org.apache.nifi.controller.service.ControllerServiceProvider
import org.apache.nifi.reporting.Bulletin
import org.apache.nifi.reporting.BulletinRepository
import org.apache.nifi.reporting.ComponentType
import org.apache.nifi.web.api.dto.*
import org.apache.nifi.web.api.entity.BulletinEntity
import org.apache.nifi.web.api.entity.UserEntity
import org.apache.nifi.web.controller.ControllerFacade
import org.apache.nifi.web.dao.AccessPolicyDAO
Expand All @@ -36,7 +40,7 @@ import spock.lang.Ignore
import spock.lang.Specification
import spock.lang.Unroll

@Ignore

class StandardNiFiServiceFacadeSpec extends Specification {

def setup() {
Expand All @@ -49,6 +53,7 @@ class StandardNiFiServiceFacadeSpec extends Specification {
SecurityContextHolder.getContext().setAuthentication(null);
}

@Ignore
@Unroll
def "CreateUser: isAuthorized: #isAuthorized"() {
given:
Expand Down Expand Up @@ -87,6 +92,7 @@ class StandardNiFiServiceFacadeSpec extends Specification {
createUserDTO() | null | ResourceFactory.usersResource | false | AuthorizationResult.denied()
}

@Ignore
@Unroll
def "GetUser: isAuthorized: #isAuthorized"() {
given:
Expand Down Expand Up @@ -134,6 +140,7 @@ class StandardNiFiServiceFacadeSpec extends Specification {
createUserDTO() | false | AuthorizationResult.denied()
}

@Ignore
@Unroll
def "UpdateUser: isAuthorized: #isAuthorized, policy exists: #userExists"() {
given:
Expand Down Expand Up @@ -188,6 +195,7 @@ class StandardNiFiServiceFacadeSpec extends Specification {
true | new Revision(1L, 'client1', 'root') | createUserDTO() | false | AuthorizationResult.denied()
}

@Ignore
@Unroll
def "DeleteUser: isAuthorized: #isAuthorized, user exists: #userExists"() {
given:
Expand Down Expand Up @@ -239,6 +247,7 @@ class StandardNiFiServiceFacadeSpec extends Specification {
false | null | createUserDTO() | false | AuthorizationResult.denied()
}

@Ignore
@Unroll
def "CreateUserGroup: isAuthorized: #isAuthorized"() {
given:
Expand Down Expand Up @@ -307,6 +316,7 @@ class StandardNiFiServiceFacadeSpec extends Specification {
createUserGroupDTO() | false | [(ResourceFactory.userGroupsResource): AuthorizationResult.denied(), (ResourceFactory.usersResource): AuthorizationResult.denied()]
}

@Ignore
@Unroll
def "GetUserGroup: isAuthorized: #isAuthorized"() {
given:
Expand Down Expand Up @@ -363,6 +373,7 @@ class StandardNiFiServiceFacadeSpec extends Specification {
new UserGroupDTO(id: '1', name: 'test group', users: [createUserEntity()]) | false | AuthorizationResult.denied()
}

@Ignore
@Unroll
def "UpdateUserGroup: isAuthorized: #isAuthorized, userGroupExists exists: #userGroupExists"() {
given:
Expand Down Expand Up @@ -444,6 +455,7 @@ class StandardNiFiServiceFacadeSpec extends Specification {
[(ResourceFactory.userGroupsResource): AuthorizationResult.denied(), (ResourceFactory.usersResource): AuthorizationResult.denied()]
}

@Ignore
@Unroll
def "DeleteUserGroup: isAuthorized: #isAuthorized, userGroup exists: #userGroupExists"() {
given:
Expand Down Expand Up @@ -521,6 +533,7 @@ class StandardNiFiServiceFacadeSpec extends Specification {
[(ResourceFactory.userGroupsResource): AuthorizationResult.denied(), (ResourceFactory.usersResource): AuthorizationResult.denied()]
}

@Ignore
@Unroll
def "CreateAccessPolicy: #isAuthorized"() {
given:
Expand Down Expand Up @@ -589,6 +602,7 @@ class StandardNiFiServiceFacadeSpec extends Specification {
new AccessPolicyDTO(id: '1', resource: ResourceFactory.flowResource.identifier, users: [createUserEntity()], canRead: true) | false | AuthorizationResult.denied()
}

@Ignore
@Unroll
def "GetAccessPolicy: isAuthorized: #isAuthorized"() {
given:
Expand Down Expand Up @@ -654,6 +668,7 @@ class StandardNiFiServiceFacadeSpec extends Specification {
new AccessPolicyDTO(id: '1', resource: ResourceFactory.flowResource.identifier, users: [createUserEntity()], canRead: true) | false | AuthorizationResult.denied()
}

@Ignore
@Unroll
def "UpdateAccessPolicy: isAuthorized: #isAuthorized, policy exists: #hasPolicy"() {
given:
Expand Down Expand Up @@ -741,6 +756,7 @@ class StandardNiFiServiceFacadeSpec extends Specification {
AuthorizationResult.denied()
}

@Ignore
@Unroll
def "DeleteAccessPolicy: isAuthorized: #isAuthorized, hasPolicy: #hasPolicy"() {
given:
Expand Down Expand Up @@ -828,6 +844,44 @@ class StandardNiFiServiceFacadeSpec extends Specification {
AuthorizationResult.denied()
}


def "CreateBulletin Successfully"() {
given:

def entityFactory = new EntityFactory()
def dtoFactory = new DtoFactory()
dtoFactory.setEntityFactory entityFactory
def authorizableLookup = Mock AuthorizableLookup
def controllerFacade = Mock ControllerFacade
def niFiServiceFacade = new StandardNiFiServiceFacade()
def bulletinRepository = Mock BulletinRepository
niFiServiceFacade.setAuthorizableLookup authorizableLookup
niFiServiceFacade.setDtoFactory dtoFactory
niFiServiceFacade.setEntityFactory entityFactory
niFiServiceFacade.setControllerFacade controllerFacade
niFiServiceFacade.setBulletinRepository bulletinRepository

def bulletinDto = new BulletinDTO()
bulletinDto.category = "SYSTEM"
bulletinDto.message = "test system message"
bulletinDto.level = "WARN"
def bulletinEntity
def retBulletinEntity = new BulletinEntity()
retBulletinEntity.bulletin = bulletinDto

when:

bulletinEntity = niFiServiceFacade.createBulletin(bulletinDto,true)


then:
1 * bulletinRepository.addBulletin(_ as Bulletin)
bulletinEntity
bulletinEntity.bulletin.message == bulletinDto.message


}

private UserGroupDTO createUserGroupDTO() {
new UserGroupDTO(id: 'group-1', name: 'test group', users: [createUserEntity()] as Set)
}
Expand Down
4 changes: 4 additions & 0 deletions nifi-toolkit/nifi-toolkit-assembly/pom.xml
Expand Up @@ -72,6 +72,10 @@ language governing permissions and limitations under the License. -->
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-toolkit-s2s</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-toolkit-upgrade</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-toolkit-zookeeper-migrator</artifactId>
Expand Down
Expand Up @@ -45,6 +45,11 @@
<outputDirectory>conf/</outputDirectory>
<fileMode>0600</fileMode>
</fileSet>
<fileSet>
<directory>${project.basedir}/src/main/resources/rules</directory>
<outputDirectory>upgrade/rules/</outputDirectory>
<fileMode>0600</fileMode>
</fileSet>
<!--<fileSet>-->
<!--<directory>${project.build.directory}/nifi-resources/src/main/resources/conf</directory>-->
<!--<outputDirectory>conf/</outputDirectory>-->
Expand Down
@@ -0,0 +1,39 @@
@echo off
rem
rem Licensed to the Apache Software Foundation (ASF) under one or more
rem contributor license agreements. See the NOTICE file distributed with
rem this work for additional information regarding copyright ownership.
rem The ASF licenses this file to You under the Apache License, Version 2.0
rem (the "License"); you may not use this file except in compliance with
rem the License. You may obtain a copy of the License at
rem
rem http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.
rem

rem Use JAVA_HOME if it's set; otherwise, just use java

if "%JAVA_HOME%" == "" goto noJavaHome
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
set JAVA_EXE=%JAVA_HOME%\bin\java.exe
goto startConfig

:noJavaHome
echo The JAVA_HOME environment variable is not defined correctly.
echo Instead the PATH will be used to find the java executable.
echo.
set JAVA_EXE=java
goto startConfig

:startConfig
set LIB_DIR=%~dp0..\upgrade;%~dp0..\lib

SET JAVA_PARAMS=-cp %LIB_DIR%\* -Xms12m -Xmx24m %JAVA_ARGS% org.apache.nifi.toolkit.upgrade.configmigrator.ConfigMigrationTool

cmd.exe /C ""%JAVA_EXE%" %JAVA_PARAMS% %* ""

0 comments on commit 088a884

Please sign in to comment.