Exemplo n.º 1
0
    def post(self, version):
        logging.debug("ServicesListHandler#post")

        if (self.valid_version(version)):
            
            name = self.request.get('name', default_value=None)
            description = self.request.get('description', default_value=None)
            
            if name and description:
                slug = slugify.slugify(name)
                existing_s = Service.get_by_slug(slug)

                # Update existing resource
                if existing_s:
                    existing_s.description = description
                    existing_s.put()
                    self.json(existing_s.rest(self.base_url(version)))
                # Create new service
                else:
                    s = Service(name=name, slug=slug, description=description)
                    s.put()
                    self.json(s.rest(self.base_url(version)))
            else:
                self.error(400, "Bad Data: Name: %s, Description: %s" % (name, description))
        else:
            self.error(404, "API Version %s not supported" % version)
Exemplo n.º 2
0
    def get(self):
        user = users.get_current_user()
        logging.debug("BasicRootHandler #get")

        q = Service.all()
        q.order("name")
        services = q.fetch(100)
        
        p = Status.all()
        p.order("severity")
        
        past = get_past_days(5)

        services = q.fetch(100)
    
        for s in services:
            logging.info(s.last_six_days())

        
        td = {}
        td["services"] = services
        td["statuses"] = p.fetch(100)
        td["past"] = past
        td["default"] = Status.default()

        self.render(td, 'site/index.html')
Exemplo n.º 3
0
    def get(self, version, service_slug):
        logging.debug("ServiceInstanceHandler#get")
        
        if (self.valid_version(version)):
            service = Service.get_by_slug(service_slug)

            if (service):
                self.json(service.rest(self.base_url(version)))
            else:
                self.error(404, "Service %s does not exist" % service_slug)
        else:
            self.error(404, "API Version %s not supported" % version)
Exemplo n.º 4
0
    def get(self, service_slug, year=None, month=None, day=None):
        user = users.get_current_user()
        logging.debug("BasicServiceHandler #get")

        service = Service.get_by_slug(service_slug)

        if not service:
            self.not_found()
            return

        events = service.events
        show_admin = False

        try: 
            if day:
                start_date = dates.add_offset(datetime(int(year),int(month),int(day)))
                end_date = start_date + timedelta(days=1)
            elif month:
                start_date = dates.add_offset(datetime(int(year),int(month),1))
                days = calendar.monthrange(start_date.year, start_date.month)[1]
                end_date = start_date + timedelta(days=days)
            elif year:
                start_date = dates.add_offset(datetime(int(year),1,1))
                end_date = start_date + timedelta(days=365)
            else:
                start_date = None
                end_date = None
                show_admin = True
        except ValueError:
            self.not_found()
            return
        
        logging.info(start_date)
            
        if start_date and end_date:
            events.filter('start >= ', start_date).filter('start <', end_date)

        events.order("-start")
        e = events.fetch(100)

        for v in e:
            v.local_start()

        td = {}
        td["service"] = service
        td["events"] = e
        td["start_date"] = start_date
        td["end_date"] = end_date

        self.render(td, 'site/service-day-summary.html')
Exemplo n.º 5
0
    def get(self, version, service_slug, sid):
        logging.debug("EventInstanceHandler#get sid=%s" % sid)
        
        if (self.valid_version(version)):
            service = Service.get_by_slug(service_slug)

            if (service):
                event = Event.get(db.Key(sid))
                if (event and service.key() == event.service.key()):
                    self.json(event.rest(self.base_url(version))) 
                else:
                    self.error(404, "No event for Service %s with sid = %s" % (service_slug,sid))
            else:
                self.error(404, "Service %s not found" % service_slug)
        else:
            self.error(404, "API Version %s not supported" % version)
Exemplo n.º 6
0
    def get(self, service_slug, year=None, month=None, day=None):
        user = users.get_current_user()
        logging.debug("AdminServiceHandler#get")
        
        service = Service.get_by_slug(service_slug)
        
        if not service:
            self.not_found()
            return
        
        try: 
            if day:
                start_date = date(int(year),int(month),int(day))
                end_date = start_date + timedelta(days=1)
            elif month:
                start_date = date(int(year),int(month),1)
                days = calendar.monthrange(start_date.year, start_date.month)[1]
                end_date = start_date + timedelta(days=days)
            elif year:
                start_date = date(int(year),1,1)
                end_date = start_date + timedelta(days=365)
            else:
                start_date = None
                end_date = None
        except ValueError:
            self.not_found()
            return
            
        td = {
            "services_selected": True,
            "service": service_slug,
            }
        
        if start_date and end_date:
            start_stamp = mktime(start_date.timetuple())
            end_stamp = mktime(end_date.timetuple())
            # Remove GMT from the string so that the date is
            # is parsed in user's time zone
            td["start_date"] = start_date
            td["end_date"] = end_date
            td["start_date_stamp"] = format_date_time(start_stamp)[:-4]
            td["end_date_stamp"] = format_date_time(end_stamp)[:-4]
        else:
            td["start_date"] = None
            td["end_date"] = None

        self.render(td, 'admin/service.html')
Exemplo n.º 7
0
    def get(self, version):
        logging.debug("ServicesListHandler#get")
        if (self.valid_version(version)):
            
            query = Service.all().order('name')
            data = []


            for s in query:
                data.append(s.rest(self.base_url(version)))

            data = { "services": data }

            self.json(data)
            
        else:
            self.error(404, "API Version %s not supported" % version)
Exemplo n.º 8
0
    def get(self, version, service_slug):
        logging.debug("StatusesListHandler#get")
        
        if (self.valid_version(version)):
            service = Service.get_by_slug(service_slug)

            if service:
                start = self.request.get('start', default_value=None)
                end = self.request.get('end', default_value=None)
                                 
                query = Event.all()
                query.filter('service =', service)
                        
                if start:
                    try:
                        _start = aware_to_naive(parse(start))
                        query.filter("start >= ", _start)
                    except:
                        self.error(400, "Invalid Date: %s" % start)
                        return

                if end:
                    try:
                        _end  = aware_to_naive(parse(end))
                        query.filter("start <=", _end)
                    except:
                        self.error(400, "Invalid Date: %s" % end)
                        return
                        
                query.order('-start')
                        
                if query:
                    data = []

                    for s in query:
                        data.append(s.rest(self.base_url(version)))

                    data = { "events": data }

                    self.json(data) 
                else:
                    self.error(404, "No events for Service %s" % service_slug)
            else:
                self.error(404, "Service %s not found" % service_slug)
        else:
            self.error(404, "API Version %s not supported" % version)
Exemplo n.º 9
0
    def get(self, service_slug):
        user = users.get_current_user()
        logging.debug("BasicServiceHandler #get")

        service = Service.get_by_slug(service_slug)

        if not service:
            self.not_found()
            return

        events = service.events
        
        td = {}
        td["service"] = service
        td["calendar"] = service.last_six_days()

        self.render(td, 'site/service.html')
Exemplo n.º 10
0
 def get(self, version, service_slug):
     logging.debug("CurrentStatusHandler#get")
     
     if (self.valid_version(version)):
     
         service = Service.get_by_slug(service_slug)
     
         if (service):
             event = service.current_event()
     
             if (event):
                 self.json(event.rest(self.base_url(version))) 
             else:
                 self.error(404, "No current event for Service %s" % service_slug)
         else:
             self.error(404, "Service %s not found" % service_slug)
     else:
         self.error(404, "Version %s not supported" % version)
Exemplo n.º 11
0
class ServiceTest(unittest.TestCase):

    def setUp(self):
        self.region = Region(slug="us-east", name="U.S. East",
                             location="United States of America")
        self.service = Service(slug="fake-service", name="Fake Service", 
                               description="This is fake, yo", region=self.region)

    def test_creation(self):
        self.assertEqual(self.service.slug, "fake-service")
        self.assertEqual(self.service.name, "Fake Service")
        self.assertEqual(self.service.region, self.region)
        self.assertEqual(self.service.description, "This is fake, yo")

    def test_feed_urls(self):
        (aa, an, iss) = self.service.feeds()
        self.assertEquals(aa["title"], "All Activity")
        self.assertEquals(aa["url"], "/feeds/services/fake-service/all-activity")
Exemplo n.º 12
0
    def delete(self, version, service_slug):
        logging.debug("ServiceInstanceHandler#delete slug=%s" % service_slug)
        
        if (self.valid_version(version)):
            
            service = Service.get_by_slug(service_slug)
            
            if service:
                query = Event.all()
                query.filter('service =', service)
                if query:
                    for e in query:
                        e.delete()

                service.delete()
                self.json(service.rest(self.base_url(version)))
            else:
                self.error(404, "Service %s not found" % service_slug)
        else:
            self.error(404, "API Version %s not supported" % version)
Exemplo n.º 13
0
 def post(self, version, service_slug):
     logging.debug("ServiceInstanceHandler#post")
     name = self.request.get('name', default_value=None)
     description = self.request.get('description', default_value=None)
     
     if (self.valid_version(version)):
         service = Service.get_by_slug(service_slug)
         if service:
             if description:
                 service.description = description
             
             if name:
                 service.name = name
             
             if name or description:
                 service.put()
                 
             self.json(service.rest(self.base_url(version)))   
         else:
             self.error(404, "Service %s does not exist" % service_slug)
     else:
         self.error(404, "API Version %s not supported" % version)
Exemplo n.º 14
0
    def post(self, version, service_slug):
        logging.debug("EventsListHandler#post")
        
        if (self.valid_version(version)):
            status_slug = self.request.get("status", default_value=None)
            message = self.request.get("message", default_value=None)
            informational = self.request.get("informational", default_value=None)
            
            if message:
                service = Service.get_by_slug(service_slug)
                if service:
                    
                    if not status_slug:
                        event = service.current_event()
                        if event:
                            status = event.status
                        else:
                            status = Status.default()
                    else:
                        status = Status.get_by_slug(status_slug)

                    if status:
                        e = Event(status=status, service=service,
                                message=message)

                        e.informational = informational and informational == "true"

                        e.put()
                        self.json(e.rest(self.base_url(version)))
                    else:
                        self.error(404, "Status %s not found" % status_slug)
                else:
                    self.error(404, "Service %s not found" % service_slug)
            else:
                self.error(400, "Event message is required")
        else:
            self.error(404, "API Version %s not supported" % version)
Exemplo n.º 15
0
 def setUp(self):
     self.region = Region(slug="us-east", name="U.S. East",
                          location="United States of America")
     self.service = Service(slug="fake-service", name="Fake Service", 
                            description="This is fake, yo", region=self.region)