-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Metrics sets and Job definitions (#85)
- Loading branch information
Showing
30 changed files
with
2,059 additions
and
444 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package anaml | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
func (c *Client) GetMetricsJob(MetricsJobID string) (*MetricsJob, error) { | ||
req, err := http.NewRequest("GET", fmt.Sprintf("%s/metrics-job/%s", c.HostURL, MetricsJobID), nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
body, err := c.doRequest(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if body == nil { | ||
return nil, nil | ||
} | ||
|
||
MetricsJob := MetricsJob{} | ||
err = json.Unmarshal(body, &MetricsJob) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &MetricsJob, nil | ||
} | ||
|
||
func (c *Client) CreateMetricsJob(creationRequest MetricsJob) (*MetricsJob, error) { | ||
rb, err := json.Marshal(creationRequest) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
req, err := http.NewRequest("POST", fmt.Sprintf("%s/metrics-job", c.HostURL), strings.NewReader(string(rb))) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
body, err := c.doRequest(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var V int | ||
err = json.Unmarshal(body, &V) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
creationRequest.ID = V | ||
return &creationRequest, nil | ||
} | ||
|
||
func (c *Client) UpdateMetricsJob(MetricsJobID string, creationRequest MetricsJob) error { | ||
rb, err := json.Marshal(creationRequest) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
req, err := http.NewRequest("PUT", fmt.Sprintf("%s/metrics-job/%s", c.HostURL, MetricsJobID), strings.NewReader(string(rb))) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = c.doRequest(req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *Client) DeleteMetricsJob(MetricsJobID string) error { | ||
req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/metrics-job/%s", c.HostURL, MetricsJobID), nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = c.doRequest(req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package anaml | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
func (c *Client) GetMetricsSet(MetricsSetID string) (*MetricsSet, error) { | ||
req, err := http.NewRequest("GET", fmt.Sprintf("%s/metrics-set/%s", c.HostURL, MetricsSetID), nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
body, err := c.doRequest(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if body == nil { | ||
return nil, nil | ||
} | ||
|
||
MetricsSet := MetricsSet{} | ||
err = json.Unmarshal(body, &MetricsSet) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &MetricsSet, nil | ||
} | ||
|
||
func (c *Client) CreateMetricsSet(creationRequest MetricsSet) (*MetricsSet, error) { | ||
rb, err := json.Marshal(creationRequest) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
req, err := http.NewRequest("POST", fmt.Sprintf("%s/metrics-set", c.HostURL), strings.NewReader(string(rb))) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
body, err := c.doRequest(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var V int | ||
err = json.Unmarshal(body, &V) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
creationRequest.ID = V | ||
return &creationRequest, nil | ||
} | ||
|
||
func (c *Client) UpdateMetricsSet(MetricsSetID string, creationRequest MetricsSet) error { | ||
rb, err := json.Marshal(creationRequest) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
req, err := http.NewRequest("PUT", fmt.Sprintf("%s/metrics-set/%s", c.HostURL, MetricsSetID), strings.NewReader(string(rb))) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = c.doRequest(req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *Client) DeleteMetricsSet(MetricsSetID string) error { | ||
req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/metrics-set/%s", c.HostURL, MetricsSetID), nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = c.doRequest(req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.