Project

General

Profile

« Previous | Next » 

Revision 6476

Added by Matt Jones about 13 years ago

Fix getCapabilities to properly throw ServiceFailure when properties can not be read, rather than failing with a log message. Fix properties in the Node object to reflect their correct values. Set the sync schedule properly to default to 5 minute intervals. Improve documentation.

View differences:

src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
27 27
import java.io.InputStream;
28 28
import java.security.NoSuchAlgorithmException;
29 29
import java.sql.SQLException;
30
import java.text.SimpleDateFormat;
31 30
import java.util.Date;
32 31
import java.util.List;
33 32
import java.util.Timer;
......
36 35
import org.apache.log4j.Logger;
37 36
import org.dataone.client.D1Client;
38 37
import org.dataone.client.MNode;
39
import org.dataone.service.util.Constants;
40 38
import org.dataone.service.exceptions.IdentifierNotUnique;
41 39
import org.dataone.service.exceptions.InsufficientResources;
42 40
import org.dataone.service.exceptions.InvalidRequest;
......
78 76
import org.dataone.service.types.v1.Synchronization;
79 77
import org.dataone.service.types.v1.SystemMetadata;
80 78
import org.dataone.service.types.v1.util.ChecksumUtil;
79
import org.dataone.service.util.Constants;
81 80

  
82 81
import edu.ucsb.nceas.metacat.DocumentImpl;
83 82
import edu.ucsb.nceas.metacat.EventLog;
......
88 87
import edu.ucsb.nceas.metacat.database.DBConnection;
89 88
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
90 89
import edu.ucsb.nceas.metacat.properties.PropertyService;
91
import edu.ucsb.nceas.metacat.util.SystemUtil;
92 90
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
93 91

  
94 92
/**
......
591 589
    }
592 590

  
593 591
    /**
594
     * Retrieve the list of objects present on the MN that match the calling parameters
592
     * Return a description of the node's capabilities and services.
595 593
     * 
596 594
     * @return node - the technical capabilities of the Member Node
597 595
     * 
......
605 603

  
606 604
        String nodeName = null;
607 605
        String nodeId = null;
608
        String nodeUrl = null;
609 606
        String nodeDesc = null;
610
        String nodeType = null;
607
        String nodeTypeString = null;
608
        NodeType nodeType = null;
611 609
        String mnCoreServiceVersion = null;
612 610
        String mnReadServiceVersion = null;
613 611
        String mnAuthorizationServiceVersion = null;
......
626 624
            // get the properties of the node based on configuration information
627 625
            nodeId = PropertyService.getProperty("dataone.memberNodeId");
628 626
            nodeName = PropertyService.getProperty("dataone.nodeName");
629
            nodeUrl = SystemUtil.getContextURL() + "/d1/";
630 627
            nodeDesc = PropertyService.getProperty("dataone.nodeDescription");
631
            nodeType = PropertyService.getProperty("dataone.nodeType");
628
            nodeTypeString = PropertyService.getProperty("dataone.nodeType");
629
            nodeType = NodeType.convert(nodeTypeString);
632 630
            nodeSynchronize = new Boolean(PropertyService.getProperty("dataone.nodeSynchronize")).booleanValue();
633 631
            nodeReplicate = new Boolean(PropertyService.getProperty("dataone.nodeReplicate")).booleanValue();
634 632

  
......
644 642
            mnStorageServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnStorage.serviceAvailable")).booleanValue();
645 643
            mnReplicationServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnReplication.serviceAvailable")).booleanValue();
646 644

  
647
        } catch (PropertyNotFoundException pnfe) {
648
            logMetacat.error("MNodeService.getCapabilities(): " + "property not found: " + pnfe.getMessage());
645
            // Set the properties of the node based on configuration information and
646
            // calls to current status methods
647
            Node node = new Node();
648
            node.setBaseURL(metacatUrl + "/" + nodeTypeString);
649
            node.setDescription(nodeDesc);
649 650

  
650
        }
651
            // set the node's health information
652
            node.setState(NodeState.UP);
653
            
654
            // set the ping response to the current value
655
            Ping canPing = new Ping();
656
            canPing.setSuccess(false);
657
            try {
658
                canPing.setSuccess(ping());
659
            } catch (InsufficientResources e) {
660
                e.printStackTrace();
661
            } catch (UnsupportedType e) {
662
                e.printStackTrace();
663
            }
664
            node.setPing(canPing);
651 665

  
652
        // Set the properties of the node based on configuration information and
653
        // calls to current status methods
654
        Node node = new Node();
655
        node.setBaseURL(metacatUrl + "/" + nodeType);
656
        node.setDescription(nodeDesc);
666
            NodeReference identifier = new NodeReference();
667
            identifier.setValue(nodeId);
668
            node.setIdentifier(identifier);
669
            node.setName(nodeName);
670
            node.setReplicate(nodeReplicate);
671
            node.setSynchronize(nodeSynchronize);
657 672

  
658
        // set the node's health information
659
        NodeState state = NodeState.UP;
660
        node.setState(state);
661
        // set the ping response to the current value
662
        Ping canPing = new Ping();
663
        canPing.setSuccess(false);
664
        try {
665
            canPing.setSuccess(ping());
666
        } catch (InsufficientResources e) {
667
            e.printStackTrace();
673
            // services: MNAuthorization, MNCore, MNRead, MNReplication, MNStorage
674
            Services services = new Services();
668 675

  
669
        } catch (UnsupportedType e) {
670
            e.printStackTrace();
676
            Service sMNCore = new Service();
677
            sMNCore.setName("MNCore");
678
            sMNCore.setVersion(mnCoreServiceVersion);
679
            sMNCore.setAvailable(mnCoreServiceAvailable);
671 680

  
672
        }
673
        node.setPing(canPing);
681
            Service sMNRead = new Service();
682
            sMNRead.setName("MNRead");
683
            sMNRead.setVersion(mnReadServiceVersion);
684
            sMNRead.setAvailable(mnReadServiceAvailable);
674 685

  
675
        NodeReference identifier = new NodeReference();
676
        identifier.setValue(nodeId);
677
        node.setIdentifier(identifier);
678
        node.setName(nodeName + " -- WAR version WARVERSION");
679
        node.setReplicate(new Boolean(nodeReplicate).booleanValue());
680
        node.setSynchronize(new Boolean(nodeSynchronize).booleanValue());
686
            Service sMNAuthorization = new Service();
687
            sMNAuthorization.setName("MNAuthorization");
688
            sMNAuthorization.setVersion(mnAuthorizationServiceVersion);
689
            sMNAuthorization.setAvailable(mnAuthorizationServiceAvailable);
681 690

  
682
        // services: MNAuthorization, MNCore, MNRead, MNReplication, MNStorage
683
        Services services = new Services();
691
            Service sMNStorage = new Service();
692
            sMNStorage.setName("MNStorage");
693
            sMNStorage.setVersion(mnStorageServiceVersion);
694
            sMNStorage.setAvailable(mnStorageServiceAvailable);
684 695

  
685
        Service sMNCore = new Service();
686
        sMNCore.setName("MNCore");
687
        sMNCore.setVersion(mnCoreServiceVersion);
688
        sMNCore.setAvailable(mnCoreServiceAvailable);
696
            Service sMNReplication = new Service();
697
            sMNReplication.setName("MNReplication");
698
            sMNReplication.setVersion(mnReplicationServiceVersion);
699
            sMNReplication.setAvailable(mnReplicationServiceAvailable);
689 700

  
690
        Service sMNRead = new Service();
691
        sMNRead.setName("MNRead");
692
        sMNRead.setVersion(mnReadServiceVersion);
693
        sMNRead.setAvailable(mnReadServiceAvailable);
701
            services.addService(sMNRead);
702
            services.addService(sMNCore);
703
            services.addService(sMNAuthorization);
704
            services.addService(sMNStorage);
705
            services.addService(sMNReplication);
706
            node.setServices(services);
694 707

  
695
        Service sMNAuthorization = new Service();
696
        sMNAuthorization.setName("MNAuthorization");
697
        sMNAuthorization.setVersion(mnAuthorizationServiceVersion);
698
        sMNAuthorization.setAvailable(mnAuthorizationServiceAvailable);
708
            // TODO: Allow the metacat admin to determine the schedule
709
            // Set the schedule for synchronization
710
            Synchronization synchronization = new Synchronization();
711
            Schedule schedule = new Schedule();
712
            Date now = new Date();
713
            schedule.setYear("*");
714
            schedule.setMon("*");
715
            schedule.setMday("*");
716
            schedule.setWday("*");
717
            schedule.setHour("*");
718
            schedule.setMin("0,5,10,15,20,25,30,35,40,45,50,55");
719
            schedule.setSec("*");
720
            synchronization.setSchedule(schedule);
721
            synchronization.setLastHarvested(now);
722
            synchronization.setLastCompleteHarvest(now);
723
            node.setSynchronization(synchronization);
699 724

  
700
        Service sMNStorage = new Service();
701
        sMNStorage.setName("MNStorage");
702
        sMNStorage.setVersion(mnStorageServiceVersion);
703
        sMNStorage.setAvailable(mnStorageServiceAvailable);
725
            node.setType(nodeType);
726
            return node;
704 727

  
705
        Service sMNReplication = new Service();
706
        sMNReplication.setName("MNReplication");
707
        sMNReplication.setVersion(mnReplicationServiceVersion);
708
        sMNReplication.setAvailable(mnReplicationServiceAvailable);
709

  
710
        services.addService(sMNRead);
711
        services.addService(sMNCore);
712
        services.addService(sMNAuthorization);
713
        services.addService(sMNStorage);
714
        services.addService(sMNReplication);
715
        node.setServices(services);
716

  
717
        // TODO: Determine the synchronization info without mock values
718
        Synchronization synchronization = new Synchronization();
719
        Schedule schedule = new Schedule();
720
        Date now = new Date();
721
        schedule.setYear(new SimpleDateFormat("yyyy").format(now));
722
        schedule.setMon(new SimpleDateFormat("MM").format(now));
723
        schedule.setMday(new SimpleDateFormat("dd").format(now));
724
        schedule.setWday(new SimpleDateFormat("dd").format(now));
725
        schedule.setHour(new SimpleDateFormat("HH").format(now));
726
        schedule.setMin(new SimpleDateFormat("mm").format(now));
727
        schedule.setSec(new SimpleDateFormat("ss").format(now));
728
        synchronization.setSchedule(schedule);
729
        synchronization.setLastHarvested(now);
730
        synchronization.setLastCompleteHarvest(now);
731
        node.setSynchronization(synchronization);
732
        node.setSynchronize(false);
733
        node.setType(NodeType.MN);
734

  
735
        return node;
728
        } catch (PropertyNotFoundException pnfe) {
729
            String msg = "MNodeService.getCapabilities(): " + "property not found: " + pnfe.getMessage();
730
            logMetacat.error(msg);
731
            throw new ServiceFailure("2162", msg);
732
        }
736 733
    }
737 734

  
738 735
    /**

Also available in: Unified diff