Exemplo n.º 1
0
// @Title Download
// @Description Down data set
// @Param	id				query 	int64	true		"The data set id"
// @Param	splitNumber		query 	int64	true		"Data set split number"
// @Param	index			query 	int64	true		"Data set split index"
// @Success 200 {[]byte} data set
// @Failure 403 {string} error description
// @router /download [get]
func (o *DataSetController) DownloadDataSetSlice() {
	id, err := o.GetInt64("id")
	if err != nil {
		log.Println(err)
		FinishRequest(o.Ctx, 403, err.Error())
		return
	}

	splitNumber, err := o.GetInt64("splitNumber")
	if err != nil {
		log.Println(err)
		FinishRequest(o.Ctx, 403, err.Error())
		return
	}

	index, err := o.GetInt64("index")
	if err != nil {
		log.Println(err)
		FinishRequest(o.Ctx, 403, err.Error())
		return
	}

	d, err := models.QueryDataSet(id)
	if err != nil {
		log.Println(err)
		FinishRequest(o.Ctx, 403, err.Error())
		return
	}

	perSplitLineNumber := d.LineNumber
	if d.DropHeader {
		perSplitLineNumber--
	}

	perSplitLineNumber = perSplitLineNumber / splitNumber

	startLineNumber := index * perSplitLineNumber

	dataSetSliceBytes, err := utility.GetFilePointLineData("../store/"+d.FilePath, startLineNumber, perSplitLineNumber)
	if err != nil {
		log.Println(err)
		FinishRequest(o.Ctx, 403, err.Error())
		return
	}

	filename := strings.TrimSuffix(d.FilePath, filepath.Ext(d.FilePath))

	o.Ctx.Output.Header("Content-Description", "File Transfer")
	o.Ctx.Output.Header("Content-Type", "application/octet-stream")
	o.Ctx.Output.Header("Content-Disposition", "attachment; filename="+filename+"-"+strconv.Itoa(int(index))+".d")
	o.Ctx.Output.Header("Content-Transfer-Encoding", "binary")
	o.Ctx.Output.Header("Expires", "0")
	o.Ctx.Output.Header("Cache-Control", "must-revalidate")
	o.Ctx.Output.Header("Pragma", "public")
	o.Ctx.Output.Body(dataSetSliceBytes)
}
Exemplo n.º 2
0
// @Title Submit
// @Description Submit a new job
// @Param	dataSetId	form 	int64	true		"The job used data set id"
// @Param	pluginId	form 	int64	true		"The job used plugin id"
// @Param	splitNumber	form 	int64	true		"Job split number"
// @Success 200 {string} the job id
// @Failure 403 {string} error description
// @router /submit [post]
func (o *JobController) Submit() {
	dataSetId, err := o.GetInt64("dataSetId")
	if err != nil {
		log.Println(err)
		FinishRequest(o.Ctx, 403, err.Error())
		return
	}

	pluginId, err := o.GetInt64("pluginId")
	if err != nil {
		log.Println(err)
		FinishRequest(o.Ctx, 403, err.Error())
		return
	}

	splitNumber, err := o.GetInt64("splitNumber")
	if err != nil {
		log.Println(err)
		FinishRequest(o.Ctx, 403, err.Error())
		return
	}

	d, err := models.QueryDataSet(dataSetId)
	if err != nil {
		log.Println(err)
		FinishRequest(o.Ctx, 403, err.Error())
		return
	}

	if pluginId != 1 {
		FinishRequest(o.Ctx, 403, "unknow plugin id")
		return
	}

	if splitNumber <= 0 {
		FinishRequest(o.Ctx, 403, "invalid cut number")
		return
	}

	id, err := models.AddJob(d, pluginId, splitNumber)
	if err != nil {
		log.Println(err)
		FinishRequest(o.Ctx, 403, err.Error())
		return
	}

	o.Ctx.WriteString(strconv.Itoa(int(id)))
}
Exemplo n.º 3
0
// @Title Query
// @Description Query data set info
// @Param	id		form 	int64	true		"The data set id"
// @Success 200 {object} controllers.DataSet
// @Failure 403 {string} error description
// @router /query [post]
func (o *DataSetController) Query() {
	id, err := o.GetInt64("id")
	if err != nil {
		log.Println(err)
		FinishRequest(o.Ctx, 403, err.Error())
		return
	}

	d, err := models.QueryDataSet(id)
	if err != nil {
		FinishRequest(o.Ctx, 403, err.Error())
		return
	}
	o.Data["json"] = newDataSet(d)
	o.ServeJson()
}