Search in sources :

Example 1 with OzoneManagerPrepareState

use of org.apache.hadoop.ozone.om.OzoneManagerPrepareState in project ozone by apache.

the class TestOMKeyRequest method setup.

@Before
public void setup() throws Exception {
    ozoneManager = Mockito.mock(OzoneManager.class);
    omMetrics = OMMetrics.create();
    OzoneConfiguration ozoneConfiguration = getOzoneConfiguration();
    ozoneConfiguration.set(OMConfigKeys.OZONE_OM_DB_DIRS, folder.newFolder().getAbsolutePath());
    ozoneConfiguration.set(OzoneConfigKeys.OZONE_METADATA_DIRS, folder.newFolder().getAbsolutePath());
    omMetadataManager = new OmMetadataManagerImpl(ozoneConfiguration);
    when(ozoneManager.getMetrics()).thenReturn(omMetrics);
    when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
    when(ozoneManager.getConfiguration()).thenReturn(ozoneConfiguration);
    OMLayoutVersionManager lvm = mock(OMLayoutVersionManager.class);
    when(lvm.getMetadataLayoutVersion()).thenReturn(0);
    when(ozoneManager.getVersionManager()).thenReturn(lvm);
    when(ozoneManager.isRatisEnabled()).thenReturn(true);
    auditLogger = Mockito.mock(AuditLogger.class);
    when(ozoneManager.getAuditLogger()).thenReturn(auditLogger);
    when(ozoneManager.isAdmin(any(String.class))).thenReturn(true);
    when(ozoneManager.isAdmin(any(UserGroupInformation.class))).thenReturn(true);
    Mockito.doNothing().when(auditLogger).logWrite(any(AuditMessage.class));
    scmClient = Mockito.mock(ScmClient.class);
    ozoneBlockTokenSecretManager = Mockito.mock(OzoneBlockTokenSecretManager.class);
    scmBlockLocationProtocol = Mockito.mock(ScmBlockLocationProtocol.class);
    keyManager = new KeyManagerImpl(ozoneManager, scmClient, ozoneConfiguration, "");
    when(ozoneManager.getScmClient()).thenReturn(scmClient);
    when(ozoneManager.getBlockTokenSecretManager()).thenReturn(ozoneBlockTokenSecretManager);
    when(ozoneManager.getScmBlockSize()).thenReturn(scmBlockSize);
    when(ozoneManager.getPreallocateBlocksMax()).thenReturn(2);
    when(ozoneManager.isGrpcBlockTokenEnabled()).thenReturn(false);
    when(ozoneManager.getOMNodeId()).thenReturn(UUID.randomUUID().toString());
    when(scmClient.getBlockClient()).thenReturn(scmBlockLocationProtocol);
    when(ozoneManager.getKeyManager()).thenReturn(keyManager);
    prepareState = new OzoneManagerPrepareState(ozoneConfiguration);
    when(ozoneManager.getPrepareState()).thenReturn(prepareState);
    Pipeline pipeline = Pipeline.newBuilder().setState(Pipeline.PipelineState.OPEN).setId(PipelineID.randomId()).setReplicationConfig(StandaloneReplicationConfig.getInstance(ReplicationFactor.ONE)).setNodes(new ArrayList<>()).build();
    AllocatedBlock allocatedBlock = new AllocatedBlock.Builder().setContainerBlockID(new ContainerBlockID(CONTAINER_ID, LOCAL_ID)).setPipeline(pipeline).build();
    List<AllocatedBlock> allocatedBlocks = new ArrayList<>();
    allocatedBlocks.add(allocatedBlock);
    when(scmBlockLocationProtocol.allocateBlock(anyLong(), anyInt(), any(), anyString(), any())).thenReturn(allocatedBlocks);
    volumeName = UUID.randomUUID().toString();
    bucketName = UUID.randomUUID().toString();
    keyName = UUID.randomUUID().toString();
    replicationFactor = HddsProtos.ReplicationFactor.ONE;
    replicationType = HddsProtos.ReplicationType.RATIS;
    clientID = Time.now();
    dataSize = 1000L;
    random = new Random();
    version = 0L;
    Pair<String, String> volumeAndBucket = Pair.of(volumeName, bucketName);
    when(ozoneManager.resolveBucketLink(any(KeyArgs.class), any(OMClientRequest.class))).thenReturn(new ResolvedBucket(volumeAndBucket, volumeAndBucket));
    when(ozoneManager.resolveBucketLink(any(Pair.class), any(OMClientRequest.class))).thenReturn(new ResolvedBucket(volumeAndBucket, volumeAndBucket));
}
Also used : AuditMessage(org.apache.hadoop.ozone.audit.AuditMessage) ArrayList(java.util.ArrayList) OzoneManagerPrepareState(org.apache.hadoop.ozone.om.OzoneManagerPrepareState) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) OMLayoutVersionManager(org.apache.hadoop.ozone.om.upgrade.OMLayoutVersionManager) Random(java.util.Random) OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) ContainerBlockID(org.apache.hadoop.hdds.client.ContainerBlockID) ResolvedBucket(org.apache.hadoop.ozone.om.ResolvedBucket) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Pair(org.apache.commons.lang3.tuple.Pair) OMClientRequest(org.apache.hadoop.ozone.om.request.OMClientRequest) AuditLogger(org.apache.hadoop.ozone.audit.AuditLogger) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) KeyArgs(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs) ScmClient(org.apache.hadoop.ozone.om.ScmClient) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) OmMetadataManagerImpl(org.apache.hadoop.ozone.om.OmMetadataManagerImpl) KeyManagerImpl(org.apache.hadoop.ozone.om.KeyManagerImpl) ScmBlockLocationProtocol(org.apache.hadoop.hdds.scm.protocol.ScmBlockLocationProtocol) AllocatedBlock(org.apache.hadoop.hdds.scm.container.common.helpers.AllocatedBlock) OzoneBlockTokenSecretManager(org.apache.hadoop.ozone.security.OzoneBlockTokenSecretManager) Before(org.junit.Before)

Example 2 with OzoneManagerPrepareState

use of org.apache.hadoop.ozone.om.OzoneManagerPrepareState in project ozone by apache.

the class TestOMCancelPrepareRequest method assertNotPrepared.

private void assertNotPrepared() {
    OzoneManagerPrepareState prepareState = ozoneManager.getPrepareState();
    OzoneManagerPrepareState.State state = prepareState.getState();
    Assert.assertEquals(state.getStatus(), PrepareStatus.NOT_PREPARED);
    Assert.assertEquals(state.getIndex(), OzoneManagerPrepareState.NO_PREPARE_INDEX);
    Assert.assertFalse(prepareState.getPrepareMarkerFile().exists());
    Assert.assertTrue(prepareState.requestAllowed(Type.CreateVolume));
}
Also used : OzoneManagerPrepareState(org.apache.hadoop.ozone.om.OzoneManagerPrepareState)

Example 3 with OzoneManagerPrepareState

use of org.apache.hadoop.ozone.om.OzoneManagerPrepareState in project ozone by apache.

the class TestOMCancelPrepareRequest method assertPrepared.

private void assertPrepared(long logIndex) {
    OzoneManagerPrepareState prepareState = ozoneManager.getPrepareState();
    OzoneManagerPrepareState.State state = prepareState.getState();
    Assert.assertEquals(state.getStatus(), PrepareStatus.PREPARE_COMPLETED);
    Assert.assertEquals(state.getIndex(), logIndex);
    Assert.assertTrue(prepareState.getPrepareMarkerFile().exists());
    Assert.assertFalse(prepareState.requestAllowed(Type.CreateVolume));
}
Also used : OzoneManagerPrepareState(org.apache.hadoop.ozone.om.OzoneManagerPrepareState)

Example 4 with OzoneManagerPrepareState

use of org.apache.hadoop.ozone.om.OzoneManagerPrepareState in project ozone by apache.

the class OzoneManagerStateMachine method preAppendTransaction.

@Override
public TransactionContext preAppendTransaction(TransactionContext trx) throws IOException {
    OMRequest request = OMRatisHelper.convertByteStringToOMRequest(trx.getStateMachineLogEntry().getLogData());
    OzoneManagerProtocolProtos.Type cmdType = request.getCmdType();
    OzoneManagerPrepareState prepareState = ozoneManager.getPrepareState();
    if (cmdType == OzoneManagerProtocolProtos.Type.Prepare) {
        // Must authenticate prepare requests here, since we must determine
        // whether or not to apply the prepare gate before proceeding with the
        // prepare request.
        String username = request.getUserInfo().getUserName();
        if (ozoneManager.getAclsEnabled() && !ozoneManager.isAdmin(username)) {
            String message = "Access denied for user " + username + ". " + "Superuser privilege is required to prepare ozone managers.";
            OMException cause = new OMException(message, OMException.ResultCodes.ACCESS_DENIED);
            // Leader should not step down because of this failure.
            throw new StateMachineException(message, cause, false);
        } else {
            prepareState.enablePrepareGate();
        }
    }
    // through.
    if (prepareState.requestAllowed(cmdType)) {
        return trx;
    } else {
        String message = "Cannot apply write request " + request.getCmdType().name() + " when OM is in prepare mode.";
        OMException cause = new OMException(message, OMException.ResultCodes.NOT_SUPPORTED_OPERATION_WHEN_PREPARED);
        // Indicate that the leader should not step down because of this failure.
        throw new StateMachineException(message, cause, false);
    }
}
Also used : OMRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) StateMachineException(org.apache.ratis.protocol.exceptions.StateMachineException) OzoneManagerProtocolProtos(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos) OzoneManagerPrepareState(org.apache.hadoop.ozone.om.OzoneManagerPrepareState) ByteString(org.apache.ratis.thirdparty.com.google.protobuf.ByteString) OMException(org.apache.hadoop.ozone.om.exceptions.OMException)

Example 5 with OzoneManagerPrepareState

use of org.apache.hadoop.ozone.om.OzoneManagerPrepareState in project ozone by apache.

the class TestOzoneManagerPrepareState method setup.

@Before
public void setup() throws Exception {
    OzoneConfiguration conf = new OzoneConfiguration();
    conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, folder.getRoot().getAbsolutePath());
    prepareState = new OzoneManagerPrepareState(conf);
}
Also used : OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) OzoneManagerPrepareState(org.apache.hadoop.ozone.om.OzoneManagerPrepareState) Before(org.junit.Before)

Aggregations

OzoneManagerPrepareState (org.apache.hadoop.ozone.om.OzoneManagerPrepareState)6 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)3 Before (org.junit.Before)3 OmMetadataManagerImpl (org.apache.hadoop.ozone.om.OmMetadataManagerImpl)2 OzoneManager (org.apache.hadoop.ozone.om.OzoneManager)2 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)2 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Pair (org.apache.commons.lang3.tuple.Pair)1 ContainerBlockID (org.apache.hadoop.hdds.client.ContainerBlockID)1 AllocatedBlock (org.apache.hadoop.hdds.scm.container.common.helpers.AllocatedBlock)1 Pipeline (org.apache.hadoop.hdds.scm.pipeline.Pipeline)1 ScmBlockLocationProtocol (org.apache.hadoop.hdds.scm.protocol.ScmBlockLocationProtocol)1 AuditLogger (org.apache.hadoop.ozone.audit.AuditLogger)1 AuditMessage (org.apache.hadoop.ozone.audit.AuditMessage)1 RatisSnapshotInfo (org.apache.hadoop.ozone.common.ha.ratis.RatisSnapshotInfo)1 KeyManagerImpl (org.apache.hadoop.ozone.om.KeyManagerImpl)1 OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)1 ResolvedBucket (org.apache.hadoop.ozone.om.ResolvedBucket)1 ScmClient (org.apache.hadoop.ozone.om.ScmClient)1