Project

General

Profile

« Previous | Next » 

Revision 5770

Added by berkley almost 14 years ago

implemented health api

View differences:

src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java
486 486
                    //health monitoring calls
487 487
                    System.out.println("processing monitor request");
488 488
                    String pathInfo = request.getPathInfo();
489
                    if (httpVerb == GET && pathInfo.toLowerCase().equals("ping")) {
490
                        System.out.println("processing ping request");
489
                    if(httpVerb == GET)
490
                    {
491
                        System.out.println("verb is GET");
492
                        System.out.println("pathInfo is " + pathInfo);
493
                        pathInfo = pathInfo.substring(1);
491 494
                        HealthService hs = new HealthService(request, response);
492
                        hs.ping();
495
                        if (pathInfo.toLowerCase().equals("ping")) {
496
                            System.out.println("processing ping request");
497
                            hs.ping();
498
                        } else if (pathInfo.toLowerCase().equals("status")) {
499
                            System.out.println("processing status request");
500
                            hs.getStatus();
501
                        } else if (pathInfo.toLowerCase().equals("object")) {
502
                            System.out.println("processing object request");
503
                            boolean day = false;
504
                            Identifier pid = null;
505
                            String url = null;
506
                            ObjectFormat of = null;
507
                            Date time = null;
508
                            
509
                            if(params.containsKey("day"))
510
                            {
511
                               day = true; 
512
                            }
513
                            if(params.containsKey("pid"))
514
                            {
515
                                String id = params.get("pid")[0];
516
                                pid = new Identifier();
517
                                pid.setValue(id);
518
                            }
519
                            if(params.containsKey("url"))
520
                            {
521
                                url = params.get("url")[0];
522
                            }
523
                            if(params.containsKey("format"))
524
                            {
525
                                String format = params.get("format")[0];
526
                                of = ObjectFormat.convert(format);
527
                            }
528
                            if(params.containsKey("time"))
529
                            {
530
                                String t = params.get("time")[0];
531
                                time = dateFormat.parse(t);
532
                            }
533
                            
534
                            hs.getObjectStatistics(day, pid, url, of, time);
535
                        } else if (pathInfo.toLowerCase().equals("event")) {
536
                            System.out.println("processing event request");
537
                            boolean day = false;
538
                            Identifier pid = null;
539
                            Date created = null;
540
                            ObjectFormat of = null;
541
                            Date time = null;
542
                            String ipAddress = null;
543
                            String event = null;
544
                            
545
                            if(params.containsKey("day"))
546
                            {
547
                               day = true; 
548
                            }
549
                            if(params.containsKey("pid"))
550
                            {
551
                                String id = params.get("pid")[0];
552
                                pid = new Identifier();
553
                                pid.setValue(id);
554
                            }
555
                            if(params.containsKey("created"))
556
                            {
557
                                String t = params.get("created")[0];
558
                                created = dateFormat.parse(t);
559
                            }
560
                            if(params.containsKey("format"))
561
                            {
562
                                String format = params.get("format")[0];
563
                                of = ObjectFormat.convert(format);
564
                            }
565
                            if(params.containsKey("eventtime"))
566
                            {
567
                                String t = params.get("eventtime")[0];
568
                                time = dateFormat.parse(t);
569
                            }
570
                            if(params.containsKey("ip_address"))
571
                            {
572
                                ipAddress = params.get("ip_address")[0];
573
                            }
574
                            if(params.containsKey("event"))
575
                            {
576
                                event = params.get("event")[0];
577
                            }
578
                            
579
                            hs.getOperationStatistics(day, pid, of, created, time, ipAddress, event);
580
                        }
493 581
                    }
494 582
                    status = true;
495 583
                }
src/edu/ucsb/nceas/metacat/dataone/HealthService.java
24 24
package edu.ucsb.nceas.metacat.dataone;
25 25

  
26 26
import java.io.IOException;
27
import java.util.Date;
27 28

  
28 29
import javax.servlet.http.HttpServletRequest;
29 30
import javax.servlet.http.HttpServletResponse;
30 31

  
31 32
import org.dataone.service.mn.MemberNodeHealth;
33
import org.dataone.service.types.Identifier;
34
import org.dataone.service.types.ObjectFormat;
35
import org.dataone.service.types.ObjectInfo;
32 36
import org.omg.CORBA.portable.OutputStream;
33 37

  
34 38
/**
35 39
 * @author berkley
36
 *
40
 * Class to implement the HealthService API for DataONE
37 41
 */
38 42
public class HealthService implements MemberNodeHealth
39 43
{    
40 44
    HttpServletRequest request;
41 45
    HttpServletResponse response;
42 46
    
47
    /**
48
     * Constructor
49
     * @param request
50
     * @param response
51
     */
43 52
    public HealthService(HttpServletRequest request, HttpServletResponse response)
44 53
    {
45 54
        this.request = request;
46 55
        this.response = response;
47 56
    }
48 57
    
58
    /**
59
     * Implements /monitory/ping from 
60
     * http://mule1.dataone.org/ArchitectureDocs-current/apis/REST_interface.html#get-monitor-object
61
     */
49 62
    public void ping()
50 63
    {
51 64
        response.setStatus(200);
......
61 74
        }
62 75
    }
63 76
    
64
    public void getObjectStatistics()
77
    /**
78
     * implements /monitor/object from 
79
     * http://mule1.dataone.org/ArchitectureDocs-current/apis/REST_interface.html#get-monitor-object
80
     */
81
    public void getObjectStatistics(boolean reportDaily, 
82
            Identifier guid, String url, ObjectFormat format, Date time)
65 83
    {
84
        response.setStatus(500);
85
        try
86
        {
87
            response.getOutputStream().write("getObjectStatistics Not Implemented".getBytes());
88
            response.getOutputStream().flush();
89
        }
90
        catch (IOException e)
91
        {
92
            System.out.println("Error in getObjectStatistics: " + e.getMessage());
93
            e.printStackTrace();
94
        }
66 95
        
67 96
    }
68 97
    
69
    public void getOperationStatistics()
98
    /**
99
     * implements /monitor/event from
100
     * http://mule1.dataone.org/ArchitectureDocs-current/apis/REST_interface.html#get-monitor-object
101
     */
102
    public void getOperationStatistics(boolean reportDaily, Identifier pid, 
103
            ObjectFormat format, Date createDate, Date eventTime, String ipAddress, String event)
70 104
    {
71
        
105
        response.setStatus(500);
106
        try
107
        {
108
            response.getOutputStream().write("getOperationStatistics Not Implemented".getBytes());
109
            response.getOutputStream().flush();
110
        }
111
        catch (IOException e)
112
        {
113
            System.out.println("Error in getOperationStatistics: " + e.getMessage());
114
            e.printStackTrace();
115
        }
72 116
    }
73 117
    
118
    /**
119
     * Implements /monitor/status from
120
     * http://mule1.dataone.org/ArchitectureDocs-current/apis/REST_interface.html#get-monitor-object
121
     * This method is mostly unimplemented.  Right now it just does what ping does.
122
     * It should be updated in the future to return status information such as 
123
     * pending outages, software updates, etc.  See Use Case 10 for more 
124
     * info.
125
     */
74 126
    public void getStatus()
75 127
    {
76
        
128
        ping();
77 129
    }
78 130
}
src/edu/ucsb/nceas/metacat/dataone/CrudService.java
119 119
    }
120 120
    
121 121
    /**
122
     * Initializes new instance by setting servlet context,request and response.
122
     * Constructor, private for singleton access
123 123
     */
124 124
    private CrudService() {
125 125
        logMetacat = Logger.getLogger(CrudService.class);

Also available in: Unified diff