swagger_server/controllers/inputs_controller.py
def mqtt_input_put(id, dataset):  # noqa: E501
    """Submits data to the framework

     # noqa: E501

    :param id: ID of the data source
    :type id: str
    :param dataset: Dataset submitted to the framework
    :type dataset: dict | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        try:
            dataset = MQTTInputSource.from_dict(connexion.request.get_json())  # noqa: E501
            dataset = connexion.request.get_json()
            logger.info("This is the dictionary: " + str(dataset))
            input_header_validation(dataset)
            # check if the file exists
            dir = os.path.join(os.getcwd(), "optimization/resources", str(id))
            if not os.path.exists(dir):
                return "Id not existing"
            else:
                dir_file = os.path.join(dir, "Input.registry.mqtt")
                if os.path.exists(dir_file):
                    # appends information
                    logger.info("Appending information to the mqtt input registry")

                    with open(dir_file, 'r+') as readfile:
                        data = json.load(readfile)
                        for header in dataset:
                            # logger.debug("Header 1: " + str(header))
                            if not header == "generic":
                                # logger.debug("Not generic")
                                data[header] = dataset[header]
                            elif header == "generic":
                                # logger.debug("Header 1: " + str(header))
                                for key in dataset["generic"]:
                                    # logger.debug("Key: " + str(key))
                                    data["generic"][key] = dataset["generic"][key]

                        readfile.seek(0)
                        logger.debug("Data " + str(data))
                        json.dump(data, readfile)
                        # logger.debug("readfile " + str(readfile))
                        readfile.truncate()
                    logger.info("data source saved into memory")
                else:
                    # saves the registry into the new folder
                    with open(dir_file, 'w') as outfile:
                        json.dump(dataset, outfile, ensure_ascii=False)
                    logger.info("data source saved into memory")

                # store_data(dataset, id, "mqtt")
                return "Data source registered", 200
        except Exception as e:
            logger.error("Invalid data " + str(e))
            return str(e).replace("\"", ""), 400
    else:
        return 'Data is not in json format', 400
Submits data to the framework

     # noqa: E501

    :param id: ID of the data source
    :type id: str
    :param dataset: Dataset submitted to the framework
    :type dataset: dict | bytes

    :rtype: None
    
Submits data to the framework
noqa: E501
Submits data to the framework noqa : E501
def mqtt_input_put(id, dataset):  
    """Submits data to the framework
    :param id: ID of the data source
    :type id: str
    :param dataset: Dataset submitted to the framework
    :type dataset: dict | bytes
    :rtype: None
    """
    if connexion.request.is_json:
        try:
            dataset = MQTTInputSource.from_dict(connexion.request.get_json())  
            dataset = connexion.request.get_json()
            logger.info("This is the dictionary: " + str(dataset))
            input_header_validation(dataset)
            dir = os.path.join(os.getcwd(), "optimization/resources", str(id))
            if not os.path.exists(dir):
                return "Id not existing"
            else:
                dir_file = os.path.join(dir, "Input.registry.mqtt")
                if os.path.exists(dir_file):
                    logger.info("Appending information to the mqtt input registry")
                    with open(dir_file, 'r+') as readfile:
                        data = json.load(readfile)
                        for header in dataset:
                            if not header == "generic":
                                data[header] = dataset[header]
                            elif header == "generic":
                                for key in dataset["generic"]:
                                    data["generic"][key] = dataset["generic"][key]
                        readfile.seek(0)
                        logger.debug("Data " + str(data))
                        json.dump(data, readfile)
                        readfile.truncate()
                    logger.info("data source saved into memory")
                else:
                    with open(dir_file, 'w') as outfile:
                        json.dump(dataset, outfile, ensure_ascii=False)
                    logger.info("data source saved into memory")
                return "Data source registered", 200
        except Exception as e:
            logger.error("Invalid data " + str(e))
            return str(e).replace("\"", ""), 400
    else:
        return 'Data is not in json format', 400
def mqtt_input_put ( id , dataset ) : if connexion . request . is_json : try : dataset = MQTTInputSource . from_dict ( connexion . request . get_json ( ) ) dataset = connexion . request . get_json ( ) logger . info ( "This is the dictionary: " + str ( dataset ) ) input_header_validation ( dataset ) dir = os . path . join ( os . getcwd ( ) , "optimization/resources" , str ( id ) ) if not os . path . exists ( dir ) : return "Id not existing" else : dir_file = os . path . join ( dir , "Input.registry.mqtt" ) if os . path . exists ( dir_file ) : logger . info ( "Appending information to the mqtt input registry" ) with open ( dir_file , 'r+' ) as readfile : data = json . load ( readfile ) for header in dataset : if not header == "generic" : data [ header ] = dataset [ header ] elif header == "generic" : for key in dataset [ "generic" ] : data [ "generic" ] [ key ] = dataset [ "generic" ] [ key ] readfile . seek ( 0 ) logger . debug ( "Data " + str ( data ) ) json . dump ( data , readfile ) readfile . truncate ( ) logger . info ( "data source saved into memory" ) else : with open ( dir_file , 'w' ) as outfile : json . dump ( dataset , outfile , ensure_ascii = False ) logger . info ( "data source saved into memory" ) return "Data source registered" , 200 except Exception as e : logger . error ( "Invalid data " + str ( e ) ) return str ( e ) . replace ( "\"" , "" ) , 400 else : return 'Data is not in json format' , 400
Submits data to the framework
 noqa: E501
Submits data to the framework noqa : E501
# noqa: E501 """Submits data to the framework

     # noqa: E501

    :param id: ID of the data source
    :type id: str
    :param dataset: Dataset submitted to the framework
    :type dataset: dict | bytes

    :rtype: None
    """ # noqa: E501 # check if the file exists # appends information # logger.debug("Header 1: " + str(header)) # logger.debug("Not generic") # logger.debug("Header 1: " + str(header)) # logger.debug("Key: " + str(key)) # logger.debug("readfile " + str(readfile)) # saves the registry into the new folder # store_data(dataset, id, "mqtt")
None
None
id
ID of the data source
ID of the data source
dataset
Dataset submitted to the framework
Dataset submitted to the framework