Skip to content

Commit

Permalink
space: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nlewo committed Jun 12, 2024
1 parent 28d4cc2 commit d36b91f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions internal/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func (m Manager) onDeployment(ctx context.Context, deploymentResult deployment.D
m.isRunning = false
m.prometheus.SetDeploymentInfo(m.deployment.Generation.SelectedCommitId, deployment.StatusToString(m.deployment.Status))
m.storage.DeploymentInsertAndCommit(m.deployment)
m.space.AgentUpdate(m.deployment)
return m
}

Expand Down
4 changes: 2 additions & 2 deletions internal/space/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions internal/space/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func New(agentName, agentMachineID string) Space {
apiKeyFilepath := os.Getenv("COMIN_SPACE_API_KEY_FILEPATH")
apiKey, err := os.ReadFile(apiKeyFilepath)
if err != nil {
logrus.Errorf("Could not read the password in the file %s: %s", apiKeyFilepath, err)
logrus.Errorf("space: could not read the password in the file %s: %s", apiKeyFilepath, err)
}
url := os.Getenv("COMIN_SPACE_URL")
return Space{
Expand All @@ -42,9 +42,9 @@ func (s *Space) agentRegister(name, machineID string) error {
req.Header.Set("Authorization", "token "+s.apiKey)
return nil
}
c, err := NewClientWithResponses(s.url, WithHTTPClient(&hc), WithRequestEditorFn(reqEditor))
c, err := NewClientWithResponses(s.url+"/api", WithHTTPClient(&hc), WithRequestEditorFn(reqEditor))
if err != nil {
return err
return fmt.Errorf("space: failed to NewClientWithResponses: %s", err)
}
s.client = c
}
Expand All @@ -57,10 +57,10 @@ func (s *Space) agentRegister(name, machineID string) error {

resp, err := s.client.GetAgentsWithResponse(ctx, &GetAgentsParams{MachineID: &s.agentMachineID})
if err != nil {
return err
return fmt.Errorf("space: failed to GetAgentsWithResponse: %s", err)
}
if resp.StatusCode() != http.StatusOK {
return fmt.Errorf("Expected HTTP 200 but received %d", resp.StatusCode())
return fmt.Errorf("space: expected HTTP 200 but received %d", resp.StatusCode())
}
agents := *resp.JSON200
if len(agents) == 1 {
Expand All @@ -72,10 +72,10 @@ func (s *Space) agentRegister(name, machineID string) error {
}
resp, err := s.client.PostAgentsWithResponse(ctx, newAgent)
if err != nil {
return err
return fmt.Errorf("space: failed to PostAgentsWithResponse: %s", err)
}
if resp.StatusCode() != http.StatusCreated {
return fmt.Errorf("Expected HTTP 201 but received %d", resp.StatusCode())
return fmt.Errorf("space: expected HTTP 201 but received %d", resp.StatusCode())
}
s.agentID = &resp.JSON201.Id
}
Expand Down Expand Up @@ -131,12 +131,12 @@ func (s *Space) AgentUpdate(d deployment.Deployment) {
return
}
if resp.StatusCode() != http.StatusCreated {
logrus.Errorf("Expected HTTP 201 while updating the agent but received %d", resp.StatusCode())
logrus.Errorf("space: expected HTTP 201 while updating the agent but received %d", resp.StatusCode())
return
}

if err := s.deploymentRegister(ctx, d); err != nil {
logrus.Errorf("Fail to register the deployment %s: %s", d.UUID, err)
logrus.Errorf("space: failed to register the deployment %s: %s", d.UUID, err)
} else {
// TODO: convert deployment.UUID to uuid type
uuidStr, _ := uuid.Parse(d.UUID)
Expand All @@ -150,7 +150,7 @@ func (s *Space) AgentUpdate(d deployment.Deployment) {
return
}
if respPatch.StatusCode() != http.StatusOK {
logrus.Errorf("Expected HTTP 200 while patching the agent but received %d", respPatch.StatusCode())
logrus.Errorf("space: expected HTTP 200 while patching the agent but received %d", respPatch.StatusCode())
return
}
}
Expand Down

0 comments on commit d36b91f

Please sign in to comment.