Exemple #1
0
 def createProject(self):
     project_obj = NDProject.fromName(self.project_name)
     project = model_to_dict(project_obj.pr)
     project['kvengine'] = REDIS
     project['host'] = 'localhost'
     project['s3backend'] = S3_TRUE
     del project['user']
     del project['dataset']
     try:
         response = getJson(
             'https://{}/resource/dataset/{}/project/{}/'.format(
                 self.host, self.dataset_name, self.project_name))
         if response.status_code == 404:
             response = postJson(
                 'https://{}/resource/dataset/{}/project/{}/'.format(
                     self.host, self.dataset_name, self.project_name),
                 project)
             if response.status_code != 201:
                 raise ValueError(
                     'The server returned status code {}'.format(
                         response.status_code))
         elif (response.status_code
               == 200) and (self.project_name
                            == response.json()['project_name']):
             self.logger.warning(
                 "Project already exists. Skipping Project creation")
         else:
             raise ValueError(
                 'The server returned status code {} and content {}'.format(
                     response.status_code, response.json()))
     except Exception as e:
         self.logger.error(e)
         sys.exit(0)
Exemple #2
0
 def createChannel(self, channel_name):
     project = NDProject.fromName(self.project_name)
     channel_obj = project.getChannelObj(channel_name)
     channel = model_to_dict(channel_obj.ch)
     del channel['id']
     del channel['project']
     # del channel['user']
     try:
         response = getJson(
             'https://{}/resource/dataset/{}/project/{}/channel/{}/'.format(
                 self.host, self.dataset_name, self.project_name,
                 channel_name))
         if response.status_code == 404:
             response = postJson(
                 'https://{}/resource/dataset/{}/project/{}/channel/{}/'.
                 format(self.host, self.dataset_name, self.project_name,
                        channel_name), channel)
             if response.status_code != 201:
                 raise ValueError(
                     'The server returned status code {}'.format(
                         response.status_code))
         elif (response.status_code
               == 200) and (channel_name
                            == response.json()['channel_name']):
             self.logger.warning(
                 "Channel already exists. Skipping Channel creation")
         else:
             raise ValueError(
                 'The server returned status code {} and content {}'.format(
                     response.status_code, response.json()))
     except Exception as e:
         self.logger.error(e)
         sys.exit(0)
Exemple #3
0
 def delete(self, request, dataset_name, project_name):
   try:
     pr = NDProject.fromName(project_name)
     pr.delete()
     return HttpResponse(status=204)
   except Exception as e:
     return HttpResponseBadRequest()
Exemple #4
0
 def delete(self, request, dataset_name, project_name):
     try:
         pr = NDProject.fromName(project_name)
         pr.delete()
         return HttpResponse(status=204)
     except Exception as e:
         return HttpResponseBadRequest()
Exemple #5
0
 def get(self, request, dataset_name, project_name):
   try:
     pr = NDProject.fromName(project_name)
     return HttpResponse(pr.serialize(), content_type='application/json')
   except Project.DoesNotExist as e:
     return HttpResponseNotFound()
   except Exception as e:
     return HttpResponseBadRequest()
Exemple #6
0
 def get(self, request, dataset_name, project_name):
     try:
         pr = NDProject.fromName(project_name)
         return HttpResponse(pr.serialize(),
                             content_type='application/json')
     except Project.DoesNotExist as e:
         return HttpResponseNotFound()
     except Exception as e:
         return HttpResponseBadRequest()
Exemple #7
0
 def post(self, request, dataset_name, project_name, token_name):
   try:
     pr = NDProject.fromName(project_name)
     tk = NDToken.fromJson(project_name, request.body)
     if request.user.is_authenticated():
       tk.user_id = request.user.id
     else:
       tk.user_id = User.objects.get(username='******').id
     tk.create()
     return HttpResponse(status=201)
   except Exception as e:
     return HttpResponseBadRequest()
Exemple #8
0
 def post(self, request, dataset_name, project_name, token_name):
     try:
         pr = NDProject.fromName(project_name)
         tk = NDToken.fromJson(project_name, request.body)
         if request.user.is_authenticated():
             tk.user_id = request.user.id
         else:
             tk.user_id = User.objects.get(username='******').id
         tk.create()
         return HttpResponse(status=201)
     except Exception as e:
         return HttpResponseBadRequest()
Exemple #9
0
 def createChannel(self, channel_name):
   project = NDProject.fromName(self.project_name)
   channel_obj = project.getChannelObj(channel_name)
   channel = model_to_dict(channel_obj.ch)
   del channel['id']
   del channel['project']
   # del channel['user']
   try:
     response = getJson('https://{}/resource/dataset/{}/project/{}/channel/{}/'.format(self.host, self.dataset_name, self.project_name, channel_name))
     if response.status_code == 404:
       response = postJson('https://{}/resource/dataset/{}/project/{}/channel/{}/'.format(self.host, self.dataset_name, self.project_name, channel_name), channel)
       if response.status_code != 201:
         raise ValueError('The server returned status code {}'.format(response.status_code))
     elif (response.status_code == 200) and (channel_name == response.json()['channel_name']):
       self.logger.warning("Channel already exists. Skipping Channel creation")
     else:
       raise ValueError('The server returned status code {} and content {}'.format(response.status_code, response.json()))
   except Exception as e:
     self.logger.error(e)
     sys.exit(0)
Exemple #10
0
 def createProject(self):
   project_obj = NDProject.fromName(self.project_name)
   project = model_to_dict(project_obj.pr)
   project['kvengine'] = REDIS
   project['host'] = 'localhost'
   project['s3backend'] = S3_TRUE
   del project['user']
   del project['dataset']
   try:
     response = getJson('https://{}/resource/dataset/{}/project/{}/'.format(self.host, self.dataset_name, self.project_name))
     if response.status_code == 404:
       response = postJson('https://{}/resource/dataset/{}/project/{}/'.format(self.host, self.dataset_name, self.project_name), project)
       if response.status_code != 201:
         raise ValueError('The server returned status code {}'.format(response.status_code))
     elif (response.status_code == 200) and (self.project_name == response.json()['project_name']):
       self.logger.warning("Project already exists. Skipping Project creation")
     else:
       raise ValueError('The server returned status code {} and content {}'.format(response.status_code, response.json()))
   except Exception as e:
     self.logger.error(e)
     sys.exit(0)
Exemple #11
0
def deleteTestDB ( project_name, token_name='unittest' ):
  

  try:
    # get the objects
    tk = NDToken.fromName(token_name)
    tk.delete()
    pr = NDProject.fromName(project_name)
    ds = pr.datasetcfg
    # tk = Token.objects.get(token_name=token_name)
    # pr = Project.objects.get(project_name=project_name)
    # ds = Dataset.objects.get(dataset_name=pr.dataset_id)
    
    # get the channel list
    # channel_list = Channel.objects.filter(project_id=pr)
    
    # get the correct object for the kvengine
    # pd = NDProjectsDB.getProjDB(pr)
    
    for ch in pr.projectChannels():
      ch.delete()
      # delete the channel table
      # pd.deleteNDChannel(ch.channel_name)
      # delete the channel
      # ch.delete()
    # delete the project database
    # pd.deleteNDProject()
    # delete the objects
    pr.delete()
    ds.delete()
    
    # delete s3 bucket and dynamo table
    if KV_ENGINE == REDIS:
      CuboidIndexDB.deleteTable()
      CuboidBucket.deleteBucket()
  except Exception, e:
    print(e)
    raise e
Exemple #12
0
def deleteTestDB(project_name, token_name='unittest'):

    try:
        # get the objects
        tk = NDToken.fromName(token_name)
        tk.delete()
        pr = NDProject.fromName(project_name)
        ds = pr.datasetcfg
        # tk = Token.objects.get(token_name=token_name)
        # pr = Project.objects.get(project_name=project_name)
        # ds = Dataset.objects.get(dataset_name=pr.dataset_id)

        # get the channel list
        # channel_list = Channel.objects.filter(project_id=pr)

        # get the correct object for the kvengine
        # pd = NDProjectsDB.getProjDB(pr)

        for ch in pr.projectChannels():
            ch.delete()
            # delete the channel table
            # pd.deleteNDChannel(ch.channel_name)
            # delete the channel
            # ch.delete()
        # delete the project database
        # pd.deleteNDProject()
        # delete the objects
        pr.delete()
        ds.delete()

        # delete s3 bucket and dynamo table
        if KV_ENGINE == REDIS:
            CuboidIndexDB.deleteTable()
            CuboidBucket.deleteBucket()
    except Exception, e:
        print(e)
        raise e
Exemple #13
0
                                              content_type="application/json")
        else:
            ds.create()
            DATASET_CREATED = True
            # pr.dataset_id = ds.dataset_name

        # extracting project and token
        pr, tk = extractProjectDict(project_dict)
        pr = NDProject.fromJson(ds.dataset_name, pr)
        pr.user_id = 1
        pr.kvengine = REDIS

        # Checking if the posted project already exists
        # Setting the foreign key for project
        if Project.objects.filter(project_name=pr.project_name).exists():
            stored_pr = NDProject.fromName(pr.project_name)
            # Checking if the existing project is same as the posted one, here we compare their datasets since python behaves wierdly with sub-objects in other objects. this is not fool-proof but works as a good hack
            tk = NDToken.fromJson(pr.project_name, tk)
            tk.user_id = 1
            if compareModelObjects(stored_pr.datasetcfg, pr.datasetcfg):
                if Token.objects.filter(token_name=tk.token_name).exists():
                    stored_tk = NDToken.fromName(tk.token_name)
                    # tk.project_id = stored_pr.project_name
                    # Checking if the existing token is same as the posted one
                    if compareModelObjects(stored_tk, tk):
                        pass
                    else:
                        if DATASET_CREATED:
                            ds.delete()
                        logger.error("Token {} already exists.".format(
                            tk.token_name))
Exemple #14
0
        return HttpResponseBadRequest(json.dumps("Dataset {} already exists and is different then the chosen dataset. Please choose a different dataset name".format(ds.dataset_name)), content_type="application/json")
    else:
      ds.create()
      DATASET_CREATED = True
      # pr.dataset_id = ds.dataset_name

    # extracting project and token 
    pr, tk = extractProjectDict(project_dict)
    pr = NDProject.fromJson(ds.dataset_name, pr)
    pr.user_id = 1
    pr.kvengine = REDIS
    
    # Checking if the posted project already exists
    # Setting the foreign key for project
    if Project.objects.filter(project_name = pr.project_name).exists():
      stored_pr = NDProject.fromName(pr.project_name)
      # Checking if the existing project is same as the posted one, here we compare their datasets since python behaves wierdly with sub-objects in other objects. this is not fool-proof but works as a good hack
      tk = NDToken.fromJson(pr.project_name, tk)
      tk.user_id = 1
      if compareModelObjects(stored_pr.datasetcfg, pr.datasetcfg):
        if Token.objects.filter(token_name = tk.token_name).exists():
          stored_tk = NDToken.fromName(tk.token_name)
          # tk.project_id = stored_pr.project_name
          # Checking if the existing token is same as the posted one
          if compareModelObjects(stored_tk, tk):
            pass
          else:
            if DATASET_CREATED:
              ds.delete()
            logger.error("Token {} already exists.".format(tk.token_name))
            return HttpResponseBadRequest(json.dumps("Token {} already exists. Please choose a different token name.".format(tk.token_name)), content_type="application/json")