Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the REST API endpoint for creating snapshots #4718

Merged
merged 4 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,31 +1,5 @@
package io.apicurio.registry.rest.v3;

import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_FOR_BROWSER;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_NAME;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_PRINCIPAL_ID;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_ROLE_MAPPING;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_RULE;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_RULE_TYPE;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_UPDATE_ROLE;
import static io.apicurio.registry.util.DtoUtil.appAuthPropertyToRegistry;
import static io.apicurio.registry.util.DtoUtil.registryAuthPropertyToApp;

import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipInputStream;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.slf4j.Logger;

import io.apicurio.common.apps.config.Dynamic;
import io.apicurio.common.apps.config.DynamicConfigPropertyDef;
import io.apicurio.common.apps.config.DynamicConfigPropertyDto;
Expand All @@ -46,6 +20,7 @@
import io.apicurio.registry.rest.v3.beans.RoleMapping;
import io.apicurio.registry.rest.v3.beans.RoleMappingSearchResults;
import io.apicurio.registry.rest.v3.beans.Rule;
import io.apicurio.registry.rest.v3.beans.SnapshotMetaData;
import io.apicurio.registry.rest.v3.beans.UpdateConfigurationProperty;
import io.apicurio.registry.rest.v3.beans.UpdateRole;
import io.apicurio.registry.rest.v3.shared.DataExporter;
Expand Down Expand Up @@ -73,6 +48,31 @@
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.slf4j.Logger;

import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipInputStream;

import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_FOR_BROWSER;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_NAME;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_PRINCIPAL_ID;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_ROLE_MAPPING;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_RULE;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_RULE_TYPE;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_UPDATE_ROLE;
import static io.apicurio.registry.util.DtoUtil.appAuthPropertyToRegistry;
import static io.apicurio.registry.util.DtoUtil.registryAuthPropertyToApp;

@ApplicationScoped
@Interceptors({ResponseErrorLivenessCheck.class, ResponseTimeoutReadinessCheck.class})
Expand Down Expand Up @@ -109,7 +109,7 @@ public class AdminResourceImpl implements AdminResource {
@Info(category = "download", description = "Download link expiry", availableSince = "2.1.2.Final")
Supplier<Long> downloadHrefTtl;

private static final void requireParameter(String parameterName, Object parameterValue) {
private static void requireParameter(String parameterName, Object parameterValue) {
if (parameterValue == null) {
throw new MissingRequiredParameterException(parameterName);
}
Expand All @@ -135,8 +135,9 @@ public List<ArtifactTypeInfo> listArtifactTypes() {

@Override
@Authorized(style=AuthorizedStyle.None, level=AuthorizedLevel.Admin)
public void triggerSnapshot() {
public SnapshotMetaData triggerSnapshot() {
storage.triggerSnapshotCreation();
return SnapshotMetaData.builder().build();
}

/**
Expand Down Expand Up @@ -381,7 +382,7 @@ public List<ConfigurationProperty> listConfigProperties() {
// Return value is the set of all dynamic config properties, with either configured or default values (depending
// on whether the value is actually configured and stored in the DB or not).
return dynamicPropertyIndex.getAcceptedPropertyNames().stream()
.sorted((pname1, pname2) -> pname1.compareTo(pname2))
.sorted(String::compareTo)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

.map(pname -> propsI.containsKey(pname) ? V3ApiUtil.dtoToConfigurationProperty(dynamicPropertyIndex.getProperty(pname), propsI.get(pname)) : defToConfigurationProperty(dynamicPropertyIndex.getProperty(pname)))
.collect(Collectors.toList());
}
Expand Down Expand Up @@ -454,7 +455,7 @@ private ConfigurationProperty defToConfigurationProperty(DynamicConfigPropertyDe

/**
* Lookup the dynamic configuration property being set. Ensure that it exists (throws
* a {@link NotFoundException} if it does not.
* a {@link io.apicurio.registry.storage.error.NotFoundException} if it does not.
* @param propertyName the name of the dynamic property
* @return the dynamic config property definition
*/
Expand Down
29 changes: 25 additions & 4 deletions common/src/main/resources/META-INF/openapi.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{

Check warning on line 1 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-api-servers

Check warning on line 1 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

rhoas-servers-config
"openapi": "3.0.3",
"info": {
"title": "Apicurio Registry API [v3]",
Expand All @@ -14,7 +14,7 @@
"url": "https://www.apache.org/licenses/LICENSE-2.0"
}
},
"paths": {

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-media-example "value" property type must be string

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-schema-example "version" property type must be string

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-schema-example "example" property must be equal to one of the allowed values: "OUTBOUND", "INBOUND". Did you mean "INBOUND"?

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-schema-example "example" property must have required property "group"

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-schema-example "content" property must have required property "contentType"

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-schema-example "example" property must match pattern "^[a-zA-Z0-9._\-+]{1,256}$"

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-schema-example "example" property must have required property "groupId"

Check warning on line 17 in common/src/main/resources/META-INF/openapi.json

View workflow job for this annotation

GitHub Actions / Validate

oas3-valid-schema-example "createdOn" property must match format "date-time"
"/ids/globalIds/{globalId}": {
"summary": "Access artifact content utilizing an artifact version's globally unique identifier.",
"get": {
Expand Down Expand Up @@ -2482,18 +2482,24 @@
"description": "Gets a list of all the configured artifact types.\n\nThis operation can fail for the following reasons:\n\n* A server error occurred (HTTP error `500`)\n"
}
},
"/admin/config/triggerSnapshot": {
"/admin/snapshots": {
"summary": "Triggers a snapshot of the Registry storage. Only supported in KafkaSQL storage",
"get": {
"post": {
"tags": [
"KafkaSQL",
"Admin",
"Snapshot"
],
"responses": {
"200": {
"content": {},
"description": "Empty content. A 200 means that the snapshot has been successfully triggered."
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SnapshotMetaData"
}
}
},
"description": "The snapshot has been successfully triggered."
},
"500": {
"$ref": "#/components/responses/ServerError"
Expand Down Expand Up @@ -4442,6 +4448,21 @@
"createdOn"
],
"type": "string"
},
"SnapshotMetaData": {
"title": "Root Type for SnapshotMetaData",
"description": "",
"required": [
"snapshotId"
],
"type": "object",
"properties": {
"snapshotId": {
"description": "",
"type": "string"
}
},
"example": {}
}
},
"responses": {
Expand Down
86 changes: 0 additions & 86 deletions go-sdk/pkg/registryclient-v2/models/new_comment_escaped.go

This file was deleted.

5 changes: 5 additions & 0 deletions go-sdk/pkg/registryclient-v3/admin/admin_request_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,8 @@ func (m *AdminRequestBuilder) RoleMappings() *RoleMappingsRequestBuilder {
func (m *AdminRequestBuilder) Rules() *RulesRequestBuilder {
return NewRulesRequestBuilderInternal(m.BaseRequestBuilder.PathParameters, m.BaseRequestBuilder.RequestAdapter)
}

// Snapshots triggers a snapshot of the Registry storage. Only supported in KafkaSQL storage
func (m *AdminRequestBuilder) Snapshots() *SnapshotsRequestBuilder {
return NewSnapshotsRequestBuilderInternal(m.BaseRequestBuilder.PathParameters, m.BaseRequestBuilder.RequestAdapter)
}

This file was deleted.

70 changes: 70 additions & 0 deletions go-sdk/pkg/registryclient-v3/admin/snapshots_request_builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package admin

import (
"context"
i00eb2e63d156923d00d8e86fe16b5d74daf30e363c9f185a8165cb42aa2f2c71 "github.com/apicurio/apicurio-registry/go-sdk/pkg/registryclient-v3/models"
i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f "github.com/microsoft/kiota-abstractions-go"
)

// SnapshotsRequestBuilder triggers a snapshot of the Registry storage. Only supported in KafkaSQL storage
type SnapshotsRequestBuilder struct {
i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.BaseRequestBuilder
}

// SnapshotsRequestBuilderPostRequestConfiguration configuration for the request such as headers, query parameters, and middleware options.
type SnapshotsRequestBuilderPostRequestConfiguration struct {
// Request headers
Headers *i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.RequestHeaders
// Request options
Options []i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.RequestOption
}

// NewSnapshotsRequestBuilderInternal instantiates a new SnapshotsRequestBuilder and sets the default values.
func NewSnapshotsRequestBuilderInternal(pathParameters map[string]string, requestAdapter i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.RequestAdapter) *SnapshotsRequestBuilder {
m := &SnapshotsRequestBuilder{
BaseRequestBuilder: *i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.NewBaseRequestBuilder(requestAdapter, "{+baseurl}/admin/snapshots", pathParameters),
}
return m
}

// NewSnapshotsRequestBuilder instantiates a new SnapshotsRequestBuilder and sets the default values.
func NewSnapshotsRequestBuilder(rawUrl string, requestAdapter i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.RequestAdapter) *SnapshotsRequestBuilder {
urlParams := make(map[string]string)
urlParams["request-raw-url"] = rawUrl
return NewSnapshotsRequestBuilderInternal(urlParams, requestAdapter)
}

// Post triggers the creation of a snapshot of the internal database for compatible storages.This operation can fail for the following reasons:* A server error occurred (HTTP error `500`)
func (m *SnapshotsRequestBuilder) Post(ctx context.Context, requestConfiguration *SnapshotsRequestBuilderPostRequestConfiguration) (i00eb2e63d156923d00d8e86fe16b5d74daf30e363c9f185a8165cb42aa2f2c71.SnapshotMetaDataable, error) {
requestInfo, err := m.ToPostRequestInformation(ctx, requestConfiguration)
if err != nil {
return nil, err
}
errorMapping := i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.ErrorMappings{
"500": i00eb2e63d156923d00d8e86fe16b5d74daf30e363c9f185a8165cb42aa2f2c71.CreateErrorFromDiscriminatorValue,
}
res, err := m.BaseRequestBuilder.RequestAdapter.Send(ctx, requestInfo, i00eb2e63d156923d00d8e86fe16b5d74daf30e363c9f185a8165cb42aa2f2c71.CreateSnapshotMetaDataFromDiscriminatorValue, errorMapping)
if err != nil {
return nil, err
}
if res == nil {
return nil, nil
}
return res.(i00eb2e63d156923d00d8e86fe16b5d74daf30e363c9f185a8165cb42aa2f2c71.SnapshotMetaDataable), nil
}

// ToPostRequestInformation triggers the creation of a snapshot of the internal database for compatible storages.This operation can fail for the following reasons:* A server error occurred (HTTP error `500`)
func (m *SnapshotsRequestBuilder) ToPostRequestInformation(ctx context.Context, requestConfiguration *SnapshotsRequestBuilderPostRequestConfiguration) (*i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.RequestInformation, error) {
requestInfo := i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.NewRequestInformationWithMethodAndUrlTemplateAndPathParameters(i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.POST, m.BaseRequestBuilder.UrlTemplate, m.BaseRequestBuilder.PathParameters)
if requestConfiguration != nil {
requestInfo.Headers.AddAll(requestConfiguration.Headers)
requestInfo.AddRequestOptions(requestConfiguration.Options)
}
requestInfo.Headers.TryAdd("Accept", "application/json")
return requestInfo, nil
}

// WithUrl returns a request builder with the provided arbitrary URL. Using this method means any other path or query parameters are ignored.
func (m *SnapshotsRequestBuilder) WithUrl(rawUrl string) *SnapshotsRequestBuilder {
return NewSnapshotsRequestBuilder(rawUrl, m.BaseRequestBuilder.RequestAdapter)
}
Loading
Loading