Ejemplo n.º 1
0
func (m *Manta) CreateJob(job []byte) (string, error) {
	if err := m.ProcessFunctionHook(m, job); err != nil {
		return "", err
	}

	jsonJob := new(manta.Job)
	err := json.Unmarshal(job, jsonJob)
	if err != nil {
		return "", err
	}
	jobId, err := localservices.NewUUID()
	if err != nil {
		return "", err
	}
	jsonJob.Id = jobId
	jsonJob.State = "running"
	jsonJob.Cancelled = false
	jsonJob.InputDone = false
	jsonJob.TimeCreated = time.Now().Format(time.RFC3339)

	//create directories
	m.mu.Lock()
	defer m.mu.Unlock()
	realPath := fmt.Sprintf(jobsPrefix, m.ServiceInstance.UserAccount, jobId)
	m.objects[realPath] = createDirectory(jobId)
	realPath = fmt.Sprintf(jobsPrefix, m.ServiceInstance.UserAccount, fmt.Sprintf("%s/stor", jobId))
	m.objects[realPath] = createDirectory("stor")

	m.jobs[jsonJob.Id] = jsonJob
	return fmt.Sprintf("/%s/jobs/%s", m.ServiceInstance.UserAccount, jobId), nil
}
Ejemplo n.º 2
0
// Objects APIs
func (m *Manta) PutObject(path, objName string, objData []byte) error {
	if err := m.ProcessFunctionHook(m, path, objName, objData); err != nil {
		return err
	}

	realPath := fmt.Sprintf(storagePrefix, m.ServiceInstance.UserAccount, path)

	// Check if parent dirs exist
	parents := getParentDirs(m.ServiceInstance.UserAccount, path)
	for _, p := range parents {
		if _, ok := m.objects[p]; !ok {
			return fmt.Errorf("%s was not found", realPath)
		}
	}

	etag, err := localservices.NewUUID()
	if err != nil {
		return err
	}

	obj := manta.Entry{
		Name:  objName,
		Type:  typeObject,
		Mtime: time.Now().Format(time.RFC3339),
		Etag:  etag,
		Size:  len(objData),
	}

	objId := fmt.Sprintf("%s/%s", realPath, objName)
	m.objects[objId] = obj
	m.objectsData[objId] = objData

	return nil
}
Ejemplo n.º 3
0
func createJobObject(objName string, objData []byte) (manta.Entry, error) {
	etag, err := localservices.NewUUID()
	return manta.Entry{
		Name:  objName,
		Type:  typeObject,
		Mtime: time.Now().Format(time.RFC3339),
		Etag:  etag,
		Size:  len(objData),
	}, err
}
Ejemplo n.º 4
0
func (m *Manta) GetJobOutput(id string) (string, error) {
	if err := m.ProcessFunctionHook(m, id); err != nil {
		return "", err
	}

	if job, ok := m.jobs[id]; ok {
		index := len(job.Phases) - 1
		phaseType := job.Phases[index].Type
		outputId, err := localservices.NewUUID()
		if err != nil {
			return "", err
		}
		jobOutput := fmt.Sprintf("/%s/jobs/%s/stor/%s.%d.%s", m.ServiceInstance.UserAccount, id, phaseType, index, outputId)

		return jobOutput, nil
	}

	return "", fmt.Errorf("/%s/jobs/%s/job.json was not found", m.ServiceInstance.UserAccount, id)
}
Ejemplo n.º 5
0
// Link APIs
func (m *Manta) PutSnapLink(path, linkName, location string) error {
	if err := m.ProcessFunctionHook(m, path, linkName, location); err != nil {
		return err
	}

	realPath := fmt.Sprintf(storagePrefix, m.ServiceInstance.UserAccount, path)

	// Check if parent dirs exist
	m.mu.Lock()
	defer m.mu.Unlock()
	parents := getParentDirs(m.ServiceInstance.UserAccount, path)
	for _, p := range parents {
		if _, ok := m.objects[p]; !ok {
			return fmt.Errorf("%s was not found", realPath)
		}
	}

	// Check if location exist
	if _, ok := m.objects[location]; !ok {
		return fmt.Errorf("%s was not found", location)
	}

	etag, err := localservices.NewUUID()
	if err != nil {
		return err
	}

	obj := manta.Entry{
		Name:  linkName,
		Type:  typeObject,
		Mtime: time.Now().Format(time.RFC3339),
		Etag:  etag,
		Size:  len(m.objectsData[location]),
	}

	objId := fmt.Sprintf("%s/%s", realPath, linkName)
	m.objects[objId] = obj
	m.objectsData[objId] = m.objectsData[location]

	return nil
}