Skip to content

Commit

Permalink
Merge pull request #6 from IBM/update-schemaregistry-sdk
Browse files Browse the repository at this point in the history
update sdk with set schema and schema version state changes
  • Loading branch information
sreee9 authored Sep 20, 2023
2 parents be8b98f + e03cca8 commit ade4734
Show file tree
Hide file tree
Showing 4 changed files with 567 additions and 61 deletions.
61 changes: 59 additions & 2 deletions examples/schema/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func main() {
os.Exit(1)
}

// Set Schema state to DISABLED to be able to delete Schema
setSchemaState(esClient, "DISABLED")

// Try to delete Schema before creating
deleteSchema(esClient)

Expand Down Expand Up @@ -106,14 +109,14 @@ func main() {
// Create Version
err = createVersion(esClient)
if err != nil {
log.Printf("error occurred while creating version")
log.Printf("error occurred while creating version: %q", err)
}
log.Printf("creating version successful")

// Get Version
err = getVersion(esClient)
if err != nil {
log.Printf("error occurred while getting version 2")
log.Printf("error occurred while getting version 2: %q", err)
}
log.Printf("getting version successful")

Expand All @@ -125,6 +128,13 @@ func main() {
}
log.Printf("listing versions successful")

// Set Schema Version state to DISABLED to be able to delete Schema Version
err = setSchemaVersionState(esClient, "DISABLED", 2)
if err != nil {
log.Printf("error occurred while updating the schema to DISABLED state: %q", err)
os.Exit(1)
}

// Delete Version
if err = deleteVersion(esClient); err != nil {
log.Printf("error occurred while deleting the version: %q", err)
Expand Down Expand Up @@ -174,6 +184,13 @@ func main() {
}
log.Printf("deleting schema rule successful")

// Set Schema state to DISABLED to be able to delete Schema
err = setSchemaState(esClient, "DISABLED")
if err != nil {
log.Printf("error occurred while updating the schema to DISABLED state: %q", err)
os.Exit(1)
}

// Delete Schema
if err = deleteSchema(esClient); err != nil {
log.Printf("error occurred while deleting the schema: %q", err)
Expand Down Expand Up @@ -221,6 +238,46 @@ func createSchema(esClient *schemaregistryv1.SchemaregistryV1) error {
return nil
} // func.end

func setSchemaState(esClient *schemaregistryv1.SchemaregistryV1, state string) error {
// Construct an instance of the setSchemaStateOptions
setSchemaStateOptions := esClient.NewSetSchemaStateOptions("schema-id")
setSchemaStateOptions.SetID("schema-id")
setSchemaStateOptions.SetState(state)

// Set the schema state
response, operationErr := esClient.SetSchemaState(setSchemaStateOptions)
if operationErr != nil {
return fmt.Errorf("error updating schema state to %s : %s", state, operationErr.Error())
}

// Check the result
if response.StatusCode != http.StatusNoContent {
operationErr = fmt.Errorf("updating schema state to %s failed with response: %v", state, response)
return operationErr
}
return nil
} // func.end

func setSchemaVersionState(esClient *schemaregistryv1.SchemaregistryV1, state string, version int64) error {
// Construct an instance of the setSchemaStateOptions
setSchemaVersionStateOptions := esClient.NewSetSchemaVersionStateOptions("schema-id", version)
setSchemaVersionStateOptions.SetID("schema-id")
setSchemaVersionStateOptions.SetState(state)

// Set the schema state
response, operationErr := esClient.SetSchemaVersionState(setSchemaVersionStateOptions)
if operationErr != nil {
return fmt.Errorf("error updating schema state to %s : %s", state, operationErr.Error())
}

// Check the result
if response.StatusCode != http.StatusNoContent {
operationErr = fmt.Errorf("updating schema state to %s failed with response: %v", state, response)
return operationErr
}
return nil
} // func.end

func getLatestSchema(esClient *schemaregistryv1.SchemaregistryV1) error {
// Construct an instance of the GetLatestSchemaOptions model
getLatestSchemaOptions := esClient.NewGetLatestSchemaOptions("schema-id")
Expand Down
Loading

0 comments on commit ade4734

Please sign in to comment.