Commit 99944ea8 authored by chiaming2000's avatar chiaming2000
Browse files

Minor code clean up only. Will continue cleaning up and add new features

for protocol 3.0.0 in this branch.
parent 4a5f6011
Loading
Loading
Loading
Loading
+1 −49
Original line number Diff line number Diff line
@@ -424,55 +424,7 @@ public class DefaultAdminClient implements KineticAdminClient {
        
    }
    
    //@Override
    public void _setup(byte[] pin, byte[] setPin, long newClusterVersion,
            boolean secureErase) throws KineticException {

        KineticMessage km = MessageFactory.createKineticMessageWithBuilder();
        
        Command.Builder commandBuilder = (Command.Builder) km.getCommand(); 

        Setup.Builder setup = commandBuilder.getBodyBuilder()
                .getSetupBuilder();
//
//        if (pin != null && pin.length > 0) {
//            setup.setPin(ByteString.copyFrom(pin));
//        }
//
//        if (setPin != null && setPin.length > 0) {
//            setup.setSetPin(ByteString.copyFrom(setPin));
//        }
//
//        setup.setInstantSecureErase(secureErase);

        if (0 > newClusterVersion) {
            throw new KineticException(
                    "Parameter invalid: new cluster version less than 0.");
        }
        
        setup.setNewClusterVersion(newClusterVersion);

        KineticMessage kmresp = configureSetupPolicy(km);

        if (kmresp.getCommand().getHeader().getMessageType() != MessageType.SETUP_RESPONSE) {
            throw new KineticException("received wrong message type.");
        }

        if (kmresp.getCommand().getStatus().getCode() == Status.StatusCode.NOT_AUTHORIZED) {

            throw new KineticException("Authorized Exception: "
                    + kmresp.getCommand().getStatus().getCode() + ": "
                    + kmresp.getCommand().getStatus().getStatusMessage());
        }

        if (kmresp.getCommand().getStatus().getCode() != Status.StatusCode.SUCCESS) {
            throw new KineticException("Unknown Error: "
                    + kmresp.getCommand().getStatus().getCode() + ": "
                    + kmresp.getCommand().getStatus().getStatusMessage());
        }

    }
    
    @Override
    public void setClusterVersion (long newClusterVersion) throws KineticException {
        
        KineticMessage km = MessageFactory.createKineticMessageWithBuilder();
+9 −1
Original line number Diff line number Diff line
@@ -179,6 +179,14 @@ public interface KineticAdminClient {
     */
    public void instantErase(byte[] pin) throws KineticException;
    
    /**
     * Set cluster version with the specified version.
     * 
     * @param newClusterVersion
     * @throws KineticException
     */
    public void setClusterVersion (long newClusterVersion) throws KineticException;

    /**
     * Close the connection and release all resources allocated by this
     * instance.
+7 −1
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ import com.seagate.kinetic.proto.Kinetic.Command.PinOperation.PinOpType;
import com.seagate.kinetic.proto.Kinetic.Command.MessageType;
import com.seagate.kinetic.proto.Kinetic.Command.Setup;
import com.seagate.kinetic.proto.Kinetic.Command.Status.StatusCode;
import com.seagate.kinetic.proto.Kinetic.Message.AuthType;
import com.seagate.kinetic.proto.Kinetic.Message;
import com.seagate.kinetic.simulator.persist.Store;

/**
@@ -51,6 +53,10 @@ public abstract class PinOperationHandler {
        // remove set up in if erase db
        boolean removeSetup = false;
        
        Message.Builder messageBuilder = (Message.Builder) respond.getMessage();
        // set pin auth
        messageBuilder.setAuthType(AuthType.PINAUTH);

        Command.Builder commandBuilder = (Command.Builder) respond.getCommand();
        
        // set reply type
+9 −9
Original line number Diff line number Diff line
@@ -102,8 +102,6 @@ public class SimulatorEngine implements MessageService {

    private Long clusterVersion = null;

    private byte[] pin = null;

    private final boolean isHttp = Boolean.getBoolean("kinetic.io.http");

    private final boolean isHttps = Boolean.getBoolean("kinetic.io.https");
@@ -204,7 +202,7 @@ public class SimulatorEngine implements MessageService {
            }
            SetupInfo setupInfo = SetupHandler.loadSetup(kineticHome);
            clusterVersion = setupInfo.getClusterVersion();
            pin = setupInfo.getPin();
            //pin = setupInfo.getPin();

            // initialize db store
            this.initStore();
@@ -470,7 +468,7 @@ public class SimulatorEngine implements MessageService {
                            kmresp, store, kineticHome);
                    if (setupInfo != null) {
                        this.clusterVersion = setupInfo.getClusterVersion();
                        this.pin = setupInfo.getPin();
                        //this.pin = setupInfo.getPin();
                    }
                }
            } else if (kmreq.getCommand().getBody().hasGetLog()) {
@@ -512,11 +510,13 @@ public class SimulatorEngine implements MessageService {
                // get command byte[]
                byte[] commandByte = commandByteString.toByteArray();
                
                // require Hmac calculation ?
                if (key != null) {
                    //calculate hmac 
                    ByteString hmac = Hmac.calc(commandByte, key);
                
                    //set hmac
                    messageBuilder.getHmacAuthBuilder().setHmac(hmac);
                }
                
                // set identity
                messageBuilder.getHmacAuthBuilder().setIdentity(userId);