Commit 992aa780 authored by chiaming2000's avatar chiaming2000
Browse files

Get vendor specific device log Java Client and simulator implementation.

Please see the AdminApiUsage.getLog() for usage examples.
parent 21f7741f
Loading
Loading
Loading
Loading
+71 −16
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ package com.seagate.kinetic.admin.impl;
import java.util.List;

import kinetic.admin.ACL;
import kinetic.admin.Device;
import kinetic.admin.Domain;
import kinetic.admin.KineticAdminClient;
import kinetic.admin.KineticLog;
@@ -446,6 +447,10 @@ public class DefaultAdminClient implements KineticAdminClient {
                getLog.addType(Type.LIMITS);
                break;
                
            case DEVICE:
                throw new java.lang.UnsupportedOperationException(
                        "Please use #getVendorSpecificDeviceLog() to get vendor specific log.");

            default:
                ;
            }
@@ -455,22 +460,7 @@ public class DefaultAdminClient implements KineticAdminClient {

        Message response = (Message) kmresp.getMessage();

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

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

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

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

        KineticLog kineticLog = new DefaultKineticLog(response);
        return kineticLog;
@@ -523,4 +513,69 @@ public class DefaultAdminClient implements KineticAdminClient {
                    + response.getCommand().getStatus().getStatusMessage());
        }
    }

    @Override
    public Device getVendorSpecificDeviceLog(byte[] name)
            throws KineticException {
        
        KineticMessage km = MessageFactory.createKineticMessageWithBuilder();

        Message.Builder request = (Builder) km.getMessage();

        GetLog.Builder getLog = request.getCommandBuilder().getBodyBuilder()
                .getGetLogBuilder();
        
        // add DEVICE type
        getLog.addType(Type.DEVICE);
        
        // set vendor specific log name
        getLog.getDeviceBuilder().setName(ByteString.copyFrom(name));
        
        // send getLog/DEVICE message
        KineticMessage kmresp = getLog(km);
        
        // get response message
        Message response = (Message) kmresp.getMessage();
        
        // sanity check response 
        checkGetLogResponse(response);
        
        // get vendor specific getLog/DEVICE name/value
        byte[] value = kmresp.getValue();
        
        
        Device device = new Device();
        
        device.setName (name);
        device.setValue(value);
        
        return device;
    }
    
    /**
     * Sanity check getLog response message.
     * 
     * @param response
     * @throws KineticException
     */
    private static void checkGetLogResponse (Message response) throws KineticException {
        
        if (response.getCommand().getHeader().getMessageType() != MessageType.GETLOG_RESPONSE) {
            throw new KineticException("received wrong message type.");
        }

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

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

        if (response.getCommand().getStatus().getCode() != Status.StatusCode.SUCCESS) {
            throw new KineticException("Unknown Error: "
                    + response.getCommand().getStatus().getCode() + ": "
                    + response.getCommand().getStatus().getStatusMessage());
        }
    }
    
}
+1 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import kinetic.client.CallbackHandler;
import kinetic.client.ClientConfiguration;
import kinetic.client.Entry;
import kinetic.client.EntryMetadata;
import kinetic.client.EntryNotFoundException;
import kinetic.client.KineticException;
import kinetic.client.advanced.AdvancedKineticClient;
import kinetic.client.advanced.PersistOption;
+1 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ package com.seagate.kinetic.client.internal;
import kinetic.client.ClusterVersionFailureException;
import kinetic.client.Entry;
import kinetic.client.EntryMetadata;
import kinetic.client.EntryNotFoundException;
import kinetic.client.KineticException;
import kinetic.client.VersionMismatchException;

@@ -31,7 +32,6 @@ import com.seagate.kinetic.proto.Kinetic.Message.Builder;
import com.seagate.kinetic.proto.Kinetic.Message.KeyValue;
import com.seagate.kinetic.proto.Kinetic.Message.MessageType;
import com.seagate.kinetic.proto.Kinetic.Message.Range;

import com.seagate.kinetic.proto.Kinetic.Message.Status.StatusCode;
import com.seagate.kinetic.proto.Kinetic.Message.Synchronization;
import com.seagate.kinetic.proto.Kinetic.MessageOrBuilder;
+1 −1
Original line number Diff line number Diff line
@@ -30,11 +30,11 @@ import kinetic.client.AsyncKineticException;
import kinetic.client.ClientConfiguration;
import kinetic.client.Entry;
import kinetic.client.EntryMetadata;
import kinetic.client.EntryNotFoundException;
import kinetic.client.KineticException;

import com.seagate.kinetic.client.internal.CallbackContext;
import com.seagate.kinetic.client.internal.ClientProxy;
import com.seagate.kinetic.client.internal.EntryNotFoundException;
import com.seagate.kinetic.client.internal.MessageFactory;
import com.seagate.kinetic.client.internal.async.DeleteAsyncCallbackHandler;
import com.seagate.kinetic.client.internal.async.GetAsyncCallbackHandler;
+93 −0
Original line number Diff line number Diff line
/**
 * Copyright (C) 2014 Seagate Technology.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package kinetic.admin;

/**
 * 
 * The Device GetLog message is to ask the device to send back the
 * log of a certain name in the value field. The limit of each
 * log is 1m byte.
 * <p>
 * Proprietary names should be prefaced by the vendor name so that name
 * collisions do not happen in the future. An example could be names that
 * start with “com.wd” would be for Western Digital devices.
 * <p>
 * If the name is not found, the get log returns NOT_FOUND.
 * <p>
 * There can be only one Device in the list of logs that can be retrieved.
 * 
 * @author chiaming
 *
 */
public class Device {
    
    // name of the vendor specific log
    private byte[] name = null;
    
    // value of the vendor specific log.
    private byte[] value = null;
    
    /**
     * default constructor.
     */
    public Device() {
        ;
    }
    
    /**
     * Get the vendor specific device log name.
     * 
     * @return the vendor specific device log name
     */
    public byte[] getName() {
        return this.name;
    }
    
    /**
     * Set the vendor specifc device name.
     *  
     * @param name the vendor specifc device name.
     */
    
    public void setName (byte[] name) {
        this.name = name;
    }
    
    /**
     * The vendor specific device value.
     * 
     * @param value vendor specific device value associated with the specified name.
     * 
     * @see #setName(byte[])
     */
    public void setValue (byte[] value) {
        this.value = value;
    }
    
    /**
     * Get the vendor specific value.
     * 
     * @return the vendor specific value associated with the specified name.
     * 
     * @see #getName()
     */
    public byte[] getValue() {
        return this.value;
    }
    
}
Loading