diff --git a/.github/workflows/dockerimage.yml b/.github/workflows/dockerimage.yml new file mode 100644 index 0000000..24b51cf --- /dev/null +++ b/.github/workflows/dockerimage.yml @@ -0,0 +1,101 @@ +name: Docker + +on: + push: + # Publish `master` as Docker `latest` image. + branches: + - main + + # Publish `v1.2.3` tags as releases. + tags: + - v* + + # Run tests for any PRs. + pull_request: + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: v1.29 + + # Optional: working directory, useful for monorepos + # working-directory: somedir + + # Optional: golangci-lint command line arguments. + # args: --issues-exit-code=0 + + # Optional: show only new issues if it's a pull request. The default value is `false`. + # only-new-issues: true + + # Optional: if set to true then the action will use pre-installed Go. + # skip-go-installation: true + + # Optional: if set to true then the action don't cache or restore ~/go/pkg. + # skip-pkg-cache: true + + # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. + # skip-build-cache: true + + # Run tests. + # See also https://docs.docker.com/docker-hub/builds/automated-testing/ + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Run tests + run: | + if [ -f docker-compose.test.yml ]; then + docker-compose --file docker-compose.test.yml build + docker-compose --file docker-compose.test.yml run sut + else + docker build . --file Dockerfile + fi + + # Push image to GitHub Packages. + # See also https://docs.docker.com/docker-hub/builds/ + push: + # Ensure test job passes before pushing image. + needs: + - test + - golangci + + runs-on: ubuntu-latest + if: github.event_name == 'push' + + steps: + - uses: actions/checkout@v2 + + - name: Build image + run: docker build . --file Dockerfile --tag image + + - name: Log into registry + run: echo "${{ secrets.CR_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Push image + run: | + IMAGE_ID=ghcr.io/${{ github.repository }} + + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + + # Strip "v" prefix from tag name + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + + # Use Docker `latest` tag convention + [ "$VERSION" == "main" ] && VERSION=latest + + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + + docker tag image $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION diff --git a/.gitignore b/.gitignore index 6393669..d2daa6e 100644 --- a/.gitignore +++ b/.gitignore @@ -11,10 +11,6 @@ .mtj.tmp/ # Package Files # -*.jar -*.war -*.nar -*.ear *.zip *.tar.gz *.rar diff --git a/.mvn/extensions.xml b/.mvn/extensions.xml deleted file mode 100644 index 148f779..0000000 --- a/.mvn/extensions.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - fr.brouillard.oss - jgitver-maven-plugin - 1.5.1 - - diff --git a/.mvn/jgitver.config.xml b/.mvn/jgitver.config.xml deleted file mode 100644 index 548cc76..0000000 --- a/.mvn/jgitver.config.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - CONFIGURABLE - - \ No newline at end of file diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java deleted file mode 100644 index b901097..0000000 --- a/.mvn/wrapper/MavenWrapperDownloader.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2007-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import java.net.*; -import java.io.*; -import java.nio.channels.*; -import java.util.Properties; - -public class MavenWrapperDownloader { - - private static final String WRAPPER_VERSION = "0.5.6"; - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" - + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; - - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; - - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; - - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if(mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: " + url); - - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } - - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { - String username = System.getenv("MVNW_USERNAME"); - char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); - Authenticator.setDefault(new Authenticator() { - @Override - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(username, password); - } - }); - } - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } - -} diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties deleted file mode 100644 index 642d572..0000000 --- a/.mvn/wrapper/maven-wrapper.properties +++ /dev/null @@ -1,2 +0,0 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip -wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8b12221..0000000 --- a/.travis.yml +++ /dev/null @@ -1,19 +0,0 @@ -sudo: required -language: java -services: - - docker - -jdk: -- openjdk11 - -notifications: - email: false - -env: - global: - - secure: m4gBucLf7Lh5vzCsTHqgj5a06mBMaRYh9e1D0EIvR8gKcbtGC471yfiX6vKhDbYxU+kHIqrRJ1OH6hoYl+Y4PnG8dNV6x86SP5cHj5mz+gY1jYJz5vj24PZnGYU6lnl8328AsBuOGI4umjFFiNASI/C5KuwRTTku+01+G7HE1VJMX5ny/LJ/K5xJ0UCa6OglHDa0mBbSl3ieKEoIpSCeIYdirSDEqkXzNr6kYgo0y1Sdr9Utyc93Pb145ktM61+kvL1fHixYSl06O4wZPVMp9Ol2DEd0V4l5kdY+DyWIa/MYQVZ521wsI2P8brdC/QKn0ZgWv/isZvFipWZMZosa0Srf2X/EdtzcSMBH8gl91YTshlAz2nyxmI3EVCXZK5XzJzCVgYVLIriuXs2ZsrK4ATeiE3rSF1domkSgTaSaKuBNWTUDe0v2+IqeRRAjviOnALZTFacNPn92jdZztxkPX6kfjC60pSufZ4gXz98lZbykIqoWzsKDjW7GDpCSgUqzHpIDpw57NxlZR57NPJHclGGhDUq4e98G6LvEPnckKfC4CXtsQdgz0pF3P4MSLtp85F/WEYZTsbiVmorHlruDpRpQz695DXjMgB/rj9EKR1chbHPruQb2CZjILDo0Lse1sRVyLLMewVpF9SAQppx1ie6SbmVN2l0/plapocBYxVQ= - - secure: rCoPVidCppZRrlTKfuYZlpbEhGUaTO22Zvrh72RODZ0KPAqElnaM6zZNgToIZWMS7KL0PsnbrjWN2F7+YNHhArUR41WxlFMF/LNWUcJWLlgHSLeEVFrxk8qMLtGyrMFSHKaHrXREqu2Dw/gXpp2Tc7wB3hksQRn9R4yoS/2DcY6g450lMgGimrJH5wrwvfzJPz6Adcy2iy2G9r5QyOsko5j3um5qzPsMOBaJyyleAI8RjPiyYVrdKSI4L65Gg7l9hUAw+Y0Lk1ybpnj/ahgwiQL14Wb/tww7akz/tKkztE7T9qqucKmApTR15dK2CZ/vZfH915OMFqTVFuA2XTOZxnHIZnFknA1gzudZpb4YaxSet73Dr/gynuK6NuRnTFLq7c2NzlQaZhpmHETS4Ei1Akhctyxd11s9rNvdNuZLl8Uz3ZB9Zjodv7iANvh6yD0EeO3kPWJh/fiWTBXOoHJpQ+u1QTjkLnl1r/8cpLXG+WjNSvrlknWn6YmxSoXYbHpItuLB+okEF4b9hk4w7rWLFdEH0acJHzD4bL6qkWtQWCCRI+BrYljIwj+iPakmeCaw6T7IiHzpFnJGfNb/V/Mzl0GFDZXr6cDR8jdU57PBiWTyQykFmVM+GbVmI8ywTlyYh1noNUI0ol1lSD52hWU8OXVMt5Pi/aAaQkOzvTwxGTg= - -script: .travis/build_script.sh - -after_success: .travis/push_script.sh diff --git a/.travis/build_script.sh b/.travis/build_script.sh deleted file mode 100755 index 80a489d..0000000 --- a/.travis/build_script.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -DOCKER_TAG=latest - -if [ -n "${TRAVIS_TAG}" ]; then - DOCKER_TAG=${TRAVIS_TAG} -fi - -if ! [[ -n "$TRAVIS_TAG" || "$TRAVIS_BRANCH" == "master" && "$TRAVIS_EVENT_TYPE" == "push" ]]; then - ./mvnw -B -Pdocker-build -Ddocker.tag="${DOCKER_TAG}" install; -fi diff --git a/.travis/push_script.sh b/.travis/push_script.sh deleted file mode 100755 index af9e236..0000000 --- a/.travis/push_script.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -DOCKER_TAG=latest - -if [ -n "$TRAVIS_TAG" -o "$TRAVIS_BRANCH" == "master" -a "$TRAVIS_EVENT_TYPE" == "push" ]; then - if [ -n "${TRAVIS_TAG}" ]; then - DOCKER_TAG=${TRAVIS_TAG} - fi - - ./mvnw -B -Pdocker-build-and-push -Ddocker.tag="$TRAVIS_TAG" install; -fi diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f08475a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM golang:1.17 as build + +WORKDIR /build + +COPY go.mod . +COPY go.sum . + +RUN go mod download + +COPY . . + +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go test ./... + +# -trimpath remove file system paths from executable +# -ldflags arguments passed to go tool link: +# -s disable symbol table +# -w disable DWARF generation +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" . + +FROM gcr.io/distroless/base +COPY --from=build /build/veidemann-contentwriter / + +# api server +EXPOSE 8080/tcp +# prometheus metrics server +EXPOSE 9153/tcp + +ENTRYPOINT ["/veidemann-contentwriter"] diff --git a/README.md b/README.md index 0754000..12feebf 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,4 @@ [![License Apache](https://img.shields.io/github/license/nlnwa/veidemann-contentwriter.svg)](https://github.com/nlnwa/veidemann-contentwriter/blob/master/LICENSE) [![GitHub release](https://img.shields.io/github/release/nlnwa/veidemann-contentwriter.svg)](https://github.com/nlnwa/veidemann-contentwriter/releases/latest) -[![Build Status](https://travis-ci.org/nlnwa/veidemann-contentwriter.svg?branch=master)](https://travis-ci.org/nlnwa/veidemann-contentwriter) # veidemann-contentwriter - -## Build container - - mvn package -Pdocker-build - -## Run integration tests - - mvn verify -Pintegration-tests diff --git a/database/cache.go b/database/cache.go new file mode 100644 index 0000000..733690d --- /dev/null +++ b/database/cache.go @@ -0,0 +1,96 @@ +/* + * Copyright 2021 National Library of Norway. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package database + +import ( + configV1 "github.com/nlnwa/veidemann-api/go/config/v1" + "sync" + "time" +) + +type entry struct { + expires time.Time + configs []*configV1.ConfigObject +} + +type cache struct { + entries map[string]*entry + ttl time.Duration + mu sync.RWMutex +} + +func newCache(ttl time.Duration) *cache { + c := &cache{ + entries: make(map[string]*entry), + ttl: ttl, + } + go func() { + for { + c.purge() + time.Sleep(ttl + 1*time.Minute) + } + }() + return c +} + +func (c *cache) purge() { + c.mu.Lock() + defer c.mu.Unlock() + for key, entry := range c.entries { + if entry != nil && entry.expires.Before(time.Now()) { + delete(c.entries, key) + } + } +} + +func (c *cache) Set(key string, value *configV1.ConfigObject) { + c.SetMany(key, []*configV1.ConfigObject{value}) +} + +func (c *cache) SetMany(key string, values []*configV1.ConfigObject) { + if c.ttl == 0 { + return + } + c.mu.Lock() + defer c.mu.Unlock() + c.entries[key] = &entry{ + expires: time.Now().Add(c.ttl), + configs: values, + } +} + +func (c *cache) Get(key string) *configV1.ConfigObject { + configs := c.GetMany(key) + if len(configs) > 0 { + return configs[0] + } + return nil +} + +func (c *cache) GetMany(key string) []*configV1.ConfigObject { + if c.ttl == 0 { + return nil + } + c.mu.RLock() + defer c.mu.RUnlock() + if result, ok := c.entries[key]; ok { + if result.expires.After(time.Now()) { + return result.configs + } + } + return nil +} diff --git a/database/codec.go b/database/codec.go new file mode 100644 index 0000000..24bd116 --- /dev/null +++ b/database/codec.go @@ -0,0 +1,144 @@ +/* + * Copyright 2021 National Library of Norway. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package database + +import ( + "encoding/json" + "fmt" + configV1 "github.com/nlnwa/veidemann-api/go/config/v1" + "github.com/nlnwa/veidemann-api/go/contentwriter/v1" + frontierV1 "github.com/nlnwa/veidemann-api/go/frontier/v1" + "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/proto" + "gopkg.in/rethinkdb/rethinkdb-go.v6/encoding" + "reflect" + "time" +) + +var decodeConfigObject = func(encoded interface{}, value reflect.Value) error { + b, err := json.Marshal(encoded) + if err != nil { + return fmt.Errorf("error decoding ConfigObject: %w", err) + } + + var co configV1.ConfigObject + unmarshaller := protojson.UnmarshalOptions{ + AllowPartial: true, + DiscardUnknown: true, + } + if err := unmarshaller.Unmarshal(b, &co); err != nil { + return fmt.Errorf("error decoding ConfigObject: %w", err) + } + + value.Set(reflect.ValueOf(&co).Elem()) + return nil +} + +var decodeCrawlExecutionStatus = func(encoded interface{}, value reflect.Value) error { + b, err := json.Marshal(encoded) + if err != nil { + return fmt.Errorf("error decoding CrawlExecutionStatus: %v", err) + } + + var co frontierV1.CrawlExecutionStatus + err = protojson.Unmarshal(b, &co) + if err != nil { + return fmt.Errorf("error decoding CrawlExecutionStatus: %v", err) + } + + value.Set(reflect.ValueOf(&co).Elem()) + return nil +} + +var decodeCrawledContent = func(encoded interface{}, value reflect.Value) error { + b, err := json.Marshal(encoded) + if err != nil { + return fmt.Errorf("error decoding CrawledContent: %w", err) + } + + var co contentwriter.CrawledContent + unmarshaller := protojson.UnmarshalOptions{ + AllowPartial: true, + DiscardUnknown: true, + } + if err := unmarshaller.Unmarshal(b, &co); err != nil { + return fmt.Errorf("error decoding CrawledContent: %w", err) + } + + value.Set(reflect.ValueOf(&co).Elem()) + return nil +} + +var encodeProtoMessage = func(value interface{}) (i interface{}, err error) { + b, err := protojson.Marshal(value.(proto.Message)) + if err != nil { + return nil, fmt.Errorf("error decoding proto message: %w", err) + } + + var m map[string]interface{} + err = json.Unmarshal(b, &m) + if err != nil { + return nil, fmt.Errorf("error encoding proto message: %w", err) + } + return encoding.Encode(m) +} + +func init() { + encoding.SetTypeEncoding( + reflect.TypeOf(&configV1.ConfigObject{}), + encodeProtoMessage, + decodeConfigObject, + ) + encoding.SetTypeEncoding( + reflect.TypeOf(&frontierV1.CrawlExecutionStatus{}), + encodeProtoMessage, + decodeCrawlExecutionStatus, + ) + encoding.SetTypeEncoding( + reflect.TypeOf(&contentwriter.CrawledContent{}), + encodeProtoMessage, + decodeCrawledContent, + ) + encoding.SetTypeEncoding( + reflect.TypeOf(map[string]interface{}{}), + func(value interface{}) (i interface{}, err error) { + m := value.(map[string]interface{}) + for k, v := range m { + switch t := v.(type) { + case string: + // Try to parse string as date + if ti, err := time.Parse(time.RFC3339Nano, t); err == nil { + m[k] = ti + } else { + if m[k], err = encoding.Encode(v); err != nil { + return nil, err + } + } + default: + if m[k], err = encoding.Encode(v); err != nil { + return nil, err + } + } + } + return value, nil + }, + func(encoded interface{}, value reflect.Value) error { + value.Set(reflect.ValueOf(encoded)) + return nil + }, + ) +} diff --git a/database/codec_test.go b/database/codec_test.go new file mode 100644 index 0000000..d16a281 --- /dev/null +++ b/database/codec_test.go @@ -0,0 +1,74 @@ +/* + * Copyright 2021 National Library of Norway. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package database + +import ( + "github.com/nlnwa/veidemann-api/go/contentwriter/v1" + "github.com/stretchr/testify/assert" + "google.golang.org/protobuf/types/known/timestamppb" + "gopkg.in/rethinkdb/rethinkdb-go.v6/encoding" + "testing" + "time" +) + +func TestEncodeCrawledContent(t *testing.T) { + ts := time.Date(2021, 8, 27, 13, 52, 0, 0, time.UTC) + + s := &contentwriter.CrawledContent{ + Digest: "digest", + WarcId: "", + TargetUri: "http://www.example.com", + Date: timestamppb.New(ts), + } + + d, err := encoding.Encode(s) + assert.NoError(t, err) + + expected := map[string]interface{}{ + "date": ts, + "digest": "digest", + "targetUri": "http://www.example.com", + "warcId": "", + } + assert.Equal(t, expected, d) +} + +func TestDecodeCrawledContent(t *testing.T) { + ts := time.Date(2021, 8, 27, 13, 52, 0, 0, time.UTC) + + s := map[string]interface{}{ + "date": ts, + "digest": "digest", + "targetUri": "http://www.example.com", + "warcId": "", + } + + var d contentwriter.CrawledContent + err := encoding.Decode(&d, s) + assert.NoError(t, err) + + expected := contentwriter.CrawledContent{ + Digest: "digest", + WarcId: "", + TargetUri: "http://www.example.com", + Date: timestamppb.New(ts), + } + assert.Equal(t, expected.Date.AsTime(), d.Date.AsTime()) + assert.Equal(t, expected.Digest, d.Digest) + assert.Equal(t, expected.WarcId, d.WarcId) + assert.Equal(t, expected.TargetUri, d.TargetUri) +} diff --git a/database/db.go b/database/db.go new file mode 100644 index 0000000..b9dd6ea --- /dev/null +++ b/database/db.go @@ -0,0 +1,221 @@ +/* + * Copyright 2021 National Library of Norway. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package database + +import ( + "context" + "fmt" + configV1 "github.com/nlnwa/veidemann-api/go/config/v1" + "github.com/nlnwa/veidemann-api/go/contentwriter/v1" + "github.com/rs/zerolog/log" + r "gopkg.in/rethinkdb/rethinkdb-go.v6" + "time" +) + +var logger = log.With().Str("component", "rethinkdb").Logger() + +// RethinkDbConnection holds the database connection +type RethinkDbConnection struct { + connectOpts r.ConnectOpts + session r.QueryExecutor + maxRetries int + waitTimeout time.Duration + queryTimeout time.Duration + batchSize int +} + +type Options struct { + Username string + Password string + Database string + UseOpenTracing bool + Address string + QueryTimeout time.Duration + MaxRetries int + MaxOpenConnections int +} + +// NewRethinkDbConnection creates a new RethinkDbConnection object +func NewRethinkDbConnection(opts Options) *RethinkDbConnection { + return &RethinkDbConnection{ + connectOpts: r.ConnectOpts{ + Address: opts.Address, + Username: opts.Username, + Password: opts.Password, + Database: opts.Database, + InitialCap: 2, + MaxOpen: opts.MaxOpenConnections, + UseOpentracing: opts.UseOpenTracing, + NumRetries: 10, + Timeout: 10 * time.Second, + }, + maxRetries: opts.MaxRetries, + waitTimeout: 60 * time.Second, + queryTimeout: opts.QueryTimeout, + batchSize: 200, + } +} + +// Connect establishes connections +func (c *RethinkDbConnection) Connect() error { + var err error + // Set up database RethinkDbConnection + c.session, err = r.Connect(c.connectOpts) + if err != nil { + return fmt.Errorf("failed to connect to RethinkDB at %s: %w", c.connectOpts.Address, err) + } + logger.Info().Msgf("Connected to RethinkDB at %s", c.connectOpts.Address) + return nil +} + +// Close closes the RethinkDbConnection +func (c *RethinkDbConnection) Close() error { + logger.Info().Msgf("Closing connection to RethinkDB") + return c.session.(*r.Session).Close() +} + +// GetConfigObject fetches a config.ConfigObject referenced by a config.ConfigRef +func (c *RethinkDbConnection) GetConfigObject(ctx context.Context, ref *configV1.ConfigRef) (*configV1.ConfigObject, error) { + term := r.Table("config").Get(ref.Id) + res, err := c.execRead(ctx, "get-config-object", &term) + if err != nil { + return nil, err + } + var result configV1.ConfigObject + err = res.One(&result) + if err != nil { + return nil, err + } + + return &result, nil +} + +func (c *RethinkDbConnection) HasCrawledContent(ctx context.Context, payloadDigest string) (*contentwriter.CrawledContent, error) { + if payloadDigest == "" { + return nil, fmt.Errorf("The required field 'digest' is missing from: 'crawledContent'") + } + + term := r.Table("crawled_content").Get(payloadDigest) + response, err := c.execRead(ctx, "db-hasCrawledContent", &term) + if err != nil { + return nil, err + } + + if response.IsNil() { + return nil, nil + } else { + var res contentwriter.CrawledContent + err := response.One(&res) + return &res, err + } +} + +func (c *RethinkDbConnection) WriteCrawledContent(ctx context.Context, crawledContent *contentwriter.CrawledContent) error { + if crawledContent.Digest == "" { + return fmt.Errorf("The required field 'digest' is missing from: 'crawledContent'") + } + if crawledContent.WarcId == "" { + return fmt.Errorf("The required field 'warc_id' is missing from: 'crawledContent'") + } + if crawledContent.TargetUri == "" { + return fmt.Errorf("The required field 'target_uri' is missing from: 'crawledContent'") + } + if crawledContent.Date == nil { + return fmt.Errorf("The required field 'date' is missing from: 'crawledContent'") + } + + term := r.Table("crawled_content").Insert(crawledContent) + err := c.execWrite(ctx, "db-writeCrawledContent", &term) + if err != nil { + return err + } + return nil +} + +// execRead executes the given read term with a timeout +func (c *RethinkDbConnection) execRead(ctx context.Context, name string, term *r.Term) (*r.Cursor, error) { + q := func(ctx context.Context) (*r.Cursor, error) { + runOpts := r.RunOpts{ + Context: ctx, + } + return term.Run(c.session, runOpts) + } + return c.execWithRetry(ctx, name, q) +} + +// execWrite executes the given write term with a timeout +func (c *RethinkDbConnection) execWrite(ctx context.Context, name string, term *r.Term) error { + q := func(ctx context.Context) (*r.Cursor, error) { + runOpts := r.RunOpts{ + Context: ctx, + Durability: "soft", + } + _, err := (*term).RunWrite(c.session, runOpts) + return nil, err + } + _, err := c.execWithRetry(ctx, name, q) + return err +} + +// execWithRetry executes given query function repeatedly until successful or max retry limit is reached +func (c *RethinkDbConnection) execWithRetry(ctx context.Context, name string, q func(ctx context.Context) (*r.Cursor, error)) (cursor *r.Cursor, err error) { + attempts := 0 + logger := logger.With().Str("operation", name).Logger() +out: + for { + attempts++ + cursor, err = c.exec(ctx, q) + if err == nil { + return + } + logger.Warn().Err(err).Int("retries", attempts-1).Msg("") + switch err { + case r.ErrQueryTimeout: + err := c.wait() + if err != nil { + logger.Warn().Err(err).Msg("") + } + case r.ErrConnectionClosed: + err := c.Connect() + if err != nil { + logger.Warn().Err(err).Msg("") + } + default: + break out + } + if attempts > c.maxRetries { + break + } + } + return nil, fmt.Errorf("failed to %s after %d of %d attempts: %w", name, attempts, c.maxRetries+1, err) +} + +// exec executes the given query with a timeout +func (c *RethinkDbConnection) exec(ctx context.Context, q func(ctx context.Context) (*r.Cursor, error)) (*r.Cursor, error) { + ctx, cancel := context.WithTimeout(ctx, c.queryTimeout) + defer cancel() + return q(ctx) +} + +// wait waits for database to be fully up date and ready for read/write +func (c *RethinkDbConnection) wait() error { + waitOpts := r.WaitOpts{ + Timeout: c.waitTimeout, + } + _, err := r.DB(c.connectOpts.Database).Wait(waitOpts).Run(c.session) + return err +} diff --git a/database/dbadapter.go b/database/dbadapter.go new file mode 100644 index 0000000..dbbc279 --- /dev/null +++ b/database/dbadapter.go @@ -0,0 +1,71 @@ +/* + * Copyright 2021 National Library of Norway. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package database + +import ( + "context" + configV1 "github.com/nlnwa/veidemann-api/go/config/v1" + "github.com/nlnwa/veidemann-api/go/contentwriter/v1" + "time" +) + +type ConfigCache interface { + GetConfigObject(context.Context, *configV1.ConfigRef) (*configV1.ConfigObject, error) + HasCrawledContent(ctx context.Context, revisitKey string) (*contentwriter.CrawledContent, error) + WriteCrawledContent(ctx context.Context, crawledContent *contentwriter.CrawledContent) error +} + +type DbAdapter interface { + GetConfigObject(context.Context, *configV1.ConfigRef) (*configV1.ConfigObject, error) + HasCrawledContent(ctx context.Context, revisitKey string) (*contentwriter.CrawledContent, error) + WriteCrawledContent(ctx context.Context, crawledContent *contentwriter.CrawledContent) error +} + +type configCache struct { + db DbAdapter + cache *cache +} + +func NewConfigCache(db DbAdapter, ttl time.Duration) ConfigCache { + return &configCache{ + db: db, + cache: newCache(ttl), + } +} + +func (cc *configCache) GetConfigObject(ctx context.Context, ref *configV1.ConfigRef) (*configV1.ConfigObject, error) { + cached := cc.cache.Get(ref.Id) + if cached != nil { + return cached, nil + } + + result, err := cc.db.GetConfigObject(ctx, ref) + if err != nil { + return nil, err + } + + cc.cache.Set(result.Id, result) + + return result, nil +} +func (cc *configCache) HasCrawledContent(ctx context.Context, revisitKey string) (*contentwriter.CrawledContent, error) { + return cc.db.HasCrawledContent(ctx, revisitKey) +} + +func (cc *configCache) WriteCrawledContent(ctx context.Context, crawledContent *contentwriter.CrawledContent) error { + return cc.db.WriteCrawledContent(ctx, crawledContent) +} diff --git a/database/dbadapter_test.go b/database/dbadapter_test.go new file mode 100644 index 0000000..72d5934 --- /dev/null +++ b/database/dbadapter_test.go @@ -0,0 +1,91 @@ +/* + * Copyright 2021 National Library of Norway. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package database + +import ( + "context" + configV1 "github.com/nlnwa/veidemann-api/go/config/v1" + "reflect" + "testing" + "time" +) + +var ( + v1 = &configV1.ConfigObject{Kind: configV1.Kind_crawlJob, Id: "1", Meta: &configV1.Meta{Name: "1"}} + v2 = &configV1.ConfigObject{Kind: configV1.Kind_crawlJob, Id: "2", Meta: &configV1.Meta{Name: "2"}} + v3 = &configV1.ConfigObject{Kind: configV1.Kind_crawlJob, Id: "3", Meta: &configV1.Meta{Name: "3"}} +) + +type dbConnMock struct { + *MockConnection + i int +} + +func (d *dbConnMock) GetConfigObject(_ context.Context, _ *configV1.ConfigRef) (*configV1.ConfigObject, error) { + d.i++ + switch d.i { + case 1: + return v1, nil + case 2: + return v2, nil + default: + return v3, nil + } +} + +func TestConfigCacheGet(t *testing.T) { + tests := []struct { + name string + sleep time.Duration + wantFirst *configV1.ConfigObject + wantSecond *configV1.ConfigObject + wantErr bool + }{ + {"same", 10 * time.Millisecond, v1, v1, false}, + {"evicted", 110 * time.Millisecond, v1, v2, false}, + } + for _, tt := range tests { + //i := 0 + t.Run(tt.name, func(t *testing.T) { + cc := NewConfigCache(&dbConnMock{}, 100*time.Millisecond) + ref := &configV1.ConfigRef{Kind: configV1.Kind_crawlJob, Id: "1"} + + gotFirst, err := cc.GetConfigObject(context.Background(), ref) + if (err != nil) != tt.wantErr { + t.Errorf("1 GetConfigObject() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(gotFirst, tt.wantFirst) { + t.Errorf("1 GetConfigObject() got = %v, want %v", gotFirst, tt.wantFirst) + } + + time.Sleep(tt.sleep) + + gotSecond, err := cc.GetConfigObject(context.Background(), ref) + if (err != nil) != tt.wantErr { + t.Errorf("2 GetConfigObject() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(gotSecond, tt.wantSecond) { + t.Errorf("2 GetConfigObject() got = %v, want %v", gotSecond, tt.wantSecond) + } + if gotSecond != tt.wantSecond { + t.Errorf("2 GetConfigObject() got = %v, want %v", gotSecond, tt.wantSecond) + } + }) + } +} diff --git a/database/mock.go b/database/mock.go new file mode 100644 index 0000000..2f28c62 --- /dev/null +++ b/database/mock.go @@ -0,0 +1,63 @@ +/* + * Copyright 2021 National Library of Norway. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package database + +import ( + "context" + configV1 "github.com/nlnwa/veidemann-api/go/config/v1" + "github.com/nlnwa/veidemann-api/go/contentwriter/v1" + r "gopkg.in/rethinkdb/rethinkdb-go.v6" + "time" +) + +type MockConnection struct { + *RethinkDbConnection +} + +// NewMockConnection creates a new mocked RethinkDbConnection object +func NewMockConnection() *MockConnection { + return &MockConnection{ + RethinkDbConnection: &RethinkDbConnection{ + connectOpts: r.ConnectOpts{ + NumRetries: 10, + }, + session: r.NewMock(), + batchSize: 200, + queryTimeout: 5 * time.Second, + }, + } +} + +func (c *MockConnection) Close() error { + return nil +} + +func (c *MockConnection) GetMock() *r.Mock { + return c.session.(*r.Mock) +} + +func (c *MockConnection) GetConfigObject(ctx context.Context, ref *configV1.ConfigRef) (*configV1.ConfigObject, error) { + return c.RethinkDbConnection.GetConfigObject(ctx, ref) +} + +func (c *MockConnection) HasCrawledContent(ctx context.Context, revisitKey string) (*contentwriter.CrawledContent, error) { + return c.RethinkDbConnection.HasCrawledContent(ctx, revisitKey) +} + +func (c *MockConnection) WriteCrawledContent(ctx context.Context, crawledContent *contentwriter.CrawledContent) error { + return c.RethinkDbConnection.WriteCrawledContent(ctx, crawledContent) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6549f37 --- /dev/null +++ b/go.mod @@ -0,0 +1,23 @@ +module github.com/nlnwa/veidemann-contentwriter + +go 1.15 + +require ( + github.com/HdrHistogram/hdrhistogram-go v1.1.0 // indirect + github.com/coreos/etcd v3.3.13+incompatible + github.com/nlnwa/gowarc v1.0.0-alpha.12 + github.com/nlnwa/veidemann-api/go v0.0.0-20210414094839-b36ce92632fe + github.com/opentracing-contrib/go-grpc v0.0.0-20210225150812-73cb765af46e + github.com/opentracing/opentracing-go v1.2.0 + github.com/pkg/errors v0.9.1 + github.com/prometheus/client_golang v1.11.0 + github.com/rs/zerolog v1.23.0 + github.com/spf13/pflag v1.0.5 + github.com/spf13/viper v1.8.1 + github.com/stretchr/testify v1.7.0 + github.com/uber/jaeger-client-go v2.29.1+incompatible + github.com/uber/jaeger-lib v2.4.1+incompatible // indirect + google.golang.org/grpc v1.38.0 + google.golang.org/protobuf v1.26.0 + gopkg.in/rethinkdb/rethinkdb-go.v6 v6.2.1 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..a002d7b --- /dev/null +++ b/go.sum @@ -0,0 +1,822 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= +cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= +cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= +cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= +cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= +cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= +cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= +cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= +cloud.google.com/go v0.72.0/go.mod h1:M+5Vjvlc2wnp6tjzE102Dw08nGShTscUx2nZMufOKPI= +cloud.google.com/go v0.74.0/go.mod h1:VV1xSbzvo+9QJOxLDaJfTjx5e+MePCpCWwvftOeQmWk= +cloud.google.com/go v0.78.0/go.mod h1:QjdrLG0uq+YwhjoVOLsS1t7TW8fs36kLs4XO5R5ECHg= +cloud.google.com/go v0.79.0/go.mod h1:3bzgcEeQlzbuEAYu4mrWhKqWjmpprinYgKJLgKHnbb8= +cloud.google.com/go v0.81.0/go.mod h1:mk/AM35KwGk/Nm2YSeZbxXdrNK3KZOYHmLkOqC2V6E0= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= +cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= +cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= +cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= +cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= +cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= +cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= +cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= +cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= +cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= +cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/HdrHistogram/hdrhistogram-go v1.1.0 h1:6dpdDPTRoo78HxAJ6T1HfMiKSnqhgRRqzCuPshRkQ7I= +github.com/HdrHistogram/hdrhistogram-go v1.1.0/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= +github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= +github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= +github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/bitly/go-hostpool v0.1.0 h1:XKmsF6k5el6xHG3WPJ8U0Ku/ye7njX7W81Ng7O2ioR0= +github.com/bitly/go-hostpool v0.1.0/go.mod h1:4gOCgp6+NZnVqlKyZ/iBZFTAJKembaVENUpMkpg42fw= +github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= +github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.13+incompatible h1:8F3hqu9fGYLBifCmRCJsicFqDx/D68Rt3q1JMazcgBQ= +github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9/ZjdUKyjop4mf3Qdd+1TvvltAvM3m8= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/kit v0.9.0 h1:wDJmvq38kDhkVxi50ni9ykkdUr1PKgqKOoi01fa0Mdk= +github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-logfmt/logfmt v0.5.0 h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih4= +github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= +github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs= +github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645/go.mod h1:6iZfnjpejD4L/4DwD7NryNaJyCQdzwWwH2MWhCA90Kw= +github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8= +github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4= +github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= +github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= +github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= +github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= +github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= +github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= +github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= +github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= +github.com/jroimartin/gocui v0.4.0/go.mod h1:7i7bbj99OgFHzo7kB2zPb8pXLqMBSQegY7azfqXMkyY= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8= +github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/magiconair/properties v1.8.4/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= +github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls= +github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= +github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= +github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= +github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= +github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/nlnwa/gowarc v1.0.0-alpha.12 h1:1xKWGVr+jPqe5g9Sqgg8qScLE/7+o3NZ/IS2vZMYYKg= +github.com/nlnwa/gowarc v1.0.0-alpha.12/go.mod h1:SUvT0iKudUMshYNnv9zGPW5MmxnInlr3ZshFj+UxaTI= +github.com/nlnwa/veidemann-api/go v0.0.0-20210414094839-b36ce92632fe h1:yaxQ13HIpCE+I1ZvcVhM1g+sUAopKAAxtt0k1NBmo2Q= +github.com/nlnwa/veidemann-api/go v0.0.0-20210414094839-b36ce92632fe/go.mod h1:UVGCJSmHATdV3Eohyq03lF3z86q9nRXRQNv3krrEC8I= +github.com/nlnwa/whatwg-url v0.0.0-20200306110950-d1a95e2e8fc3 h1:iarpnapq+Q98GFlSqalcQq9Qc0f5p7hMO/r+65aitOs= +github.com/nlnwa/whatwg-url v0.0.0-20200306110950-d1a95e2e8fc3/go.mod h1:v3hJLcAdjhIn7PA89dVhJ9GSWooX0z2/qPgwlhz0HD8= +github.com/nsf/termbox-go v1.1.1/go.mod h1:T0cTdVuOwf7pHQNtfhnEbzHbcNyCEcVU4YPpouCbVxo= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA= +github.com/opentracing-contrib/go-grpc v0.0.0-20210225150812-73cb765af46e h1:4cPxUYdgaGzZIT5/j0IfqOrrXmq6bG8AwvwisMXpdrg= +github.com/opentracing-contrib/go-grpc v0.0.0-20210225150812-73cb765af46e/go.mod h1:DYR5Eij8rJl8h7gblRrOZ8g0kW1umSpKqYIBTgeDtLo= +github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= +github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= +github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc= +github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ= +github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= +github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= +github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= +github.com/prometheus/client_golang v1.11.0 h1:HNkLOAEQMIDv/K+04rukrLx6ch7msSRwf3/SASFAGtQ= +github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M= +github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= +github.com/prometheus/common v0.26.0 h1:iMAkS2TDoNWnKM+Kopnx/8tnEStIfpYA0ur0xQzzhMQ= +github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= +github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4= +github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= +github.com/prometheus/tsdb v0.7.1 h1:YZcsG11NqnK4czYLrWd9mpEuAJIHVQLwdrleYfszMAA= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= +github.com/rs/zerolog v1.23.0 h1:UskrK+saS9P9Y789yNNulYKdARjPZuS35B8gJF2x60g= +github.com/rs/zerolog v1.23.0/go.mod h1:6c7hFfxPOy7TacJc4Fcdi24/J0NKYGzjG8FWRI916Qo= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/sirupsen/logrus v1.0.6/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= +github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/assertions v1.0.0 h1:UVQPSSmc3qtTi+zPPkCXvZX9VvW/xT/NsRvKfwY81a8= +github.com/smartystreets/assertions v1.0.0/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM= +github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/afero v1.4.1/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= +github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY= +github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= +github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= +github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= +github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= +github.com/spf13/viper v1.8.1 h1:Kq1fyeebqsBfbjZj4EL7gj2IO0mMaiyjYUWcUsl2O44= +github.com/spf13/viper v1.8.1/go.mod h1:o0Pch8wJ9BVSWGQMbra6iw0oQ5oktSIBaujf1rJH9Ns= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= +github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= +github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/uber/jaeger-client-go v2.29.1+incompatible h1:R9ec3zO3sGpzs0abd43Y+fBZRJ9uiH6lXyR/+u6brW4= +github.com/uber/jaeger-client-go v2.29.1+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= +github.com/uber/jaeger-lib v2.4.1+incompatible h1:td4jdvLcExb4cBISKIpHuGoVXh+dVKhn2Um6rjCsSsg= +github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= +github.com/willf/bitset v1.1.10 h1:NotGKqX0KwQ72NUzqrjZq5ipPNDQex9lo3WpaS8L2sc= +github.com/willf/bitset v1.1.10/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= +go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= +go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= +go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= +golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6 h1:QE6XYQK6naiK1EPAe1g/ILLxN5RBoH5xkJk3CqlMI/Y= +golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= +golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190921015927-1a5e07d1ff72/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201026091529-146b70c837a4/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.0.0-20210505214959-0714010a04ed h1:V9kAVxLvz1lkufatrpHuUVyJ/5tR3Ms7rk951P4mI98= +golang.org/x/net v0.0.0-20210505214959-0714010a04ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201027090413-e1471140ff15/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210503173754-0981d6026fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 h1:JWgyZ1qgdTaF3N3oxC+MdTV7qvEEgHo3otj+HB5CM7Q= +golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= +golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE= +golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo= +gonum.org/v1/gonum v0.8.2 h1:CCXrcPKiGGotvnN6jfUsKk4rRqm7q09/YbKb5xCEvtM= +gonum.org/v1/gonum v0.8.2/go.mod h1:oe/vMfY3deqTw+1EZJhuvEW2iwGF1bW9wwu7XCu0+v0= +gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0 h1:OE9mWmgKkjJyEmDAAtGMPjXu+YNeGvK9VTSHY6+Qihc= +gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw= +gonum.org/v1/plot v0.0.0-20190515093506-e2840ee46a6b/go.mod h1:Wt8AAjI+ypCyYX3nZBvf6cAIx93T+c/OS2HFAYskSZc= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= +google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= +google.golang.org/api v0.35.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ1dg= +google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE= +google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8= +google.golang.org/api v0.41.0/go.mod h1:RkxM5lITDfTzmyKFPt+wGrCJbVfniCr2ool8kTBzRTU= +google.golang.org/api v0.43.0/go.mod h1:nQsDGjRXMo4lvh5hP0TKqF244gqhGcr/YSIykhUk/94= +google.golang.org/api v0.44.0/go.mod h1:EBOGZqzyhtvMDoxwS97ctnh0zUmYY6CxqXsc1AvkYD8= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= +google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= +google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201026171402-d4b8fe4fd877/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201201144952-b05cb90ed32e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210222152913-aa3ee6e6a81c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210303154014-9728d6b83eeb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210310155132-4ce2db91004e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210319143718-93e7006c17a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A= +google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c h1:wtujag7C+4D6KMoulW9YauvK2lgdvCMS260jsqqBXr0= +google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= +google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= +google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= +google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.38.0 h1:/9BgsAsa5nWe26HqOlvlgJnqBuktYOLCgjCPqsa56W0= +google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/cenkalti/backoff.v2 v2.2.1 h1:eJ9UAg01/HIHG987TwxvnzK2MgxXq97YY6rYDpY9aII= +gopkg.in/cenkalti/backoff.v2 v2.2.1/go.mod h1:S0QdOvT2AlerfSBkp0O+dk+bbIMaNbEmVk876gPCthU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo= +gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU= +gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/rethinkdb/rethinkdb-go.v6 v6.2.1 h1:d4KQkxAaAiRY2h5Zqis161Pv91A37uZyJOx73duwUwM= +gopkg.in/rethinkdb/rethinkdb-go.v6 v6.2.1/go.mod h1:WbjuEoo1oadwzQ4apSDU+JTvmllEHtsNHS6y7vFc7iw= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= +rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/logger/initlog.go b/logger/initlog.go new file mode 100644 index 0000000..c910dfa --- /dev/null +++ b/logger/initlog.go @@ -0,0 +1,60 @@ +/* + * Copyright 2021 National Library of Norway. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package logger + +import ( + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" + stdlog "log" + "os" + "strings" + "time" +) + +func InitLog(level string, format string, logCaller bool) { + zerolog.TimeFieldFormat = zerolog.TimeFormatUnix + + switch strings.ToLower(level) { + case "panic": + log.Logger = log.Level(zerolog.PanicLevel) + case "fatal": + log.Logger = log.Level(zerolog.FatalLevel) + case "error": + log.Logger = log.Level(zerolog.ErrorLevel) + case "warn": + log.Logger = log.Level(zerolog.WarnLevel) + case "info": + log.Logger = log.Level(zerolog.InfoLevel) + case "debug": + log.Logger = log.Level(zerolog.DebugLevel) + case "trace": + log.Logger = log.Level(zerolog.TraceLevel) + } + + if format == "logfmt" { + log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}) + } + + if logCaller { + log.Logger = log.With().Caller().Logger() + } + + stdlog.SetFlags(0) + stdlog.SetOutput(log.Logger) + + log.Info().Msgf("Setting log level to %s", level) +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..23b52c4 --- /dev/null +++ b/main.go @@ -0,0 +1,114 @@ +package main + +import ( + "fmt" + "github.com/nlnwa/veidemann-contentwriter/database" + "github.com/nlnwa/veidemann-contentwriter/logger" + "github.com/nlnwa/veidemann-contentwriter/server" + "github.com/nlnwa/veidemann-contentwriter/settings" + "github.com/nlnwa/veidemann-contentwriter/telemetry" + "github.com/opentracing/opentracing-go" + "github.com/rs/zerolog/log" + "os" + "os/signal" + "syscall" + "time" + + "github.com/spf13/pflag" + "github.com/spf13/viper" + "strings" +) + +func main() { + pflag.String("interface", "", "interface the browser controller api listens to. No value means all interfaces.") + pflag.Int("port", 8080, "port the browser controller api listens to.") + pflag.String("host-name", "", "") + pflag.String("warc-dir", "", "") + pflag.Int("warc-writer-pool-size", 1, "") + pflag.String("work-dir", "", "") + pflag.Int("termination-grace-period-seconds", 0, "") + + pflag.String("db-host", "rethinkdb-proxy", "DB host") + pflag.Int("db-port", 28015, "DB port") + pflag.String("db-name", "veidemann", "DB name") + pflag.String("db-user", "", "Database username") + pflag.String("db-password", "", "Database password") + pflag.Duration("db-query-timeout", 1*time.Minute, "Database query timeout") + pflag.Int("db-max-retries", 5, "Max retries when database query fails") + pflag.Int("db-max-open-conn", 10, "Max open database connections") + pflag.Bool("db-use-opentracing", false, "Use opentracing for database queries") + pflag.Duration("db-cache-ttl", 5*time.Minute, "How long to cache results from database") + + pflag.String("metrics-interface", "", "Interface for exposing metrics. Empty means all interfaces") + pflag.Int("metrics-port", 9153, "Port for exposing metrics") + pflag.String("metrics-path", "/metrics", "Path for exposing metrics") + + pflag.String("log-level", "info", "log level, available levels are panic, fatal, error, warn, info, debug and trace") + pflag.String("log-formatter", "logfmt", "log formatter, available values are logfmt and json") + pflag.Bool("log-method", false, "log method names") + + pflag.Parse() + _ = viper.BindPFlags(pflag.CommandLine) + + replacer := strings.NewReplacer("-", "_") + viper.SetEnvKeyReplacer(replacer) + viper.AutomaticEnv() + err := viper.BindPFlags(pflag.CommandLine) + if err != nil { + log.Fatal().Err(err).Msg("Could not parse flags") + } + + logger.InitLog(viper.GetString("log-level"), viper.GetString("log-formatter"), viper.GetBool("log-method")) + + db := database.NewRethinkDbConnection( + database.Options{ + Address: fmt.Sprintf("%s:%d", viper.GetString("db-host"), viper.GetInt("db-port")), + Username: viper.GetString("db-user"), + Password: viper.GetString("db-password"), + Database: viper.GetString("db-name"), + QueryTimeout: viper.GetDuration("db-query-timeout"), + MaxOpenConnections: viper.GetInt("db-max-open-conn"), + MaxRetries: viper.GetInt("db-max-retries"), + UseOpenTracing: viper.GetBool("db-use-opentracing"), + }, + ) + if err := db.Connect(); err != nil { + panic(err) + } + defer db.Close() + + configCache := database.NewConfigCache(db, viper.GetDuration("db-cache-ttl")) + contentwriterService := server.New(viper.GetString("interface"), viper.GetInt("port"), settings.ViperSettings{}, configCache) + + // telemetry setup + tracer, closer := telemetry.InitTracer("Scope checker") + if tracer != nil { + opentracing.SetGlobalTracer(tracer) + defer closer.Close() + } + + errc := make(chan error, 1) + + ms := telemetry.NewMetricsServer(viper.GetString("metrics-interface"), viper.GetInt("metrics-port"), viper.GetString("metrics-path")) + go func() { errc <- ms.Start() }() + defer ms.Close() + + go func() { + signals := make(chan os.Signal, 1) + signal.Notify(signals, os.Interrupt, syscall.SIGTERM) + + select { + case err := <-errc: + log.Err(err).Msg("Metrics server failed") + contentwriterService.Shutdown() + case sig := <-signals: + log.Debug().Msgf("Received signal: %s", sig) + contentwriterService.Shutdown() + } + }() + + err = contentwriterService.Start() + if err != nil { + log.Err(err).Msg("Could not start Content writer service") + } +} diff --git a/mvnw b/mvnw deleted file mode 100755 index 41c0f0c..0000000 --- a/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd deleted file mode 100644 index 8611571..0000000 --- a/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 55fb869..0000000 --- a/pom.xml +++ /dev/null @@ -1,496 +0,0 @@ - - - 4.0.0 - com.github.nlnwa - veidemann-contentwriter - 0 - jar - - - National Library of Norway - http://nb.no - - - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - - - UTF-8 - 11 - 11 - - 0.3.3 - 1.0.0-beta14 - 0.4.1 - 0.4.5 - 1.1.1 - 2.14.0 - 2.4.0 - - - ${env.DOCKER_TAG} - - ${env.DOCKER_USERNAME} - - ${env.DOCKER_PASSWORD} - - - - - jitpack.io - https://jitpack.io - - - - - - com.github.nlnwa - veidemann-api - ${veidemann.api.version} - - - com.github.nlnwa - veidemann-rethinkdbadapter - ${veidemann.rethinkdbadapter.version} - - - com.github.nlnwa - veidemann-commons - ${veidemann.commons.version} - - - - - org.jwat - jwat-common - ${org.jwat.version} - - - org.jwat - jwat-gzip - ${org.jwat.version} - - - org.jwat - jwat-warc - ${org.jwat.version} - - - org.jwat - jwat-archive - ${org.jwat.version} - - - - - com.typesafe - config - 1.4.0 - - - - - org.slf4j - slf4j-api - 1.7.26 - - - org.apache.logging.log4j - log4j-api - ${log4j.version} - - - org.apache.logging.log4j - log4j-core - ${log4j.version} - - - org.apache.logging.log4j - log4j-slf4j-impl - ${log4j.version} - - - org.apache.logging.log4j - log4j-jul - ${log4j.version} - - - - - junit - junit - 4.13.1 - test - - - org.assertj - assertj-core - 3.8.0 - test - - - org.mockito - mockito-core - 2.27.0 - test - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.19.1 - - - org.apache.maven.plugins - maven-failsafe-plugin - 3.0.0-M3 - - - io.fabric8 - docker-maven-plugin - 0.29.0 - - - org.apache.maven.plugins - maven-jar-plugin - 3.2.0 - - - com.google.cloud.tools - jib-maven-plugin - 2.0.0 - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - 1C - false - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - true - - - - - - com.google.cloud.tools - jib-maven-plugin - - - docker.io/norsknettarkiv/${project.artifactId} - - - - 8080 - - - /workdir - /warcs - - - /workdir - /warcs - - - -Dfile.encoding=UTF-8 - - - - - - - - - - docker-build - - - - com.google.cloud.tools - jib-maven-plugin - - - package - - dockerBuild - - - - - - - - - - docker-build-and-push - - - - com.google.cloud.tools - jib-maven-plugin - - - package - - build - - - - - - - ${docker.tag} - - - ${docker.username} - ${docker.password} - - - - - - - - - - integration-tests - - - - io.fabric8 - docker-maven-plugin - - - prepare-tests - pre-integration-test - - volume-create - start - - - - - - remove-tests - post-integration-test - - stop - volume-remove - - - - - - - true - true - false - true - - - contentwriter-rethink-data - - - contentwriter-workdir - - - contentwriter-warcs - local - - tmpfs - tmpfs - - - true - - - - - - rethinkdb:${rethinkdb.version} - db - - - custom - contentwriter-test-net - db - - - +db.host:db.port:28015 - +dbgui.host:dbgui.port:8080 - - - - contentwriter-rethink-data:/data - - - - true - - - - - 8080 - 28015 - 29015 - - - - - - - norsknettarkiv/veidemann-db-initializer:${veidemann.rethinkdbadapter.version} - db-initializer - - - custom - contentwriter-test-net - db-initializer - - - db - - - db - admin - - - true - - - 0 - - - - - - norsknettarkiv/veidemann-contentwriter - contentwriter - - - custom - contentwriter-test-net - contentwriter - - - +contentwriter.host:contentwriter.port:8080 - - - db-initializer - - - - contentwriter-warcs:/warcs - contentwriter-workdir:/workdir - - - - db - test-veidemann-contentwriter-uuid - 4 - - - true - - - Veidemann Content Writer .* started - - - - always - - - - - norsknettarkiv/veidemann-contentexplorer - contentexplorer - - - custom - contentwriter-test-net - contentexplorer - - - +contentexplorer.host:contentexplorer.port:8081 - - - db-initializer - - - - contentwriter-warcs:/warcs - contentwriter-workdir:/workdir - - - - db - true - - - true - - - Veidemann Content Explorer .* started - - - - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - - integration-test - verify - - - - - - - ${db.host} - - ${db.port} - - ${contentwriter.host} - - ${contentwriter.port} - - ${contentexplorer.host} - - ${contentexplorer.port} - - - - - - - - diff --git a/server/recordtype.go b/server/recordtype.go new file mode 100644 index 0000000..d31b8ce --- /dev/null +++ b/server/recordtype.go @@ -0,0 +1,68 @@ +/* + * Copyright 2021 National Library of Norway. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package server + +import ( + "github.com/nlnwa/gowarc" + "github.com/nlnwa/veidemann-api/go/contentwriter/v1" +) + +func ToGowarcRecordType(recordType contentwriter.RecordType) gowarc.RecordType { + switch recordType { + case contentwriter.RecordType_WARCINFO: + return gowarc.Warcinfo + case contentwriter.RecordType_RESPONSE: + return gowarc.Response + case contentwriter.RecordType_RESOURCE: + return gowarc.Resource + case contentwriter.RecordType_REQUEST: + return gowarc.Request + case contentwriter.RecordType_METADATA: + return gowarc.Metadata + case contentwriter.RecordType_REVISIT: + return gowarc.Revisit + case contentwriter.RecordType_CONVERSION: + return gowarc.Conversion + case contentwriter.RecordType_CONTINUATION: + return gowarc.Continuation + default: + return 0 + } +} + +func FromGowarcRecordType(recordType gowarc.RecordType) contentwriter.RecordType { + switch recordType { + case gowarc.Warcinfo: + return contentwriter.RecordType_WARCINFO + case gowarc.Response: + return contentwriter.RecordType_RESPONSE + case gowarc.Resource: + return contentwriter.RecordType_RESOURCE + case gowarc.Request: + return contentwriter.RecordType_REQUEST + case gowarc.Metadata: + return contentwriter.RecordType_METADATA + case gowarc.Revisit: + return contentwriter.RecordType_REVISIT + case gowarc.Conversion: + return contentwriter.RecordType_CONVERSION + case gowarc.Continuation: + return contentwriter.RecordType_CONTINUATION + default: + return 0 + } +} diff --git a/server/server.go b/server/server.go new file mode 100644 index 0000000..9ca4c57 --- /dev/null +++ b/server/server.go @@ -0,0 +1,160 @@ +/* + * Copyright 2021 National Library of Norway. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package server + +import ( + "fmt" + "github.com/nlnwa/gowarc" + "github.com/nlnwa/veidemann-contentwriter/database" + "github.com/nlnwa/veidemann-contentwriter/settings" + "google.golang.org/grpc/codes" + "io" + + "github.com/nlnwa/veidemann-api/go/contentwriter/v1" + "github.com/nlnwa/veidemann-contentwriter/telemetry" + otgrpc "github.com/opentracing-contrib/go-grpc" + "github.com/opentracing/opentracing-go" + "github.com/rs/zerolog/log" + "google.golang.org/grpc" + "net" +) + +type GrpcServer struct { + listenHost string + listenPort int + settings settings.Settings + grpcServer *grpc.Server + configCache database.ConfigCache + service *ContentWriterService +} + +func New(host string, port int, settings settings.Settings, configCache database.ConfigCache) *GrpcServer { + s := &GrpcServer{ + listenHost: host, + listenPort: port, + settings: settings, + configCache: configCache, + service: &ContentWriterService{ + settings: settings, + warcWriterRegistry: newWarcWriterRegistry(settings, configCache), + configCache: configCache, + }, + } + return s +} + +func (s *GrpcServer) Start() error { + lis, err := net.Listen("tcp", fmt.Sprintf("%s:%d", s.listenHost, s.listenPort)) + if err != nil { + log.Fatal().Msgf("failed to listen: %v", err) + } + + tracer := opentracing.GlobalTracer() + var opts = []grpc.ServerOption{ + grpc.UnaryInterceptor(otgrpc.OpenTracingServerInterceptor(tracer)), + grpc.StreamInterceptor(otgrpc.OpenTracingStreamServerInterceptor(tracer)), + } + s.grpcServer = grpc.NewServer(opts...) + contentwriter.RegisterContentWriterServer(s.grpcServer, s.service) + + log.Info().Msgf("ContentWriter Service listening on %s", lis.Addr()) + return s.grpcServer.Serve(lis) +} + +func (s *GrpcServer) Shutdown() { + log.Info().Msg("Shutting down ContentWriter Service") + s.grpcServer.GracefulStop() + s.service.warcWriterRegistry.Shutdown() +} + +type ContentWriterService struct { + contentwriter.UnimplementedContentWriterServer + settings settings.Settings + configCache database.ConfigCache + warcWriterRegistry *warcWriterRegistry +} + +func (s *ContentWriterService) Write(stream contentwriter.ContentWriter_WriteServer) error { + telemetry.ScopechecksTotal.Inc() + //telemetry.ScopecheckResponseTotal.With(prometheus.Labels{"code": strconv.Itoa(int(result.ExcludeReason))}).Inc() + ctx := newWriteSessionContext(s.settings, s.configCache) + + for { + request, err := stream.Recv() + if err == io.EOF { + return s.onCompleted(ctx, stream) + } + if err != nil { + log.Err(err).Msgf("Error caught: %s", err.Error()) + ctx.cancelSession(err.Error()) + return err + } + + switch v := request.Value.(type) { + case *contentwriter.WriteRequest_Meta: + log.Trace().Msgf("Got API request %T for %d records", v, len(v.Meta.RecordMeta)) + if err := ctx.setWriteRequestMeta(v.Meta); err != nil { + ctx.cancelSession(err.Error()) + return err + } + case *contentwriter.WriteRequest_ProtocolHeader: + log.Trace().Msgf("Got API request %T for record #%d. Size: %d", v, v.ProtocolHeader.RecordNum, len(v.ProtocolHeader.GetData())) + if err := ctx.writeProtocolHeader(v.ProtocolHeader); err != nil { + return err + } + case *contentwriter.WriteRequest_Payload: + log.Trace().Msgf("Got API request %T for record #%d. Size: %d", v, v.Payload.RecordNum, len(v.Payload.GetData())) + if err := ctx.writePayoad(v.Payload); err != nil { + return err + } + case *contentwriter.WriteRequest_Cancel: + log.Trace().Msgf("Got API request %T", v) + ctx.cancelSession(v.Cancel) + default: + return fmt.Errorf("Invalid request %s", v) + } + } +} + +func (s *ContentWriterService) onCompleted(context *writeSessionContext, stream contentwriter.ContentWriter_WriteServer) error { + if context.canceled { + return context.handleErr(codes.Canceled, "Session canceled") + //return stream.SendAndClose(&contentwriter.WriteReply{}) + } + + if context.meta == nil { + return context.handleErr(codes.InvalidArgument, "Missing metadata object") + } + + if err := context.validateSession(); err != nil { + context.cancelSession("Validation failed: " + err.Error()) + return err + } + + records := make([]gowarc.WarcRecord, len(context.records)) + for i := 0; i < len(records); i++ { + records[i] = context.records[int32(i)] + } + writer := s.warcWriterRegistry.GetWarcWriter(context.collectionConfig, context.meta.RecordMeta[0]) + writeResponseMeta, err := writer.Write(context.meta, records...) + if err != nil { + context.cancelSession("Failed writing record: " + err.Error()) + return err + } + + return stream.SendAndClose(writeResponseMeta) +} diff --git a/server/server_test.go b/server/server_test.go new file mode 100644 index 0000000..c0cdbbe --- /dev/null +++ b/server/server_test.go @@ -0,0 +1,443 @@ +/* + * Copyright 2021 National Library of Norway. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package server + +import ( + "context" + "fmt" + "github.com/coreos/etcd/pkg/fileutil" + "github.com/nlnwa/veidemann-api/go/config/v1" + "github.com/nlnwa/veidemann-api/go/contentwriter/v1" + "github.com/nlnwa/veidemann-contentwriter/database" + "github.com/nlnwa/veidemann-contentwriter/settings" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "google.golang.org/grpc" + "google.golang.org/grpc/test/bufconn" + "google.golang.org/protobuf/types/known/timestamppb" + r "gopkg.in/rethinkdb/rethinkdb-go.v6" + "io/ioutil" + "net" + "os" + "regexp" + "testing" + "time" +) + +const bufSize = 1024 * 1024 +const warcdir = "testdata" + +type serverAndClient struct { + lis *bufconn.Listener + dbMock *r.Mock + server *GrpcServer + clientConn *grpc.ClientConn + client contentwriter.ContentWriterClient +} + +func newServerAndClient() serverAndClient { + serverAndClient := serverAndClient{} + + dbMockConn := database.NewMockConnection() + dbMockConn.GetMock(). + On(r.Table("config").Get("c1")).Return(map[string]interface{}{ + "id": "c1", + "meta": map[string]interface{}{ + "name": "c1", + }, + "collection": map[string]interface{}{ + "collectionDedupPolicy": "HOURLY", + "fileRotationPolicy": "MONTHLY", + }}, nil). + On(r.Table("config").Get("c2")).Return(map[string]interface{}{ + "id": "c2", + "meta": map[string]interface{}{ + "name": "c2", + }, + "collection": map[string]interface{}{ + "collectionDedupPolicy": "HOURLY", + "fileRotationPolicy": "MONTHLY", + "compress": true, + }}, nil) + serverAndClient.dbMock = dbMockConn.GetMock() + + configCache := database.NewConfigCache(dbMockConn, time.Duration(1)) + serverAndClient.lis = bufconn.Listen(bufSize) + server := New("", 0, settings.NewMock(warcdir, 1), configCache) + server.grpcServer = grpc.NewServer() + contentwriter.RegisterContentWriterServer(server.grpcServer, server.service) + go func() { + if err := server.grpcServer.Serve(serverAndClient.lis); err != nil { + panic(fmt.Errorf("Server exited with error: %v", err)) + } + }() + serverAndClient.server = server + + // Set up client + bufDialer := func(context.Context, string) (net.Conn, error) { + return serverAndClient.lis.Dial() + } + ctx := context.Background() + conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(bufDialer), grpc.WithInsecure()) + if err != nil { + panic(fmt.Errorf("Failed to dial bufnet: %v", err)) + } + serverAndClient.clientConn = conn + serverAndClient.client = contentwriter.NewContentWriterClient(conn) + + return serverAndClient +} + +func (s serverAndClient) close() { + s.clientConn.Close() //nolint + s.server.Shutdown() +} + +type writeRequests []*contentwriter.WriteRequest + +var writeReq1 writeRequests = writeRequests{ + &contentwriter.WriteRequest{Value: &contentwriter.WriteRequest_ProtocolHeader{ProtocolHeader: &contentwriter.Data{ + RecordNum: 0, + Data: []byte("GET / HTTP/1.0\r\n" + + "Host: example.com\r\n" + + "Accept-Language: en-US,en;q=0.8,ru;q=0.6\r\n" + + "Referer: http://example.com/foo.html\r\n" + + "Connection: close\r\n" + + "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36\r\n", + ), + }}}, + &contentwriter.WriteRequest{Value: &contentwriter.WriteRequest_ProtocolHeader{ProtocolHeader: &contentwriter.Data{ + RecordNum: 1, + Data: []byte("HTTP/1.1 200 OK\r\n" + + "Date: Tue, 19 Sep 2016 17:18:40 GMT\r\n" + + "Server: Apache/2.0.54 (Ubuntu)\r\n" + + "Last-Modified: Mon, 16 Jun 2013 22:28:51 GMT\r\n" + + "ETag: \"3e45-67e-2ed02ec0\"\r\n" + + "Accept-Ranges: bytes\r\n" + + "Content-Length: 19\r\n" + + "Connection: close\r\n" + + "Content-Type: text/plain\r\n", + ), + }}}, + &contentwriter.WriteRequest{Value: &contentwriter.WriteRequest_Payload{Payload: &contentwriter.Data{ + RecordNum: 1, + Data: []byte("This is the content"), + }}}, + &contentwriter.WriteRequest{Value: &contentwriter.WriteRequest_Meta{Meta: &contentwriter.WriteRequestMeta{ + ExecutionId: "eid1", + TargetUri: "http://www.example.com/foo.html", + RecordMeta: map[int32]*contentwriter.WriteRequestMeta_RecordMeta{ + 0: { + RecordNum: 0, + Type: contentwriter.RecordType_REQUEST, + Size: 268, + RecordContentType: "application/http;msgtype=request", + BlockDigest: "sha1:AD6944346BF47CEACBE14E387EB031FCBDB59227", + PayloadDigest: "sha1:DA39A3EE5E6B4B0D3255BFEF95601890AFD80709", + }, + 1: { + RecordNum: 1, + Type: contentwriter.RecordType_RESPONSE, + Size: 267, + RecordContentType: "application/http;msgtype=response", + BlockDigest: "sha1:4126C2DC27F113BEEC37A46276514CD4300DA10D", + PayloadDigest: "sha1:C37FFB221569C553A2476C22C7DAD429F3492977", + }, + }, + FetchTimeStamp: timestamppb.Now(), + IpAddress: "127.0.0.1", + CollectionRef: &config.ConfigRef{Kind: config.Kind_collection, Id: "c1"}, + }}}, +} + +var writeReq2 writeRequests = writeRequests{ + &contentwriter.WriteRequest{Value: &contentwriter.WriteRequest_ProtocolHeader{ProtocolHeader: &contentwriter.Data{ + RecordNum: 0, + Data: []byte("GET / HTTP/1.0\r\n" + + "Host: example.com\r\n" + + "Accept-Language: en-US,en;q=0.8,ru;q=0.6\r\n" + + "Referer: http://example.com/foo.html\r\n" + + "Connection: close\r\n" + + "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36\r\n", + ), + }}}, + &contentwriter.WriteRequest{Value: &contentwriter.WriteRequest_ProtocolHeader{ProtocolHeader: &contentwriter.Data{ + RecordNum: 1, + Data: []byte("HTTP/1.1 200 OK\r\n" + + "Date: Tue, 19 Sep 2016 17:18:40 GMT\r\n" + + "Server: Apache/2.0.54 (Ubuntu)\r\n" + + "Last-Modified: Mon, 16 Jun 2013 22:28:51 GMT\r\n" + + "ETag: \"3e45-67e-2ed02ec0\"\r\n" + + "Accept-Ranges: bytes\r\n" + + "Content-Length: 19\r\n" + + "Connection: close\r\n" + + "Content-Type: text/plain\r\n", + ), + }}}, + &contentwriter.WriteRequest{Value: &contentwriter.WriteRequest_Payload{Payload: &contentwriter.Data{ + RecordNum: 1, + Data: []byte("This is the content"), + }}}, + &contentwriter.WriteRequest{Value: &contentwriter.WriteRequest_Meta{Meta: &contentwriter.WriteRequestMeta{ + ExecutionId: "eid1", + TargetUri: "http://www.example.com/foo.html", + RecordMeta: map[int32]*contentwriter.WriteRequestMeta_RecordMeta{ + 0: { + RecordNum: 0, + Type: contentwriter.RecordType_REQUEST, + Size: 268, + RecordContentType: "application/http;msgtype=request", + BlockDigest: "sha1:AD6944346BF47CEACBE14E387EB031FCBDB59227", + PayloadDigest: "sha1:DA39A3EE5E6B4B0D3255BFEF95601890AFD80709", + }, + 1: { + RecordNum: 1, + Type: contentwriter.RecordType_RESPONSE, + Size: 267, + RecordContentType: "application/http;msgtype=response", + BlockDigest: "sha1:4126C2DC27F113BEEC37A46276514CD4300DA10D", + PayloadDigest: "sha1:C37FFB221569C553A2476C22C7DAD429F3492977", + }, + }, + FetchTimeStamp: timestamppb.Now(), + IpAddress: "127.0.0.1", + CollectionRef: &config.ConfigRef{Kind: config.Kind_collection, Id: "c2"}, + }}}, +} + +func TestContentWriterService_Write(t *testing.T) { + err := os.Mkdir(warcdir, fileutil.PrivateDirMode) + defer rmDir(warcdir) + require.NoError(t, err) + + now = func() time.Time { + return time.Date(2000, 10, 10, 2, 59, 59, 0, time.UTC) + } + + serverAndClient := newServerAndClient() + serverAndClient.dbMock. + On(r.Table("crawled_content").Get("sha1:C37FFB221569C553A2476C22C7DAD429F3492977:c1_2000101002")). + Return(nil, nil).Once() + + s := map[string]interface{}{ + "date": r.MockAnything(), + "digest": "sha1:C37FFB221569C553A2476C22C7DAD429F3492977:c1_2000101002", + "targetUri": "http://www.example.com/foo.html", + "warcId": r.MockAnything(), + } + + serverAndClient.dbMock. + On(r.Table("crawled_content").Insert(s)).Return(&r.WriteResponse{Inserted: 1}, nil) + + ctx := context.Background() + assert := assert.New(t) + + stream, err := serverAndClient.client.Write(ctx) + assert.NoError(err) + for i, r := range writeReq1 { + err = stream.Send(r) + assert.NoErrorf(err, "Error sending request #%d", i) + } + reply, err := stream.CloseAndRecv() + assert.NoError(err) + assert.Equal(2, len(reply.Meta.RecordMeta)) + + fileNamePattern := `c1_2000101002-\d{14}-0001-\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}.warc` + + assert.Equal(int32(0), reply.Meta.RecordMeta[0].RecordNum) + assert.Equal(contentwriter.RecordType_REQUEST, reply.Meta.RecordMeta[0].Type) + assert.Regexp("", reply.Meta.RecordMeta[0].WarcId) + assert.Equal("sha1:AD6944346BF47CEACBE14E387EB031FCBDB59227", reply.Meta.RecordMeta[0].BlockDigest) + assert.Equal("sha1:DA39A3EE5E6B4B0D3255BFEF95601890AFD80709", reply.Meta.RecordMeta[0].PayloadDigest) + assert.Equal("c1_2000101002", reply.Meta.RecordMeta[0].CollectionFinalName) + assert.Equal("", reply.Meta.RecordMeta[0].RevisitReferenceId) + assert.Regexp("warcfile:"+fileNamePattern+`:\d\d\d$`, reply.Meta.RecordMeta[0].StorageRef) + + assert.Equal(int32(1), reply.Meta.RecordMeta[1].RecordNum) + assert.Equal(contentwriter.RecordType_RESPONSE, reply.Meta.RecordMeta[1].Type) + assert.Regexp("", reply.Meta.RecordMeta[1].WarcId) + assert.Equal("sha1:4126C2DC27F113BEEC37A46276514CD4300DA10D", reply.Meta.RecordMeta[1].BlockDigest) + assert.Equal("sha1:C37FFB221569C553A2476C22C7DAD429F3492977", reply.Meta.RecordMeta[1].PayloadDigest) + assert.Equal("c1_2000101002", reply.Meta.RecordMeta[1].CollectionFinalName) + assert.Equal("", reply.Meta.RecordMeta[1].RevisitReferenceId) + assert.Regexp("warcfile:"+fileNamePattern+`:\d\d\d\d$`, reply.Meta.RecordMeta[1].StorageRef) + + dirHasFilesMatching(t, warcdir, "^"+fileNamePattern+".open$", 1) + serverAndClient.close() + dirHasFilesMatching(t, warcdir, "^"+fileNamePattern+"$", 1) +} + +func TestContentWriterService_Write_Compressed(t *testing.T) { + err := os.Mkdir(warcdir, fileutil.PrivateDirMode) + defer rmDir(warcdir) + require.NoError(t, err) + + now = func() time.Time { + return time.Date(2000, 10, 10, 2, 59, 59, 0, time.UTC) + } + + serverAndClient := newServerAndClient() + serverAndClient.dbMock. + On(r.Table("crawled_content").Get("sha1:C37FFB221569C553A2476C22C7DAD429F3492977:c2_2000101002")). + Return(nil, nil).Once() + + s := map[string]interface{}{ + "date": r.MockAnything(), + "digest": "sha1:C37FFB221569C553A2476C22C7DAD429F3492977:c2_2000101002", + "targetUri": "http://www.example.com/foo.html", + "warcId": r.MockAnything(), + } + + serverAndClient.dbMock. + On(r.Table("crawled_content").Insert(s)).Return(&r.WriteResponse{Inserted: 1}, nil) + + ctx := context.Background() + assert := assert.New(t) + + stream, err := serverAndClient.client.Write(ctx) + assert.NoError(err) + for i, r := range writeReq2 { + err = stream.Send(r) + assert.NoErrorf(err, "Error sending request #%d", i) + } + reply, err := stream.CloseAndRecv() + assert.NoError(err) + assert.Equal(2, len(reply.Meta.RecordMeta)) + + fileNamePattern := `c2_2000101002-\d{14}-0001-\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}.warc.gz` + + assert.Equal(int32(0), reply.Meta.RecordMeta[0].RecordNum) + assert.Equal(contentwriter.RecordType_REQUEST, reply.Meta.RecordMeta[0].Type) + assert.Regexp("", reply.Meta.RecordMeta[0].WarcId) + assert.Equal("sha1:AD6944346BF47CEACBE14E387EB031FCBDB59227", reply.Meta.RecordMeta[0].BlockDigest) + assert.Equal("sha1:DA39A3EE5E6B4B0D3255BFEF95601890AFD80709", reply.Meta.RecordMeta[0].PayloadDigest) + assert.Equal("c2_2000101002", reply.Meta.RecordMeta[0].CollectionFinalName) + assert.Equal("", reply.Meta.RecordMeta[0].RevisitReferenceId) + assert.Regexp("warcfile:"+fileNamePattern+`:\d\d\d$`, reply.Meta.RecordMeta[0].StorageRef) + + assert.Equal(int32(1), reply.Meta.RecordMeta[1].RecordNum) + assert.Equal(contentwriter.RecordType_RESPONSE, reply.Meta.RecordMeta[1].Type) + assert.Regexp("", reply.Meta.RecordMeta[1].WarcId) + assert.Equal("sha1:4126C2DC27F113BEEC37A46276514CD4300DA10D", reply.Meta.RecordMeta[1].BlockDigest) + assert.Equal("sha1:C37FFB221569C553A2476C22C7DAD429F3492977", reply.Meta.RecordMeta[1].PayloadDigest) + assert.Equal("c2_2000101002", reply.Meta.RecordMeta[1].CollectionFinalName) + assert.Equal("", reply.Meta.RecordMeta[1].RevisitReferenceId) + assert.Regexp("warcfile:"+fileNamePattern+`:\d\d\d$`, reply.Meta.RecordMeta[1].StorageRef) + + dirHasFilesMatching(t, warcdir, "^"+fileNamePattern+".open$", 1) + serverAndClient.close() + dirHasFilesMatching(t, warcdir, "^"+fileNamePattern+"$", 1) +} + +func TestContentWriterService_WriteRevisit(t *testing.T) { + err := os.Mkdir(warcdir, fileutil.PrivateDirMode) + defer rmDir(warcdir) + require.NoError(t, err) + + now = func() time.Time { + return time.Date(2000, 10, 10, 2, 59, 59, 0, time.UTC) + } + + serverAndClient := newServerAndClient() + serverAndClient.dbMock. + On(r.Table("crawled_content").Get("sha1:C37FFB221569C553A2476C22C7DAD429F3492977:c1_2000101002")). + Return(map[string]interface{}{ + "date": time.Date(2021, 8, 27, 13, 52, 0, 0, time.UTC), + "digest": "digest", + "targetUri": "http://www.example.com", + "warcId": "", + }, nil).Once() + + ctx := context.Background() + assert := assert.New(t) + + stream, err := serverAndClient.client.Write(ctx) + assert.NoError(err) + for i, r := range writeReq1 { + err = stream.Send(r) + assert.NoErrorf(err, "Error sending request #%d", i) + } + reply, err := stream.CloseAndRecv() + assert.NoError(err) + assert.Equal(2, len(reply.Meta.RecordMeta)) + + fileNamePattern := `c1_2000101002-\d{14}-0001-\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}.warc` + + assert.Equal(int32(0), reply.Meta.RecordMeta[0].RecordNum) + assert.Equal(contentwriter.RecordType_REQUEST, reply.Meta.RecordMeta[0].Type) + assert.Regexp("", reply.Meta.RecordMeta[0].WarcId) + assert.Equal("sha1:AD6944346BF47CEACBE14E387EB031FCBDB59227", reply.Meta.RecordMeta[0].BlockDigest) + assert.Equal("sha1:DA39A3EE5E6B4B0D3255BFEF95601890AFD80709", reply.Meta.RecordMeta[0].PayloadDigest) + assert.Equal("c1_2000101002", reply.Meta.RecordMeta[0].CollectionFinalName) + assert.Equal("", reply.Meta.RecordMeta[0].RevisitReferenceId) + assert.Regexp(`warcfile:`+fileNamePattern+`:\d\d\d`, reply.Meta.RecordMeta[0].StorageRef) + + assert.Equal(int32(1), reply.Meta.RecordMeta[1].RecordNum) + assert.Equal(contentwriter.RecordType_REVISIT, reply.Meta.RecordMeta[1].Type) + assert.Regexp("", reply.Meta.RecordMeta[1].WarcId) + assert.Equal("sha1:C3BAD90968CC446FF64FED82D030AAB5A0B5884A", reply.Meta.RecordMeta[1].BlockDigest) + assert.Equal("sha1:C37FFB221569C553A2476C22C7DAD429F3492977", reply.Meta.RecordMeta[1].PayloadDigest) + assert.Equal("c1_2000101002", reply.Meta.RecordMeta[1].CollectionFinalName) + assert.Equal("", reply.Meta.RecordMeta[1].RevisitReferenceId) + assert.Regexp(`warcfile:`+fileNamePattern+`:\d\d\d\d`, reply.Meta.RecordMeta[1].StorageRef) + + dirHasFilesMatching(t, warcdir, "^"+fileNamePattern+".open$", 1) + serverAndClient.close() + dirHasFilesMatching(t, warcdir, "^"+fileNamePattern+"$", 1) +} + +func dirHasFilesMatching(t *testing.T, dir string, pattern string, count int) bool { + files, err := ioutil.ReadDir(dir) + if err != nil { + panic(err) + } + + found := 0 + p := regexp.MustCompile(pattern) + for _, file := range files { + if p.MatchString(file.Name()) { + found++ + } + } + if found != count { + f := "" + for _, ff := range files { + f += "\n " + ff.Name() + } + return assert.Fail(t, "Wrong number of files in '"+dir+"'", "Expected %d files to match %s, but found %d\nFiles in dir:%s", count, pattern, found, f) + } + return false +} + +func rmDir(dir string) { + files, err := ioutil.ReadDir(dir) + if err != nil { + return + } + + for _, file := range files { + fileName := warcdir + "/" + file.Name() + err = os.Remove(fileName) + if err != nil { + panic(err) + } + } + err = os.Remove(dir) + if err != nil { + panic(err) + } +} diff --git a/server/sessioncontext.go b/server/sessioncontext.go new file mode 100644 index 0000000..88cf906 --- /dev/null +++ b/server/sessioncontext.go @@ -0,0 +1,181 @@ +/* + * Copyright 2019 National Library of Norway. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package server + +import ( + "context" + "fmt" + "github.com/nlnwa/gowarc" + "github.com/nlnwa/veidemann-api/go/config/v1" + "github.com/nlnwa/veidemann-api/go/contentwriter/v1" + "github.com/nlnwa/veidemann-contentwriter/database" + "github.com/nlnwa/veidemann-contentwriter/settings" + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "sync" +) + +type writeSessionContext struct { + log zerolog.Logger + settings settings.Settings + configCache database.ConfigCache + meta *contentwriter.WriteRequestMeta + collectionConfig *config.ConfigObject + records map[int32]gowarc.WarcRecord + recordBuilders map[int32]gowarc.WarcRecordBuilder + payloadStarted map[int32]bool + rbMapSync sync.Mutex + canceled bool +} + +func newWriteSessionContext(settings settings.Settings, configCache database.ConfigCache) *writeSessionContext { + return &writeSessionContext{ + settings: settings, + configCache: configCache, + records: make(map[int32]gowarc.WarcRecord), + recordBuilders: make(map[int32]gowarc.WarcRecordBuilder), + payloadStarted: make(map[int32]bool), + log: log.Logger, + } +} + +func (s *writeSessionContext) handleErr(code codes.Code, msg string, args ...interface{}) error { + m := fmt.Sprintf(msg, args...) + s.log.Error().Msg(m) + return status.Error(code, m) +} + +func (s *writeSessionContext) setWriteRequestMeta(w *contentwriter.WriteRequestMeta) error { + if s.meta == nil { + s.log = log.With().Str("eid", w.ExecutionId).Str("uri", w.TargetUri).Logger() + } + s.meta = w + + if w.CollectionRef == nil { + return s.handleErr(codes.InvalidArgument, "No collection id in request") + } + if w.IpAddress == "" { + return s.handleErr(codes.InvalidArgument, "Missing IP-address") + } + + collectionConfig, err := s.configCache.GetConfigObject(context.TODO(), w.GetCollectionRef()) + if err != nil { + msg := "Error getting collection config " + w.GetCollectionRef().GetId() + s.log.Error().Msg(msg) + return status.Error(codes.Unknown, msg) + } + s.collectionConfig = collectionConfig + if collectionConfig == nil || collectionConfig.Meta == nil || collectionConfig.Spec == nil { + return s.handleErr(codes.Unknown, "Collection with id '%s' is missing or insufficient: %s", w.CollectionRef.Id, collectionConfig.String()) + } + return nil +} + +func (s *writeSessionContext) writeProtocolHeader(header *contentwriter.Data) error { + recordBuilder, err := s.getRecordBuilder(header.RecordNum) + if err != nil { + s.cancelSession(err.Error()) + return err + } + if recordBuilder.Size() != 0 { + err := s.handleErr(codes.InvalidArgument, "Header received twice") + s.cancelSession(err.Error()) + return err + } + if _, err := recordBuilder.Write(header.GetData()); err != nil { + s.cancelSession(err.Error()) + return err + } + return nil +} + +func (s *writeSessionContext) writePayoad(payload *contentwriter.Data) error { + recordBuilder, err := s.getRecordBuilder(payload.RecordNum) + if err != nil { + s.cancelSession(err.Error()) + return err + } + if !s.payloadStarted[payload.RecordNum] { + if _, err := recordBuilder.Write([]byte("\r\n")); err != nil { + s.cancelSession(err.Error()) + return err + } + s.payloadStarted[payload.RecordNum] = true + } + if _, err := recordBuilder.Write(payload.GetData()); err != nil { + s.cancelSession(err.Error()) + return err + } + return nil +} + +func (s *writeSessionContext) getRecordBuilder(recordNum int32) (gowarc.WarcRecordBuilder, error) { + s.rbMapSync.Lock() + defer s.rbMapSync.Unlock() + + if recordBuilder, ok := s.recordBuilders[recordNum]; ok { + return recordBuilder, nil + } + + rb := gowarc.NewRecordBuilder(0, + //gowarc.WithStrictValidation(), + gowarc.WithBufferTmpDir(s.settings.WorkDir()), + gowarc.WithVersion(s.settings.WarcVersion())) + s.recordBuilders[recordNum] = rb + return rb, nil +} + +func (s *writeSessionContext) validateSession() error { + for k, rb := range s.recordBuilders { + recordMeta, ok := s.meta.RecordMeta[k] + if !ok { + return s.handleErr(codes.InvalidArgument, "Missing metadata for record num: %d", k) + } + + rt := ToGowarcRecordType(recordMeta.Type) + rb.SetRecordType(rt) + rb.AddWarcHeader(gowarc.WarcTargetURI, s.meta.TargetUri) + rb.AddWarcHeader(gowarc.WarcIPAddress, s.meta.IpAddress) + rb.AddWarcHeaderTime(gowarc.WarcDate, s.meta.FetchTimeStamp.AsTime()) + rb.AddWarcHeaderInt64(gowarc.ContentLength, recordMeta.Size) + rb.AddWarcHeader(gowarc.ContentType, recordMeta.RecordContentType) + rb.AddWarcHeader(gowarc.WarcBlockDigest, recordMeta.BlockDigest) + if recordMeta.PayloadDigest != "" { + rb.AddWarcHeader(gowarc.WarcPayloadDigest, recordMeta.PayloadDigest) + } + for _, wct := range recordMeta.GetWarcConcurrentTo() { + rb.AddWarcHeader(gowarc.WarcConcurrentTo, "<"+wct+">") + } + + wr, _, err := rb.Build() + if err != nil { + return s.handleErr(codes.InvalidArgument, "Error: %s", err) + } + s.records[k] = wr + } + return nil +} + +func (s *writeSessionContext) cancelSession(cancelReason string) { + s.canceled = true + s.log.Debug().Msgf("Request cancelled before WARC record written. Reason %s", cancelReason) + for _, rb := range s.recordBuilders { + _ = rb.Close() + } +} diff --git a/server/warcinfogenerator.go b/server/warcinfogenerator.go new file mode 100644 index 0000000..fbadc06 --- /dev/null +++ b/server/warcinfogenerator.go @@ -0,0 +1,43 @@ +/* + * Copyright 2021 National Library of Norway. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package server + +import ( + "fmt" + "github.com/nlnwa/gowarc" + "github.com/nlnwa/veidemann-api/go/config/v1" + "os" +) + +func (ww *warcWriter) warcInfoGenerator(recordBuilder gowarc.WarcRecordBuilder) error { + payload := &gowarc.WarcFields{} + payload.Set("format", fmt.Sprintf("WARC File Format %d.%d", ww.settings.WarcVersion().Major(), ww.settings.WarcVersion().Minor())) + payload.Set("collection", ww.collectionConfig.GetMeta().GetName()) + payload.Set("description", ww.collectionConfig.GetMeta().GetDescription()) + if ww.subCollection != config.Collection_UNDEFINED { + payload.Set("subCollection", ww.subCollection.String()) + } + payload.Set("isPartOf", ww.CollectionName()) + h, e := os.Hostname() + if e != nil { + return e + } + payload.Set("host", h) + + _, err := recordBuilder.WriteString(payload.String()) + return err +} diff --git a/server/warcwriter.go b/server/warcwriter.go new file mode 100644 index 0000000..a3686b0 --- /dev/null +++ b/server/warcwriter.go @@ -0,0 +1,305 @@ +/* + * Copyright 2021 National Library of Norway. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package server + +import ( + "context" + "github.com/nlnwa/gowarc" + "github.com/nlnwa/veidemann-api/go/config/v1" + "github.com/nlnwa/veidemann-api/go/contentwriter/v1" + "github.com/nlnwa/veidemann-contentwriter/database" + "github.com/nlnwa/veidemann-contentwriter/settings" + "github.com/rs/zerolog/log" + "google.golang.org/protobuf/types/known/timestamppb" + "strconv" + "sync" + "time" +) + +// now is a function so that tests can override the clock. +var now = time.Now + +const warcFileScheme = "warcfile" + +type warcWriter struct { + settings settings.Settings + collectionConfig *config.ConfigObject + subCollection config.Collection_SubCollectionType + filePrefix string + fileWriter *gowarc.WarcFileWriter + dbAdapter database.DbAdapter + timer *time.Timer + done chan interface{} + lock sync.Mutex +} + +func newWarcWriter(s settings.Settings, db database.DbAdapter, c *config.ConfigObject, recordMeta *contentwriter.WriteRequestMeta_RecordMeta) *warcWriter { + collectionConfig := c.GetCollection() + ww := &warcWriter{ + settings: s, + dbAdapter: db, + collectionConfig: c, + subCollection: recordMeta.GetSubCollection(), + filePrefix: createFilePrefix(c.GetMeta().GetName(), recordMeta.GetSubCollection(), now(), c.GetCollection().GetCollectionDedupPolicy()), + } + ww.initFileWriter() + + rotationPolicy := collectionConfig.GetFileRotationPolicy() + dedupPolicy := collectionConfig.GetCollectionDedupPolicy() + if dedupPolicy != config.Collection_NONE && dedupPolicy < rotationPolicy { + rotationPolicy = dedupPolicy + } + if d, ok := timeToNextRotation(now(), rotationPolicy); ok { + ww.timer = time.NewTimer(d) + ww.done = make(chan interface{}) + go func() { + for { + if !ww.waitForTimer(rotationPolicy) { + break + } + } + }() + } + + return ww +} + +func (ww *warcWriter) CollectionName() string { + return ww.filePrefix[:len(ww.filePrefix)-1] +} + +func (ww *warcWriter) Write(meta *contentwriter.WriteRequestMeta, record ...gowarc.WarcRecord) (*contentwriter.WriteReply, error) { + ww.lock.Lock() + defer ww.lock.Unlock() + revisitKeys := make([]string, len(record)) + for i, r := range record { + r := r + record[i], revisitKeys[i] = ww.detectRevisit(int32(i), r, meta) + defer func() { _ = r.Close() }() + } + results := ww.fileWriter.Write(record...) + var err error + + reply := &contentwriter.WriteReply{ + Meta: &contentwriter.WriteResponseMeta{ + RecordMeta: map[int32]*contentwriter.WriteResponseMeta_RecordMeta{}, + }, + } + + for i, res := range results { + recNum := int32(i) + rec := record[i] + revisitKey := revisitKeys[i] + + if res.Err != nil { + log.Err(res.Err).Msg("Aha!!!") + } + // If writing records faild. Set err to the first error + if err == nil && res.Err != nil { + err = res.Err + } + + if res.Err == nil && revisitKey != "" { + t, err := time.Parse(time.RFC3339, rec.WarcHeader().Get(gowarc.WarcDate)) + if err != nil { + log.Err(err).Msg("Could not write CrawledContent to DB") + } + cr := &contentwriter.CrawledContent{ + Digest: revisitKey, + WarcId: rec.WarcHeader().Get(gowarc.WarcRecordID), + TargetUri: meta.GetTargetUri(), + Date: timestamppb.New(t), + } + if err := ww.dbAdapter.WriteCrawledContent(context.TODO(), cr); err != nil { + log.Err(err).Msg("Could not write CrawledContent to DB") + } + } + storageRef := warcFileScheme + ":" + res.FileName + ":" + strconv.FormatInt(res.FileOffset, 10) + collectionFinalName := ww.filePrefix[:len(ww.filePrefix)-1] + + reply.GetMeta().GetRecordMeta()[recNum] = &contentwriter.WriteResponseMeta_RecordMeta{ + RecordNum: recNum, + Type: FromGowarcRecordType(record[i].Type()), + WarcId: rec.WarcHeader().Get(gowarc.WarcRecordID), + StorageRef: storageRef, + BlockDigest: rec.WarcHeader().Get(gowarc.WarcBlockDigest), + PayloadDigest: rec.WarcHeader().Get(gowarc.WarcPayloadDigest), + RevisitReferenceId: rec.WarcHeader().Get(gowarc.WarcRefersTo), + CollectionFinalName: collectionFinalName, + } + } + return reply, err +} + +func (ww *warcWriter) detectRevisit(recordNum int32, record gowarc.WarcRecord, meta *contentwriter.WriteRequestMeta) (gowarc.WarcRecord, string) { + if record.Type() == gowarc.Response || record.Type() == gowarc.Resource { + digest := record.WarcHeader().Get(gowarc.WarcPayloadDigest) + if digest == "" { + digest = record.WarcHeader().Get(gowarc.WarcBlockDigest) + } + revisitKey := digest + ":" + ww.filePrefix[:len(ww.filePrefix)-1] + duplicate, err := ww.dbAdapter.HasCrawledContent(context.TODO(), revisitKey) + if err != nil { + log.Err(err).Msg("Failed checking for revisit, treating as new object") + } + + if duplicate != nil { + log.Debug().Msgf("Detected %s as a revisit of %s", + record.WarcHeader().Get(gowarc.WarcRecordID), duplicate.GetWarcId()) + ref := &gowarc.RevisitRef{ + Profile: gowarc.ProfileIdenticalPayloadDigest, + TargetRecordId: duplicate.GetWarcId(), + TargetUri: duplicate.GetTargetUri(), + TargetDate: duplicate.GetDate().AsTime().In(time.UTC).Format(time.RFC3339), + } + revisit, err := record.ToRevisitRecord(ref) + if err != nil { + log.Err(err).Msg("Failed checking for revisit, treating as new object") + } + + newRecordMeta := meta.GetRecordMeta()[recordNum] + newRecordMeta.Type = contentwriter.RecordType_REVISIT + newRecordMeta.BlockDigest = revisit.Block().BlockDigest() + if r, ok := revisit.Block().(gowarc.PayloadBlock); ok { + newRecordMeta.PayloadDigest = r.PayloadDigest() + } + + size, err := strconv.ParseInt(revisit.WarcHeader().Get(gowarc.ContentLength), 10, 64) + if err != nil { + log.Err(err).Msg("Failed checking for revisit, treating as new object") + } + newRecordMeta.Size = size + meta.GetRecordMeta()[recordNum] = newRecordMeta + return revisit, "" + } + return record, revisitKey + } + return record, "" +} + +func (ww *warcWriter) initFileWriter() { + log.Debug().Msgf("Initializing filewriter with dir: '%s' and file prefix: '%s'", ww.settings.WarcDir(), ww.filePrefix) + c := ww.collectionConfig.GetCollection() + namer := &gowarc.PatternNameGenerator{ + Directory: ww.settings.WarcDir(), + Prefix: ww.filePrefix, + } + + opts := []gowarc.WarcFileWriterOption{ + gowarc.WithCompression(c.GetCompress()), + gowarc.WithMaxFileSize(c.GetFileSize()), + gowarc.WithFileNameGenerator(namer), + gowarc.WithWarcInfoFunc(ww.warcInfoGenerator), + gowarc.WithMaxConcurrentWriters(ww.settings.WarcWriterPoolSize()), + gowarc.WithAddWarcConcurrentToHeader(true), + } + + ww.fileWriter = gowarc.NewWarcFileWriter(opts...) +} + +func (ww *warcWriter) waitForTimer(rotationPolicy config.Collection_RotationPolicy) bool { + select { + case <-ww.done: + case <-ww.timer.C: + c := ww.collectionConfig.GetCollection() + prefix := createFilePrefix(ww.collectionConfig.GetMeta().GetName(), ww.subCollection, now(), c.GetCollectionDedupPolicy()) + if prefix != ww.filePrefix { + ww.lock.Lock() + defer ww.lock.Unlock() + ww.filePrefix = prefix + if err := ww.fileWriter.Close(); err != nil { + log.Err(err).Msg("failed closing file writer") + } + ww.fileWriter = nil + ww.initFileWriter() + } else { + if err := ww.fileWriter.Rotate(); err != nil { + log.Err(err).Msg("failed rotating file") + } + } + + if d, ok := timeToNextRotation(now(), rotationPolicy); ok { + ww.timer.Reset(d) + } + return true + } + + // We still need to check the return value + // of Stop, because timer could have fired + // between the receive on done and this line. + if !ww.timer.Stop() { + <-ww.timer.C + } + return false +} + +func (ww *warcWriter) Shutdown() { + if ww.timer != nil { + close(ww.done) + } + if err := ww.fileWriter.Close(); err != nil { + log.Err(err).Msg("failed closing file writer") + } +} + +func timeToNextRotation(now time.Time, p config.Collection_RotationPolicy) (time.Duration, bool) { + var t2 time.Time + + switch p { + case config.Collection_HOURLY: + t2 = time.Date(now.Year(), now.Month(), now.Day(), now.Hour()+1, 0, 0, 0, now.Location()) + case config.Collection_DAILY: + t2 = time.Date(now.Year(), now.Month(), now.Day()+1, 0, 0, 0, 0, now.Location()) + case config.Collection_MONTHLY: + t2 = time.Date(now.Year(), now.Month()+1, 1, 0, 0, 0, 0, now.Location()) + case config.Collection_YEARLY: + t2 = time.Date(now.Year()+1, 1, 1, 0, 0, 0, 0, now.Location()) + default: + return 0, false + } + + d := t2.Sub(now) + return d, true +} + +func createFileRotationKey(now time.Time, p config.Collection_RotationPolicy) string { + switch p { + case config.Collection_HOURLY: + return now.Format("2006010215") + case config.Collection_DAILY: + return now.Format("20060102") + case config.Collection_MONTHLY: + return now.Format("200601") + case config.Collection_YEARLY: + return now.Format("2006") + default: + return "" + } +} + +func createFilePrefix(collectionName string, subCollection config.Collection_SubCollectionType, ts time.Time, dedupPolicy config.Collection_RotationPolicy) string { + if subCollection != config.Collection_UNDEFINED { + collectionName += "_" + subCollection.String() + } + + dedupRotationKey := createFileRotationKey(ts, dedupPolicy) + if dedupRotationKey == "" { + return collectionName + "-" + } else { + return collectionName + "_" + dedupRotationKey + "-" + } +} diff --git a/server/warcwriterregistry.go b/server/warcwriterregistry.go new file mode 100644 index 0000000..c194b49 --- /dev/null +++ b/server/warcwriterregistry.go @@ -0,0 +1,59 @@ +/* + * Copyright 2021 National Library of Norway. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package server + +import ( + "github.com/nlnwa/veidemann-api/go/config/v1" + "github.com/nlnwa/veidemann-api/go/contentwriter/v1" + "github.com/nlnwa/veidemann-contentwriter/database" + "github.com/nlnwa/veidemann-contentwriter/settings" + "sync" +) + +type warcWriterRegistry struct { + settings settings.Settings + dbAdapter database.DbAdapter + warcWriters map[string]*warcWriter + lock sync.Mutex +} + +func newWarcWriterRegistry(settings settings.Settings, db database.DbAdapter) *warcWriterRegistry { + return &warcWriterRegistry{settings: settings, warcWriters: make(map[string]*warcWriter), dbAdapter: db} +} + +func (w *warcWriterRegistry) GetWarcWriter(collectionConf *config.ConfigObject, recordMeta *contentwriter.WriteRequestMeta_RecordMeta) *warcWriter { + w.lock.Lock() + defer w.lock.Unlock() + + key := collectionConf.GetMeta().GetName() + "#" + recordMeta.GetSubCollection().String() + if ww, ok := w.warcWriters[key]; ok { + return ww + } + + ww := newWarcWriter(w.settings, w.dbAdapter, collectionConf, recordMeta) + w.warcWriters[key] = ww + return ww +} + +func (w *warcWriterRegistry) Shutdown() { + w.lock.Lock() + defer w.lock.Unlock() + + for _, ww := range w.warcWriters { + ww.Shutdown() + } +} diff --git a/server/warcwriterregistry_test.go b/server/warcwriterregistry_test.go new file mode 100644 index 0000000..528d581 --- /dev/null +++ b/server/warcwriterregistry_test.go @@ -0,0 +1,157 @@ +/* + * Copyright 2021 National Library of Norway. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package server + +import ( + "github.com/nlnwa/gowarc" + "github.com/nlnwa/veidemann-api/go/config/v1" + "github.com/stretchr/testify/assert" + "regexp" + "testing" + "time" +) + +func Test_timeToNextRotation(t *testing.T) { + ts1 := time.Date(2021, 1, 1, 0, 0, 0, 0, time.Local) + ts2 := time.Date(2021, 11, 20, 11, 29, 59, 0, time.Local) + ts3 := time.Date(2021, 12, 31, 23, 59, 59, 0, time.Local) + type args struct { + now time.Time + p config.Collection_RotationPolicy + } + tests := []struct { + name string + args args + want time.Duration + wantOk bool + }{ + {"none", args{ts1, config.Collection_NONE}, 0, false}, + {"none", args{ts2, config.Collection_NONE}, 0, false}, + {"none", args{ts3, config.Collection_NONE}, 0, false}, + {"hourly", args{ts1, config.Collection_HOURLY}, time.Minute * 60, true}, + {"hourly", args{ts2, config.Collection_HOURLY}, time.Minute*30 + time.Second*1, true}, + {"hourly", args{ts3, config.Collection_HOURLY}, time.Second * 1, true}, + {"daily", args{ts1, config.Collection_DAILY}, time.Hour * 24, true}, + {"daily", args{ts2, config.Collection_DAILY}, time.Hour*12 + time.Minute*30 + time.Second*1, true}, + {"daily", args{ts3, config.Collection_DAILY}, time.Second * 1, true}, + {"monthly", args{ts1, config.Collection_MONTHLY}, time.Hour * 24 * 31, true}, + {"monthly", args{ts2, config.Collection_MONTHLY}, time.Hour*(24*10+12) + time.Minute*30 + time.Second*1, true}, + {"monthly", args{ts3, config.Collection_MONTHLY}, time.Second * 1, true}, + {"yearly", args{ts1, config.Collection_YEARLY}, time.Hour * 24 * 365, true}, + {"yearly", args{ts2, config.Collection_YEARLY}, time.Hour*(24*(10+31)+12) + time.Minute*30 + time.Second*1, true}, + {"yearly", args{ts3, config.Collection_YEARLY}, time.Second * 1, true}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, got1 := timeToNextRotation(tt.args.now, tt.args.p) + if got != tt.want { + t.Errorf("timeToNextRotation() got = %v, want %v", got, tt.want) + } + if got1 != tt.wantOk { + t.Errorf("timeToNextRotation() got1 = %v, want %v", got1, tt.wantOk) + } + }) + } +} + +func Test_createFileRotationKey(t *testing.T) { + ts1 := time.Date(2021, 1, 1, 0, 0, 0, 0, time.Local) + ts2 := time.Date(2021, 11, 20, 11, 29, 59, 0, time.Local) + ts3 := time.Date(2021, 12, 31, 23, 59, 59, 0, time.Local) + type args struct { + now time.Time + p config.Collection_RotationPolicy + } + tests := []struct { + name string + args args + want string + }{ + {"none", args{ts1, config.Collection_NONE}, ""}, + {"none", args{ts2, config.Collection_NONE}, ""}, + {"none", args{ts3, config.Collection_NONE}, ""}, + {"hourly", args{ts1, config.Collection_HOURLY}, "2021010100"}, + {"hourly", args{ts2, config.Collection_HOURLY}, "2021112011"}, + {"hourly", args{ts3, config.Collection_HOURLY}, "2021123123"}, + {"daily", args{ts1, config.Collection_DAILY}, "20210101"}, + {"daily", args{ts2, config.Collection_DAILY}, "20211120"}, + {"daily", args{ts3, config.Collection_DAILY}, "20211231"}, + {"monthly", args{ts1, config.Collection_MONTHLY}, "202101"}, + {"monthly", args{ts2, config.Collection_MONTHLY}, "202111"}, + {"monthly", args{ts3, config.Collection_MONTHLY}, "202112"}, + {"yearly", args{ts1, config.Collection_YEARLY}, "2021"}, + {"yearly", args{ts2, config.Collection_YEARLY}, "2021"}, + {"yearly", args{ts3, config.Collection_YEARLY}, "2021"}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := createFileRotationKey(tt.args.now, tt.args.p); got != tt.want { + t.Errorf("createFileRotationKey() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_getFilename(t *testing.T) { + ng := &gowarc.PatternNameGenerator{ + Directory: "", + Prefix: createFilePrefix("foo", config.Collection_UNDEFINED, time.Now(), config.Collection_NONE), + Serial: 0, + } + d1, f1 := ng.NewWarcfileName() + d2, f2 := ng.NewWarcfileName() + assert.Regexp(t, regexp.MustCompile(`foo-\d{14}-0001-\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\.warc`), f1) + assert.Equal(t, "", d1) + assert.Regexp(t, regexp.MustCompile(`foo-\d{14}-0002-\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\.warc`), f2) + assert.Equal(t, "", d2) + + ng = &gowarc.PatternNameGenerator{ + Directory: "", + Prefix: createFilePrefix("foo", config.Collection_UNDEFINED, time.Now(), config.Collection_YEARLY), + Serial: 0, + } + d1, f1 = ng.NewWarcfileName() + d2, f2 = ng.NewWarcfileName() + assert.Regexp(t, regexp.MustCompile(`foo_\d{4}-\d{14}-0001-\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\.warc`), f1) + assert.Equal(t, "", d1) + assert.Regexp(t, regexp.MustCompile(`foo_\d{4}-\d{14}-0002-\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\.warc`), f2) + assert.Equal(t, "", d2) + + ng = &gowarc.PatternNameGenerator{ + Directory: "myDir", + Prefix: createFilePrefix("foo", config.Collection_DNS, time.Now(), config.Collection_MONTHLY), + Serial: 0, + } + d1, f1 = ng.NewWarcfileName() + d2, f2 = ng.NewWarcfileName() + assert.Regexp(t, regexp.MustCompile(`foo_DNS_\d{6}-\d{14}-0001-\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\.warc`), f1) + assert.Equal(t, "myDir", d1) + assert.Regexp(t, regexp.MustCompile(`foo_DNS_\d{6}-\d{14}-0002-\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\.warc`), f2) + assert.Equal(t, "myDir", d2) + + ng = &gowarc.PatternNameGenerator{ + Directory: "myDir", + Prefix: createFilePrefix("foo", config.Collection_DNS, time.Now(), config.Collection_DAILY), + Serial: 0, + } + d1, f1 = ng.NewWarcfileName() + d2, f2 = ng.NewWarcfileName() + assert.Regexp(t, regexp.MustCompile(`foo_DNS_\d{8}-\d{14}-0001-\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\.warc`), f1) + assert.Equal(t, "myDir", d1) + assert.Regexp(t, regexp.MustCompile(`foo_DNS_\d{8}-\d{14}-0002-\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\.warc`), f2) + assert.Equal(t, "myDir", d2) +} diff --git a/settings/mock.go b/settings/mock.go new file mode 100644 index 0000000..9a6ad6b --- /dev/null +++ b/settings/mock.go @@ -0,0 +1,55 @@ +/* + * Copyright 2021 National Library of Norway. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package settings + +import "github.com/nlnwa/gowarc" + +type Mock struct { + hostName string + warcDir string + warcWriterPoolSize int + workDir string + terminationGracePeriodSeconds int +} + +func NewMock(warcDir string, warcWriterPoolSize int) *Mock { + return &Mock{warcDir: warcDir, warcWriterPoolSize: warcWriterPoolSize} +} + +func (m Mock) HostName() string { + return m.hostName +} + +func (m Mock) WarcDir() string { + return m.warcDir +} + +func (m Mock) WarcWriterPoolSize() int { + return m.warcWriterPoolSize +} + +func (m Mock) WorkDir() string { + return m.workDir +} + +func (m Mock) TerminationGracePeriodSeconds() int { + return m.terminationGracePeriodSeconds +} + +func (m Mock) WarcVersion() *gowarc.WarcVersion { + return gowarc.V1_1 +} diff --git a/settings/settings.go b/settings/settings.go new file mode 100644 index 0000000..aa6b344 --- /dev/null +++ b/settings/settings.go @@ -0,0 +1,57 @@ +/* + * Copyright 2021 National Library of Norway. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package settings + +import ( + "github.com/nlnwa/gowarc" + "github.com/spf13/viper" +) + +type Settings interface { + HostName() string + WarcDir() string + WarcWriterPoolSize() int + WorkDir() string + TerminationGracePeriodSeconds() int + WarcVersion() *gowarc.WarcVersion +} + +type ViperSettings struct{} + +func (s ViperSettings) HostName() string { + return viper.GetString("host-name") +} + +func (s ViperSettings) WarcDir() string { + return viper.GetString("warc-dir") +} + +func (s ViperSettings) WarcWriterPoolSize() int { + return viper.GetInt("warc-writer-pool-size") +} + +func (s ViperSettings) WorkDir() string { + return viper.GetString("work-dir") +} + +func (s ViperSettings) TerminationGracePeriodSeconds() int { + return viper.GetInt("termination-grace-period-seconds") +} + +func (s ViperSettings) WarcVersion() *gowarc.WarcVersion { + return gowarc.V1_1 +} diff --git a/src/main/java/no/nb/nna/veidemann/contentwriter/ApiServer.java b/src/main/java/no/nb/nna/veidemann/contentwriter/ApiServer.java deleted file mode 100644 index 9a578b4..0000000 --- a/src/main/java/no/nb/nna/veidemann/contentwriter/ApiServer.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2017 National Library of Norway. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package no.nb.nna.veidemann.contentwriter; - -import io.grpc.Server; -import io.grpc.ServerBuilder; -import io.opentracing.contrib.ServerTracingInterceptor; -import io.opentracing.util.GlobalTracer; -import no.nb.nna.veidemann.contentwriter.warc.WarcCollectionRegistry; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.io.UncheckedIOException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -/** - * - */ -public class ApiServer implements AutoCloseable { - private static final Logger LOG = LoggerFactory.getLogger(ApiServer.class); - private final Server server; - private final ExecutorService threadPool; - private int shutdownTimeoutSeconds = 60; - - - /** - * Construct a new REST API server. - */ - public ApiServer(int port, int shutdownTimeoutSeconds, WarcCollectionRegistry warcCollectionRegistry) { - this(ServerBuilder.forPort(port), warcCollectionRegistry); - this.shutdownTimeoutSeconds = shutdownTimeoutSeconds; - } - - public ApiServer(ServerBuilder serverBuilder, WarcCollectionRegistry warcCollectionRegistry) { - - ServerTracingInterceptor tracingInterceptor = new ServerTracingInterceptor.Builder(GlobalTracer.get()) - .withTracedAttributes(ServerTracingInterceptor.ServerRequestAttribute.CALL_ATTRIBUTES, - ServerTracingInterceptor.ServerRequestAttribute.METHOD_TYPE) - .build(); - - serverBuilder.intercept(tracingInterceptor); - - threadPool = Executors.newCachedThreadPool(); - serverBuilder.executor(threadPool); - - server = serverBuilder.addService(new ContentWriterService(warcCollectionRegistry)).build(); - } - - public ApiServer start() { - try { - server.start(); - - LOG.info("Content Writer api listening on {}", server.getPort()); - - return this; - } catch (IOException ex) { - throw new UncheckedIOException(ex); - } - } - - @Override - public void close() { - long startTime = System.currentTimeMillis(); - server.shutdown(); - try { - server.awaitTermination(); - } catch (InterruptedException e) { - server.shutdownNow(); - } - threadPool.shutdown(); - long timeoutSeconds = shutdownTimeoutSeconds - ((System.currentTimeMillis() - startTime) / 1000); - try { - threadPool.awaitTermination(timeoutSeconds, TimeUnit.SECONDS); - } catch (InterruptedException e) { - threadPool.shutdownNow(); - } - } - -} diff --git a/src/main/java/no/nb/nna/veidemann/contentwriter/ContentBuffer.java b/src/main/java/no/nb/nna/veidemann/contentwriter/ContentBuffer.java deleted file mode 100644 index 743d95a..0000000 --- a/src/main/java/no/nb/nna/veidemann/contentwriter/ContentBuffer.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2017 National Library of Norway. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package no.nb.nna.veidemann.contentwriter; - -import com.google.protobuf.ByteString; -import no.nb.nna.veidemann.commons.util.Sha1Digest; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static io.netty.handler.codec.http.HttpConstants.CR; -import static io.netty.handler.codec.http.HttpConstants.LF; - -/** - * - */ -public class ContentBuffer implements AutoCloseable { - - private static final Logger LOG = LoggerFactory.getLogger(ContentBuffer.class); - - static final byte[] CRLF = {CR, LF}; - - private final static String EMPTY_DIGEST_STRING = "sha1:da39a3ee5e6b4b0d3255bfef95601890afd80709"; - - private final Sha1Digest blockDigest; - private Sha1Digest payloadDigest; - private Sha1Digest headerDigest; - - private ByteString headerBuf; - private ByteString payloadBuf; - - private final String warcId; - - public ContentBuffer() { - this.blockDigest = new Sha1Digest(); - this.warcId = Util.createIdentifier(); - } - - public void setHeader(ByteString header) { - this.headerBuf = header; - updateDigest(headerBuf, blockDigest); - - // Get the partial result after creating a digest of the headers - headerDigest = blockDigest.clone(); - } - - public void addPayload(ByteString payload) { - if (payloadBuf == null) { - payloadBuf = payload; - if (hasHeader()) { - // Add the payload separator to the digest - blockDigest.update(CRLF); - payloadDigest = new Sha1Digest(); - } - } else { - payloadBuf = payloadBuf.concat(payload); - } - updateDigest(payload, blockDigest, payloadDigest); - } - - private void updateDigest(ByteString buf, Sha1Digest... digests) { - for (Sha1Digest d : digests) { - if (d != null) { - d.update(buf); - } - } - } - - public String getBlockDigest() { - return blockDigest.getPrefixedDigestString(); - } - - public String getPayloadDigest() { - if (hasHeader()) { - if (payloadDigest == null) { - return EMPTY_DIGEST_STRING; - } else { - return payloadDigest.getPrefixedDigestString(); - } - } - return ""; - } - - public String getHeaderDigest() { - if (headerDigest == null) { - return EMPTY_DIGEST_STRING; - } - return headerDigest.getPrefixedDigestString(); - } - - public long getPayloadSize() { - return payloadBuf == null ? 0 : payloadBuf.size(); - } - - public long getHeaderSize() { - return headerBuf == null ? 0 : headerBuf.size(); - } - - public long getTotalSize() { - return getHeaderSize() + getPayloadSize() + (hasHeader() && hasPayload() ? 2L : 0L); - } - - public ByteString getHeader() { - return headerBuf; - } - - public ByteString getPayload() { - return payloadBuf; - } - - public void removeHeader() { - payloadBuf = null; - } - - public void removePayload() { - payloadBuf = null; - } - - public boolean hasHeader() { - return headerBuf != null; - } - - public boolean hasPayload() { - return payloadBuf != null; - } - - public String getWarcId() { - return warcId; - } - - public void close() { - // Clean up resources - headerBuf = null; - payloadBuf = null; - } -} diff --git a/src/main/java/no/nb/nna/veidemann/contentwriter/ContentWriter.java b/src/main/java/no/nb/nna/veidemann/contentwriter/ContentWriter.java deleted file mode 100644 index 35f6714..0000000 --- a/src/main/java/no/nb/nna/veidemann/contentwriter/ContentWriter.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2017 National Library of Norway. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package no.nb.nna.veidemann.contentwriter; - -import com.typesafe.config.Config; -import com.typesafe.config.ConfigBeanFactory; -import com.typesafe.config.ConfigException; -import com.typesafe.config.ConfigFactory; -import no.nb.nna.veidemann.commons.db.DbException; -import no.nb.nna.veidemann.commons.db.DbService; -import no.nb.nna.veidemann.commons.opentracing.TracerFactory; -import no.nb.nna.veidemann.contentwriter.settings.Settings; -import no.nb.nna.veidemann.contentwriter.warc.WarcCollectionRegistry; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Class for launching the service. - */ -public class ContentWriter { - - private static final Logger LOG = LoggerFactory.getLogger(ContentWriter.class); - - private static final Settings SETTINGS; - - static { - Config config = ConfigFactory.load(); - config.checkValid(ConfigFactory.defaultReference()); - SETTINGS = ConfigBeanFactory.create(config, Settings.class); - - TracerFactory.init("ContentWriter"); - } - - /** - * Create a new ContentWriter service. - */ - public ContentWriter() { - } - - /** - * Start the service. - *

- * - * @return this instance - */ - public ContentWriter start() { - try (DbService db = DbService.configure(SETTINGS); - WarcCollectionRegistry warcCollectionRegistry = new WarcCollectionRegistry(); - ApiServer apiServer = new ApiServer(SETTINGS.getApiPort(), SETTINGS.getTerminationGracePeriodSeconds(), warcCollectionRegistry)) { - - registerShutdownHook(); - - apiServer.start(); - - LOG.info("Veidemann Content Writer (v. {}) started", - ContentWriter.class.getPackage().getImplementationVersion()); - - try { - Thread.currentThread().join(); - } catch (InterruptedException ex) { - // Interrupted, shut down - } - } catch (ConfigException | DbException ex) { - LOG.error("Configuration error: {}", ex.getLocalizedMessage()); - System.exit(1); - } - - return this; - } - - private void registerShutdownHook() { - Thread mainThread = Thread.currentThread(); - - Runtime.getRuntime().addShutdownHook(new Thread(() -> { - // Use stderr here since the logger may have been reset by its JVM shutdown hook. - System.err.println("*** shutting down since JVM is shutting down"); - mainThread.interrupt(); - try { - mainThread.join(); - } catch (InterruptedException e) { - // - } - })); - } - - /** - * Get the settings object. - *

- * - * @return the settings - */ - public static Settings getSettings() { - return SETTINGS; - } - -} diff --git a/src/main/java/no/nb/nna/veidemann/contentwriter/ContentWriterService.java b/src/main/java/no/nb/nna/veidemann/contentwriter/ContentWriterService.java deleted file mode 100644 index 294c7fa..0000000 --- a/src/main/java/no/nb/nna/veidemann/contentwriter/ContentWriterService.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright 2017 National Library of Norway. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package no.nb.nna.veidemann.contentwriter; - -import io.grpc.Status; -import io.grpc.StatusException; -import io.grpc.stub.StreamObserver; -import no.nb.nna.veidemann.api.contentwriter.v1.ContentWriterGrpc; -import no.nb.nna.veidemann.api.contentwriter.v1.WriteReply; -import no.nb.nna.veidemann.api.contentwriter.v1.WriteRequest; -import no.nb.nna.veidemann.api.contentwriter.v1.WriteResponseMeta; -import no.nb.nna.veidemann.contentwriter.WriteSessionContext.RecordData; -import no.nb.nna.veidemann.contentwriter.warc.SingleWarcWriter; -import no.nb.nna.veidemann.contentwriter.warc.WarcCollection; -import no.nb.nna.veidemann.contentwriter.warc.WarcCollection.Instance; -import no.nb.nna.veidemann.contentwriter.warc.WarcCollectionRegistry; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.net.URI; - -/** - * - */ -public class ContentWriterService extends ContentWriterGrpc.ContentWriterImplBase { - - private static final Logger LOG = LoggerFactory.getLogger(ContentWriterService.class); - - private final WarcCollectionRegistry warcCollectionRegistry; - - public ContentWriterService(WarcCollectionRegistry warcCollectionRegistry) { - this.warcCollectionRegistry = warcCollectionRegistry; - } - - @Override - public StreamObserver write(StreamObserver responseObserver) { - return new StreamObserver<>() { - private final WriteSessionContext context = new WriteSessionContext(); - - @Override - public void onNext(WriteRequest value) { - try { - context.initMDC(); - - ContentBuffer contentBuffer; - switch (value.getValueCase()) { - case META: - try { - context.setWriteRequestMeta(value.getMeta()); - } catch (StatusException e) { - responseObserver.onError(e); - } - break; - case PROTOCOL_HEADER: - contentBuffer = context.getRecordData(value.getProtocolHeader().getRecordNum()).getContentBuffer(); - if (contentBuffer.hasHeader()) { - LOG.error("Header received twice"); - Status status = Status.INVALID_ARGUMENT.withDescription("Header received twice"); - responseObserver.onError(status.asException()); - break; - } - contentBuffer.setHeader(value.getProtocolHeader().getData()); - break; - case PAYLOAD: - contentBuffer = context.getRecordData(value.getPayload().getRecordNum()).getContentBuffer(); - contentBuffer.addPayload(value.getPayload().getData()); - break; - case CANCEL: - context.cancelSession(value.getCancel()); - break; - default: - break; - } - } catch (Exception ex) { - Status status = Status.UNKNOWN.withDescription(ex.toString()); - LOG.error(ex.getMessage(), ex); - responseObserver.onError(status.asException()); - } - } - - @Override - public void onError(Throwable t) { - context.initMDC(); - LOG.error("Error caught: {}", t.getMessage(), t); - context.cancelSession(t.getMessage()); - } - - @Override - public void onCompleted() { - context.initMDC(); - if (context.isCanceled()) { - responseObserver.onNext(WriteReply.getDefaultInstance()); - responseObserver.onCompleted(); - return; - } - - if (!context.hasWriteRequestMeta()) { - LOG.error("Missing metadata object"); - Status status = Status.INVALID_ARGUMENT.withDescription("Missing metadata object"); - responseObserver.onError(status.asException()); - return; - } - - WriteReply.Builder reply = WriteReply.newBuilder(); - try { - context.validateSession(); - } catch (StatusException e) { - responseObserver.onError(e); - return; - } catch (Exception ex) { - Status status = Status.UNKNOWN.withDescription(ex.toString()); - LOG.error(ex.getMessage(), ex); - responseObserver.onError(status.asException()); - return; - } - - WarcCollection collection = warcCollectionRegistry.getWarcCollection(context.getCollectionConfig()); - try (Instance warcWriters = collection.getWarcWriters()) { - for (Integer recordNum : context.getRecordNums()) { - try (RecordData recordData = context.getRecordData(recordNum)) { - context.detectRevisit(recordNum, collection); - - URI ref = warcWriters.getWarcWriter(recordData.getSubCollectionType()).writeRecord(recordData); - - WriteResponseMeta.RecordMeta.Builder responseMeta = WriteResponseMeta.RecordMeta.newBuilder() - .setRecordNum(recordNum) - .setType(recordData.getRecordType()) - .setWarcId(recordData.getWarcId()) - .setStorageRef(ref.toString()) - .setBlockDigest(recordData.getContentBuffer().getBlockDigest()) - .setPayloadDigest(recordData.getContentBuffer().getPayloadDigest()) - .setCollectionFinalName(collection.getCollectionName(recordData.getSubCollectionType())); - if (recordData.getRevisitRef() != null) { - responseMeta.setRevisitReferenceId(recordData.getRevisitRef().getWarcId()); - } - - reply.getMetaBuilder().putRecordMeta(responseMeta.getRecordNum(), responseMeta.build()); - } catch (IOException ex) { - Status status = Status.UNKNOWN.withDescription(ex.toString()); - LOG.error("Failed write: {}", ex.getMessage(), ex); - responseObserver.onError(status.asException()); - } catch (SingleWarcWriter.SizeMismatchException ex) { - Status status = Status.OUT_OF_RANGE.withDescription(ex.getMessage()); - LOG.error(status.getDescription()); - throw status.asException(); - } catch (Exception ex) { - LOG.error("Failed write: {}", ex.getMessage(), ex); - responseObserver.onError(Status.fromThrowable(ex).asException()); - } - } - responseObserver.onNext(reply.build()); - responseObserver.onCompleted(); - } catch (Exception ex) { - Status status = Status.UNKNOWN.withDescription(ex.toString()); - LOG.error(ex.getMessage(), ex); - responseObserver.onError(status.asException()); - } - } - - }; - } -} diff --git a/src/main/java/no/nb/nna/veidemann/contentwriter/Main.java b/src/main/java/no/nb/nna/veidemann/contentwriter/Main.java deleted file mode 100644 index c7b3d4b..0000000 --- a/src/main/java/no/nb/nna/veidemann/contentwriter/Main.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2017 National Library of Norway. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package no.nb.nna.veidemann.contentwriter; - -/** - * Main class for launching the service. - */ -public final class Main { - - /** - * Private constructor to avoid instantiation. - */ - private Main() { - } - - /** - * Start the server. - *

- * @param args the command line arguments - */ - public static void main(String[] args) { - // This class intentionally doesn't do anything except for instanciating a ResourceResolverServer. - // This is necessary to be able to replace the LogManager. The system property must be set before any other - // logging is even loaded. - System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager"); - - new ContentWriter().start(); - } - -} diff --git a/src/main/java/no/nb/nna/veidemann/contentwriter/Util.java b/src/main/java/no/nb/nna/veidemann/contentwriter/Util.java deleted file mode 100644 index ec59d1a..0000000 --- a/src/main/java/no/nb/nna/veidemann/contentwriter/Util.java +++ /dev/null @@ -1,22 +0,0 @@ -package no.nb.nna.veidemann.contentwriter; - -import no.nb.nna.veidemann.api.contentwriter.v1.RecordType; - -import java.util.UUID; - -public class Util { - private Util() { - } - - public static String createIdentifier() { - return UUID.randomUUID().toString(); - } - - public static String formatIdentifierAsUrn(String id) { - return ""; - } - - public static String getRecordTypeString(RecordType recordType) { - return recordType.name().toLowerCase(); - } -} diff --git a/src/main/java/no/nb/nna/veidemann/contentwriter/WriteSessionContext.java b/src/main/java/no/nb/nna/veidemann/contentwriter/WriteSessionContext.java deleted file mode 100644 index a45ebf1..0000000 --- a/src/main/java/no/nb/nna/veidemann/contentwriter/WriteSessionContext.java +++ /dev/null @@ -1,252 +0,0 @@ -/* - * Copyright 2019 National Library of Norway. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package no.nb.nna.veidemann.contentwriter; - -import com.google.protobuf.Timestamp; -import io.grpc.Status; -import io.grpc.StatusException; -import no.nb.nna.veidemann.api.config.v1.Collection.SubCollectionType; -import no.nb.nna.veidemann.api.config.v1.ConfigObject; -import no.nb.nna.veidemann.api.contentwriter.v1.CrawledContent; -import no.nb.nna.veidemann.api.contentwriter.v1.RecordType; -import no.nb.nna.veidemann.api.contentwriter.v1.WriteRequestMeta; -import no.nb.nna.veidemann.commons.db.ConfigAdapter; -import no.nb.nna.veidemann.commons.db.ExecutionsAdapter; -import no.nb.nna.veidemann.commons.db.DbException; -import no.nb.nna.veidemann.commons.db.DbService; -import no.nb.nna.veidemann.contentwriter.warc.WarcCollection; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.slf4j.MDC; - -import java.util.*; -import java.util.Map.Entry; -import java.util.stream.Collectors; - -public class WriteSessionContext { - private static final Logger LOG = LoggerFactory.getLogger(WriteSessionContext.class); - private static final ConfigAdapter config = DbService.getInstance().getConfigAdapter(); - private static final ExecutionsAdapter dbAdapter = DbService.getInstance().getExecutionsAdapter(); - - // private final Map contentBuffers = new HashMap<>(); - final Map recordDataMap = new HashMap<>(); - - WriteRequestMeta.Builder writeRequestMeta; - ConfigObject collectionConfig; - private boolean canceled = false; - - public RecordData getRecordData(Integer recordNum) { - return recordDataMap.computeIfAbsent(recordNum, RecordData::new); - } - - public void initMDC() { - if (writeRequestMeta != null) { - MDC.put("eid", writeRequestMeta.getExecutionId()); - MDC.put("uri", writeRequestMeta.getTargetUri()); - } - } - - public void setWriteRequestMeta(WriteRequestMeta writeRequestMeta) throws StatusException { - this.writeRequestMeta = writeRequestMeta.toBuilder(); - initMDC(); - - try { - if (!writeRequestMeta.hasCollectionRef()) { - String msg = "No collection id in request"; - LOG.error(msg); - Status status = Status.INVALID_ARGUMENT.withDescription(msg); - throw status.asException(); - } else { - collectionConfig = config.getConfigObject(writeRequestMeta.getCollectionRef()); - if (collectionConfig == null || !collectionConfig.hasMeta() || !collectionConfig.hasCollection()) { - String msg = "Collection with id '" + writeRequestMeta.getCollectionRef() + "' is missing or insufficient: " + collectionConfig; - LOG.error(msg); - Status status = Status.UNKNOWN.withDescription(msg); - throw status.asException(); - } - } - } catch (Exception e) { - String msg = "Error getting collection config " + writeRequestMeta.getCollectionRef(); - LOG.error(msg, e); - Status status = Status.UNKNOWN.withDescription(msg); - throw status.asException(); - } - } - - public boolean hasWriteRequestMeta() { - return writeRequestMeta != null; - } - - public ConfigObject getCollectionConfig() { - return collectionConfig; - } - - public void validateSession() throws StatusException { - for (Entry recordEntry : recordDataMap.entrySet()) { - ContentBuffer contentBuffer = recordEntry.getValue().getContentBuffer(); - WriteRequestMeta.RecordMeta recordMeta = writeRequestMeta.getRecordMetaOrDefault(recordEntry.getKey(), null); - if (recordMeta == null) { - throw Status.INVALID_ARGUMENT.withDescription("Missing metadata for record num: " + recordEntry.getKey()).asException(); - } - - if (contentBuffer.getTotalSize() == 0L) { - LOG.error("Nothing to store"); - throw Status.INVALID_ARGUMENT.withDescription("Nothing to store").asException(); - } - - if (contentBuffer.getTotalSize() != recordMeta.getSize()) { - LOG.error("Size mismatch. Expected {}, but was {}", - recordMeta.getSize(), contentBuffer.getTotalSize()); - throw Status.INVALID_ARGUMENT.withDescription("Size mismatch").asException(); - } - - if (!contentBuffer.getBlockDigest().equals(recordMeta.getBlockDigest())) { - LOG.error("Block digest mismatch. Expected {}, but was {}", - recordMeta.getBlockDigest(), contentBuffer.getBlockDigest()); - throw Status.INVALID_ARGUMENT.withDescription("Block digest mismatch").asException(); - } - - if (writeRequestMeta.getIpAddress().isEmpty()) { - LOG.error("Missing IP-address"); - throw Status.INVALID_ARGUMENT.withDescription("Missing IP-address").asException(); - } - } - } - - public Set getRecordNums() { - return writeRequestMeta.getRecordMetaMap().keySet(); - } - - public void detectRevisit(final Integer recordNum, final WarcCollection collection) { - RecordData rd = getRecordData(recordNum); - if (rd.getRecordType() == RecordType.RESPONSE || rd.getRecordType() == RecordType.RESOURCE) { - Optional isDuplicate = Optional.empty(); - try { - String digest = rd.getContentBuffer().getPayloadDigest(); - if (digest == null || digest.isEmpty()) { - digest = rd.getContentBuffer().getBlockDigest(); - } - CrawledContent cr = CrawledContent.newBuilder() - .setDigest(digest + ":" + collection.getCollectionName(rd.getSubCollectionType())) - .setWarcId(rd.getWarcId()) - .setTargetUri(writeRequestMeta.getTargetUri()) - .setDate(writeRequestMeta.getFetchTimeStamp()) - .build(); - isDuplicate = dbAdapter - .hasCrawledContent(cr); - } catch (DbException e) { - LOG.error("Failed checking for revisit, treating as new object", e); - } - - if (isDuplicate.isPresent()) { - CrawledContent cc = isDuplicate.get(); - LOG.debug("Detected {} as a revisit of {}", - MDC.get("uri"), cc.getWarcId()); - - WriteRequestMeta.RecordMeta newRecordMeta = rd.getRecordMeta().toBuilder() - .setType(RecordType.REVISIT) - .setBlockDigest(rd.getContentBuffer().getHeaderDigest()) - .setPayloadDigest(rd.getContentBuffer().getPayloadDigest()) - .setSize(rd.getContentBuffer().getHeaderSize()) - .build(); - writeRequestMeta.putRecordMeta(recordNum, newRecordMeta); - - rd.getContentBuffer().removePayload(); - - rd.revisitRef = cc; - } - } - - if (rd.revisitRef == null) { - WriteRequestMeta.RecordMeta newRecordMeta = rd.getRecordMeta().toBuilder() - .setBlockDigest(rd.getContentBuffer().getBlockDigest()) - .setPayloadDigest(rd.getContentBuffer().getPayloadDigest()) - .build(); - writeRequestMeta.putRecordMeta(recordNum, newRecordMeta); - } - } - - public boolean isCanceled() { - return canceled; - } - - public void cancelSession(String cancelReason) { - canceled = true; - LOG.debug("Request cancelled before WARC record written. Reason {}", cancelReason); - for (RecordData cb : recordDataMap.values()) { - cb.close(); - } - } - - public class RecordData implements AutoCloseable { - private final Integer recordNum; - private final ContentBuffer contentBuffer = new ContentBuffer(); - private CrawledContent revisitRef; - - public RecordData(Integer recordNum) { - this.recordNum = recordNum; - } - - public ContentBuffer getContentBuffer() { - return contentBuffer; - } - - public WriteRequestMeta.RecordMeta getRecordMeta() { - return writeRequestMeta.getRecordMetaOrThrow(recordNum); - } - - public CrawledContent getRevisitRef() { - return revisitRef; - } - - public String getWarcId() { - return contentBuffer.getWarcId(); - } - - public RecordType getRecordType() { - return getRecordMeta().getType(); - } - - public SubCollectionType getSubCollectionType() { - return getRecordMeta().getSubCollection(); - } - - public String getTargetUri() { - return writeRequestMeta.getTargetUri(); - } - - public Timestamp getFetchTimeStamp() { - return writeRequestMeta.getFetchTimeStamp(); - } - - public String getIpAddress() { - return writeRequestMeta.getIpAddress(); - } - - public List getWarcConcurrentToIds() { - List ids = recordDataMap.values().stream() - .map(cb -> cb.getContentBuffer().getWarcId()) - .collect(Collectors.toList()); - ids.addAll(getRecordMeta().getWarcConcurrentToList()); - return ids; - } - - public void close() { - contentBuffer.close(); - } - } -} diff --git a/src/main/java/no/nb/nna/veidemann/contentwriter/settings/Settings.java b/src/main/java/no/nb/nna/veidemann/contentwriter/settings/Settings.java deleted file mode 100644 index 0a9b6ff..0000000 --- a/src/main/java/no/nb/nna/veidemann/contentwriter/settings/Settings.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2017 National Library of Norway. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package no.nb.nna.veidemann.contentwriter.settings; - -import no.nb.nna.veidemann.commons.settings.CommonSettings; - -/** - * Configuration settings for Veidemann Content Writer. - */ -public class Settings extends CommonSettings { - - private int apiPort; - - private String hostName; - - private String warcDir; - - private int warcWriterPoolSize; - - private String workDir; - - private int terminationGracePeriodSeconds; - - public int getApiPort() { - return apiPort; - } - - public void setApiPort(int apiPort) { - this.apiPort = apiPort; - } - - public String getHostName() { - return hostName; - } - - public void setHostName(String hostName) { - this.hostName = hostName; - } - - public String getWarcDir() { - return warcDir; - } - - public void setWarcDir(String warcDir) { - this.warcDir = warcDir; - } - - public int getWarcWriterPoolSize() { - return warcWriterPoolSize; - } - - public void setWarcWriterPoolSize(int warcWriterPoolSize) { - this.warcWriterPoolSize = warcWriterPoolSize; - } - - public String getWorkDir() { - return workDir; - } - - public void setWorkDir(String workDir) { - this.workDir = workDir; - } - - public int getTerminationGracePeriodSeconds() { - return terminationGracePeriodSeconds; - } - - public void setTerminationGracePeriodSeconds(int terminationGracePeriodSeconds) { - this.terminationGracePeriodSeconds = terminationGracePeriodSeconds; - } -} diff --git a/src/main/java/no/nb/nna/veidemann/contentwriter/warc/SingleWarcWriter.java b/src/main/java/no/nb/nna/veidemann/contentwriter/warc/SingleWarcWriter.java deleted file mode 100644 index c1f86c7..0000000 --- a/src/main/java/no/nb/nna/veidemann/contentwriter/warc/SingleWarcWriter.java +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Copyright 2017 National Library of Norway. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package no.nb.nna.veidemann.contentwriter.warc; - -import no.nb.nna.veidemann.api.config.v1.Collection.SubCollection; -import no.nb.nna.veidemann.api.config.v1.ConfigObject; -import no.nb.nna.veidemann.api.contentwriter.v1.WriteRequestMeta.RecordMeta; -import no.nb.nna.veidemann.commons.util.Sha1Digest; -import no.nb.nna.veidemann.contentwriter.ContentBuffer; -import no.nb.nna.veidemann.contentwriter.Util; -import no.nb.nna.veidemann.contentwriter.WriteSessionContext.RecordData; -import no.nb.nna.veidemann.db.ProtoUtils; -import org.jwat.warc.WarcFileWriter; -import org.jwat.warc.WarcFileWriterConfig; -import org.jwat.warc.WarcRecord; -import org.jwat.warc.WarcWriter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.yaml.snakeyaml.Yaml; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.UncheckedIOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.*; - -import static io.netty.handler.codec.http.HttpConstants.CR; -import static io.netty.handler.codec.http.HttpConstants.LF; -import static org.jwat.warc.WarcConstants.*; - -/** - * - */ -public class SingleWarcWriter implements AutoCloseable { - - private static final Logger LOG = LoggerFactory.getLogger(SingleWarcWriter.class); - - static final byte[] CRLF = {CR, LF}; - static final String WARC_FILE_SCHEME = "warcfile"; - - final WarcFileWriter warcFileWriter; - final VeidemannWarcFileNaming warcFileNaming; - final ConfigObject config; - final SubCollection subCollection; - - public SingleWarcWriter(ConfigObject config, SubCollection subCollection, String filePrefix, File targetDir, String hostName) { - this.config = config; - this.subCollection = subCollection; - warcFileNaming = new VeidemannWarcFileNaming(filePrefix, hostName); - WarcFileWriterConfig writerConfig = new WarcFileWriterConfig(targetDir, config.getCollection().getCompress(), - config.getCollection().getFileSize(), false); - warcFileWriter = WarcFileWriter.getWarcWriterInstance(warcFileNaming, writerConfig); - } - - public URI writeRecord(final RecordData recordData) throws IOException, SizeMismatchException { - ContentBuffer contentBuffer = recordData.getContentBuffer(); - long size = 0L; - boolean newFile; - - try { - newFile = warcFileWriter.nextWriter(); - } catch (Exception e) { - throw new RuntimeException(e); - } - - File currentFile = warcFileWriter.getFile(); - String finalFileName = currentFile.getName().substring(0, currentFile.getName().length() - 5); - - if (newFile) { - writeFileDescriptionRecords(finalFileName); - } - - writeWarcHeader(recordData); - - if (contentBuffer.hasHeader()) { - size += addPayload(contentBuffer.getHeader().newInput()); - } - - if (contentBuffer.hasPayload()) { - // If both headers and payload are present, add separator - if (contentBuffer.hasHeader()) { - size += addPayload(CRLF); - } - long payloadSize = addPayload(contentBuffer.getPayload().newInput()); - - LOG.debug("Payload of size {}b written for {}", payloadSize, recordData.getTargetUri()); - size += payloadSize; - } - - try { - closeRecord(); - } catch (IllegalStateException e) { - throw new SizeMismatchException(e.getMessage()); - } catch (IOException ex) { - if (recordData.getRecordMeta().getSize() != size) { - SizeMismatchException sizeMismatchException = new SizeMismatchException(recordData.getRecordMeta().getSize(), size); - sizeMismatchException.initCause(ex); - throw sizeMismatchException; - } else { - throw ex; - } - } - try { - return new URI(WARC_FILE_SCHEME + ":" + finalFileName + ":" + currentFile.length()); - } catch (URISyntaxException e) { - throw new RuntimeException(e); - } - } - - @Override - public void close() throws Exception { - warcFileWriter.close(); - } - - void writeFileDescriptionRecords(String finalFileName) throws IOException { - WarcWriter writer = warcFileWriter.getWriter(); - WarcRecord record = WarcRecord.createRecord(writer); - record.header.major = 1; - record.header.minor = 0; - - record.header.addHeader(FN_WARC_TYPE, RT_WARCINFO); - GregorianCalendar cal = new GregorianCalendar(); - cal.setTimeZone(TimeZone.getTimeZone("UTC")); - cal.setTimeInMillis(System.currentTimeMillis()); - record.header.addHeader(FN_WARC_DATE, cal.getTime(), null); - record.header.addHeader(FN_WARC_FILENAME, finalFileName); - record.header.addHeader(FN_WARC_RECORD_ID, "<" + warcFileWriter.warcinfoRecordId + ">"); - record.header.addHeader(FN_CONTENT_TYPE, "application/warc-fields"); - - Map payload = new HashMap<>(); - payload.put("isPartOf", warcFileNaming.getFilePrefix()); - payload.put("collection", config.getMeta().getName()); - if (subCollection != null) { - payload.put("subCollection", subCollection.getName()); - } - payload.put("host", warcFileNaming.getHostName()); - payload.put("format", "WARC File Format 1.0"); - payload.put("description", config.getMeta().getDescription()); - - Yaml yaml = new Yaml(); - - byte[] payloadBytes = yaml.dumpAsMap(payload).getBytes(); - Sha1Digest payloadDigest = new Sha1Digest(); - payloadDigest.update(payloadBytes); - - record.header.addHeader(FN_CONTENT_LENGTH, payloadBytes.length, null); - record.header.addHeader(FN_WARC_BLOCK_DIGEST, payloadDigest.getPrefixedDigestString()); - writer.writeHeader(record); - - writer.writePayload(payloadBytes); - writer.closeRecord(); - } - - void writeWarcHeader(final RecordData recordData) throws IOException { - WarcWriter writer = warcFileWriter.getWriter(); - WarcRecord record = WarcRecord.createRecord(writer); - record.header.major = 1; - record.header.minor = 0; - - record.header.addHeader(FN_WARC_TYPE, Util.getRecordTypeString(recordData.getRecordType())); - record.header.addHeader(FN_WARC_TARGET_URI, recordData.getTargetUri()); - Date warcDate = Date.from(ProtoUtils.tsToOdt(recordData.getFetchTimeStamp()).toInstant()); - record.header.addHeader(FN_WARC_DATE, warcDate, null); - record.header.addHeader(FN_WARC_RECORD_ID, Util.formatIdentifierAsUrn(recordData.getWarcId())); - - if (recordData.getRevisitRef() != null) { - record.header.addHeader(FN_WARC_PROFILE, PROFILE_IDENTICAL_PAYLOAD_DIGEST); - record.header.addHeader(FN_WARC_REFERS_TO, Util.formatIdentifierAsUrn(recordData.getRevisitRef().getWarcId())); - if (!recordData.getRevisitRef().getTargetUri().isEmpty() && recordData.getRevisitRef().hasDate()) { - record.header.addHeader(FN_WARC_REFERS_TO_TARGET_URI, - recordData.getRevisitRef().getTargetUri()); - record.header.addHeader(FN_WARC_REFERS_TO_DATE, - Date.from(ProtoUtils.tsToOdt(recordData.getRevisitRef().getDate()).toInstant()), null); - } - } - - record.header.addHeader(FN_WARC_IP_ADDRESS, recordData.getIpAddress()); - record.header.addHeader(FN_WARC_WARCINFO_ID, "<" + warcFileWriter.warcinfoRecordId + ">"); - - RecordMeta recordMeta = recordData.getRecordMeta(); - record.header.addHeader(FN_WARC_BLOCK_DIGEST, recordMeta.getBlockDigest()); - if (!recordMeta.getPayloadDigest().isEmpty()) { - record.header.addHeader(FN_WARC_PAYLOAD_DIGEST, recordMeta.getPayloadDigest()); - } - - record.header.addHeader(FN_CONTENT_LENGTH, recordMeta.getSize(), null); - - if (!recordMeta.getRecordContentType().isEmpty()) { - record.header.addHeader(FN_CONTENT_TYPE, recordMeta.getRecordContentType()); - } - - for (String otherId : recordData.getWarcConcurrentToIds()) { - if (!otherId.equals(recordData.getWarcId())) { - record.header.addHeader(FN_WARC_CONCURRENT_TO, Util.formatIdentifierAsUrn(otherId)); - } - } - - writer.writeHeader(record); - } - - long addPayload(byte[] data) throws UncheckedIOException { - try { - return warcFileWriter.getWriter().writePayload(data); - } catch (IOException ex) { - throw new UncheckedIOException(ex); - } - } - - long addPayload(InputStream data) throws UncheckedIOException { - try { - return warcFileWriter.getWriter().streamPayload(data); - } catch (IOException ex) { - throw new UncheckedIOException(ex); - } - } - - void closeRecord() throws IOException { - warcFileWriter.getWriter().closeRecord(); - } - - public static class SizeMismatchException extends Exception { - SizeMismatchException(String message) { - super(message); - } - - SizeMismatchException(long expectedSize, long actualSize) { - super("Size doesn't match metadata. Expected " + expectedSize + ", but was " + actualSize); - } - } -} diff --git a/src/main/java/no/nb/nna/veidemann/contentwriter/warc/VeidemannWarcFileNaming.java b/src/main/java/no/nb/nna/veidemann/contentwriter/warc/VeidemannWarcFileNaming.java deleted file mode 100644 index 20b268f..0000000 --- a/src/main/java/no/nb/nna/veidemann/contentwriter/warc/VeidemannWarcFileNaming.java +++ /dev/null @@ -1,72 +0,0 @@ -package no.nb.nna.veidemann.contentwriter.warc; - -import org.jwat.warc.WarcFileNaming; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Objects; -import java.util.concurrent.atomic.AtomicInteger; - -public class VeidemannWarcFileNaming implements WarcFileNaming { - - /** - * DateFormat to the following format 'yyyyMMddHHmmss'. - */ - protected final DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); - - /** - * Prefix component. - */ - protected final String filePrefix; - - /** - * Host name component. - */ - protected final String hostName; - - /** - * Extension component (including leading "."). - */ - protected final String extension; - - protected final static AtomicInteger sequenceNumber = new AtomicInteger(0); - - /** - * Construct file naming instance. - * - * @param filePrefix prefix or null, will default to "Veidemann" - * @param hostName host name or null, if you want to use default local host name - */ - public VeidemannWarcFileNaming(String filePrefix, String hostName) { - this.filePrefix = Objects.requireNonNullElse(filePrefix, "Veidemann"); - this.hostName = hostName; - extension = ".warc"; - } - - @Override - public boolean supportMultipleFiles() { - return true; - } - - @Override - public String getFilename(int sequenceNr, boolean bCompressed) { - String dateStr = dateFormat.format(new Date()); - - String filename = filePrefix + "-" + dateStr - + "-" + hostName.replace("-", "_") - + "-" + String.format("%05d", sequenceNumber.getAndIncrement()) + extension; - if (bCompressed) { - filename += ".gz"; - } - return filename; - } - - public String getFilePrefix() { - return filePrefix; - } - - public String getHostName() { - return hostName; - } -} diff --git a/src/main/java/no/nb/nna/veidemann/contentwriter/warc/WarcCollection.java b/src/main/java/no/nb/nna/veidemann/contentwriter/warc/WarcCollection.java deleted file mode 100644 index 9f7e4b5..0000000 --- a/src/main/java/no/nb/nna/veidemann/contentwriter/warc/WarcCollection.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright 2019 National Library of Norway. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package no.nb.nna.veidemann.contentwriter.warc; - -import no.nb.nna.veidemann.api.config.v1.Collection.RotationPolicy; -import no.nb.nna.veidemann.api.config.v1.Collection.SubCollection; -import no.nb.nna.veidemann.api.config.v1.Collection.SubCollectionType; -import no.nb.nna.veidemann.api.config.v1.ConfigObject; -import no.nb.nna.veidemann.commons.util.Pool.Lease; -import no.nb.nna.veidemann.contentwriter.ContentWriter; -import no.nb.nna.veidemann.contentwriter.settings.Settings; -import no.nb.nna.veidemann.db.ProtoUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.io.IOException; -import java.nio.file.DirectoryStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.time.OffsetDateTime; -import java.time.format.DateTimeFormatter; -import java.util.EnumMap; -import java.util.Map; - -public class WarcCollection implements AutoCloseable { - private static final Logger LOG = LoggerFactory.getLogger(WarcCollection.class); - - static final DateTimeFormatter HOUR_FORMAT = DateTimeFormatter.ofPattern("YYYYMMddHH"); - static final DateTimeFormatter DAY_FORMAT = DateTimeFormatter.ofPattern("YYYYMMdd"); - static final DateTimeFormatter MONTH_FORMAT = DateTimeFormatter.ofPattern("YYYYMM"); - static final DateTimeFormatter YEAR_FORMAT = DateTimeFormatter.ofPattern("YYYY"); - - final ConfigObject config; - final WarcWriterPool warcWriterPool; - final Map subCollections; - final String filePrefix; - final String currentFileRotationKey; - final Settings settings = ContentWriter.getSettings(); - - public WarcCollection(ConfigObject config) { - - this.config = config; - filePrefix = createFilePrefix(ProtoUtils.getNowOdt()); - currentFileRotationKey = createFileRotationKey(config.getCollection().getFileRotationPolicy(), ProtoUtils.getNowOdt()); - - this.warcWriterPool = new WarcWriterPool( - config, - null, - filePrefix, - new File(settings.getWarcDir()), - config.getCollection().getFileSize(), - config.getCollection().getCompress(), - settings.getWarcWriterPoolSize(), - settings.getHostName()); - - subCollections = new EnumMap<>(SubCollectionType.class); - for (SubCollection sub : config.getCollection().getSubCollectionsList()) { - subCollections.put(sub.getType(), new WarcWriterPool( - config, - sub, - filePrefix + "_" + sub.getName(), - new File(settings.getWarcDir()), - config.getCollection().getFileSize(), - config.getCollection().getCompress(), - settings.getWarcWriterPoolSize(), - settings.getHostName())); - } - } - - public Instance getWarcWriters() { - return new Instance(); - } - - public String getCollectionName(SubCollectionType subType) { - return subCollections.getOrDefault(subType, warcWriterPool).getName(); - } - - public boolean shouldFlushFiles(ConfigObject config, OffsetDateTime timestamp) { - if (!createFileRotationKey(config.getCollection().getFileRotationPolicy(), timestamp) - .equals(currentFileRotationKey)) { - return true; - } - - if (!createFilePrefix(timestamp).equals(filePrefix)) { - return true; - } - - if (config == this.config) { - return false; - } else { - ConfigObject c = this.config; - ConfigObject other = config; - boolean isEqual = true; - isEqual = isEqual && c.hasMeta() == other.hasMeta(); - isEqual = isEqual && c.getMeta().getName().equals(other.getMeta().getName()); - isEqual = isEqual && c.getMeta().getDescription().equals(other.getMeta().getDescription()); - - isEqual = isEqual && c.getCollection().getCollectionDedupPolicy() == other.getCollection().getCollectionDedupPolicy(); - isEqual = isEqual && c.getCollection().getFileRotationPolicy() == other.getCollection().getFileRotationPolicy(); - isEqual = isEqual && c.getCollection().getCompress() == other.getCollection().getCompress(); - isEqual = isEqual && c.getCollection().getFileSize() == other.getCollection().getFileSize(); - isEqual = isEqual && c.getCollection().getSubCollectionsList().equals(other.getCollection().getSubCollectionsList()); - - return !isEqual; - } - } - - String createFilePrefix(OffsetDateTime timestamp) { - String name = config.getMeta().getName(); - String dedupRotationKey = createFileRotationKey(config.getCollection().getCollectionDedupPolicy(), timestamp); - if (dedupRotationKey.isEmpty()) { - return name; - } else { - return name + "_" + dedupRotationKey; - } - } - - String createFileRotationKey(RotationPolicy fileRotationPolicy, OffsetDateTime timestamp) { - switch (fileRotationPolicy) { - case HOURLY: - return timestamp.format(HOUR_FORMAT); - case DAILY: - return timestamp.format(DAY_FORMAT); - case MONTHLY: - return timestamp.format(MONTH_FORMAT); - case YEARLY: - return timestamp.format(YEAR_FORMAT); - default: - return ""; - } - } - - @Override - public void close() { - try { - warcWriterPool.close(); - } catch (InterruptedException e) { - LOG.error("Failed closing collection " + warcWriterPool.getName(), e); - } - for (WarcWriterPool sub : subCollections.values()) { - try { - sub.close(); - } catch (InterruptedException e) { - LOG.error("Failed closing collection " + sub.getName(), e); - } - } - } - - public void deleteFiles() throws IOException { - Path dir = Paths.get(settings.getWarcDir()); - try (DirectoryStream stream = Files.newDirectoryStream(dir, warcWriterPool.getName() + "*.warc*")) { - for (Path path : stream) { - LOG.info("Deleting " + path); - Files.delete(path); - } - } - } - - public class Instance implements AutoCloseable { - Lease warcWriterLease; - final Map> subCollectionWarcWriterLeases = - new EnumMap<>(SubCollectionType.class); - - public SingleWarcWriter getWarcWriter(SubCollectionType subType) { - if (subCollections.containsKey(subType)) { - Lease sub = subCollectionWarcWriterLeases.computeIfAbsent(subType, k -> { - try { - return subCollections.get(k).lease(); - } catch (InterruptedException e) { - LOG.error("Can't get WarcWriter", e); - throw new RuntimeException(e); - } - }); - return sub.getObject(); - } else { - if (warcWriterLease == null) { - try { - warcWriterLease = warcWriterPool.lease(); - } catch (InterruptedException e) { - LOG.error("Can't get WarcWriter", e); - throw new RuntimeException(e); - } - } - return warcWriterLease.getObject(); - } - } - - @Override - public void close() { - if (warcWriterLease != null) { - warcWriterLease.close(); - } - for (Lease sub : subCollectionWarcWriterLeases.values()) { - sub.close(); - } - } - } -} diff --git a/src/main/java/no/nb/nna/veidemann/contentwriter/warc/WarcCollectionRegistry.java b/src/main/java/no/nb/nna/veidemann/contentwriter/warc/WarcCollectionRegistry.java deleted file mode 100644 index 6b1a2a7..0000000 --- a/src/main/java/no/nb/nna/veidemann/contentwriter/warc/WarcCollectionRegistry.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2019 National Library of Norway. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package no.nb.nna.veidemann.contentwriter.warc; - -import no.nb.nna.veidemann.api.config.v1.ConfigObject; -import no.nb.nna.veidemann.db.ProtoUtils; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; - -public class WarcCollectionRegistry implements AutoCloseable { - private final Map collections = new HashMap<>(); - - public WarcCollection getWarcCollection(ConfigObject config) { - WarcCollection c = collections.get(config.getId()); - if (c == null) { - c = new WarcCollection(config); - collections.put(config.getId(), c); - } else if (c.shouldFlushFiles(config, ProtoUtils.getNowOdt())) { - c.close(); - c = new WarcCollection(config); - collections.put(config.getId(), c); - } - return c; - } - - @Override - public void close() { - for (Iterator> it = collections.entrySet().iterator(); it.hasNext(); ) { - it.next().getValue().close(); - it.remove(); - } - } - - public void deleteFiles(ConfigObject config) throws IOException { - close(); - WarcCollection c = new WarcCollection(config); - c.deleteFiles(); - c.close(); - } -} diff --git a/src/main/java/no/nb/nna/veidemann/contentwriter/warc/WarcWriterPool.java b/src/main/java/no/nb/nna/veidemann/contentwriter/warc/WarcWriterPool.java deleted file mode 100644 index 21d382e..0000000 --- a/src/main/java/no/nb/nna/veidemann/contentwriter/warc/WarcWriterPool.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2019 National Library of Norway. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package no.nb.nna.veidemann.contentwriter.warc; - -import no.nb.nna.veidemann.api.config.v1.Collection.SubCollection; -import no.nb.nna.veidemann.api.config.v1.ConfigObject; -import no.nb.nna.veidemann.commons.util.Pool; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; - -/** - * - */ -public class WarcWriterPool extends Pool { - private static final Logger LOG = LoggerFactory.getLogger(WarcWriterPool.class); - - private final String name; - - /** - * Creates the pool. - *

- * - * @param poolSize maximum number of writers residing in the pool - */ - public WarcWriterPool(final ConfigObject config, SubCollection subCollection, final String name, final File targetDir, final long maxFileSize, - final boolean compress, final int poolSize, final String hostName) { - - super(poolSize, - () -> new SingleWarcWriter(config, subCollection, name, targetDir, hostName), - null, - singleWarcWriter -> { - try { - singleWarcWriter.close(); - } catch (Exception e) { - // Use stderr here since the logger may have been reset by its JVM shutdown hook. - System.err.println("Failed closing collection " + name + ": " + e.getLocalizedMessage()); - } - }); - - this.name = name; - targetDir.mkdirs(); - } - - public String getName() { - return name; - } -} diff --git a/src/main/jib/app/LICENSE.txt b/src/main/jib/app/LICENSE.txt deleted file mode 100644 index a3b8182..0000000 --- a/src/main/jib/app/LICENSE.txt +++ /dev/null @@ -1,14 +0,0 @@ - -Copyright 2019 National Library of Norway. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/src/main/jib/app/resources/application.conf b/src/main/jib/app/resources/application.conf deleted file mode 100644 index 88996cf..0000000 --- a/src/main/jib/app/resources/application.conf +++ /dev/null @@ -1,25 +0,0 @@ -logTraffic=false - -# The port the server listens to. -apiPort=8080 -apiPort=${?API_PORT} - -# Where to put WARC files -warcDir="."; -warcDir=${?WARC_DIR} - -warcWriterPoolSize=2 -warcWriterPoolSize=${?WARC_WRITER_POOL_SIZE} - -# Where to put temporary files -workDir="." -workDir=${?WORK_DIR} - -# Regular expression matching url's which are allowed to do cross origin resource requests -corsAllowedOriginPattern="" - -hostName="unknown" -hostName=${?HOST_NAME} - -terminationGracePeriodSeconds=60 -terminationGracePeriodSeconds=${?TERMINATION_GRACE_PERIOD_SECONDS} diff --git a/src/main/jib/app/resources/log4j2.xml b/src/main/jib/app/resources/log4j2.xml deleted file mode 100644 index 0526386..0000000 --- a/src/main/jib/app/resources/log4j2.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/src/test/java/no/nb/nna/veidemann/contentwriter/ContentWriterServiceTestIT.java b/src/test/java/no/nb/nna/veidemann/contentwriter/ContentWriterServiceTestIT.java deleted file mode 100644 index 0becc77..0000000 --- a/src/test/java/no/nb/nna/veidemann/contentwriter/ContentWriterServiceTestIT.java +++ /dev/null @@ -1,452 +0,0 @@ -/* - * Copyright 2019 National Library of Norway. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package no.nb.nna.veidemann.contentwriter; - -import com.google.protobuf.ByteString; -import com.google.protobuf.util.Timestamps; -import com.rethinkdb.RethinkDB; -import io.grpc.StatusException; -import no.nb.nna.veidemann.api.config.v1.Collection.SubCollectionType; -import no.nb.nna.veidemann.api.config.v1.ConfigRef; -import no.nb.nna.veidemann.api.config.v1.Kind; -import no.nb.nna.veidemann.api.contentwriter.v1.Data; -import no.nb.nna.veidemann.api.contentwriter.v1.RecordType; -import no.nb.nna.veidemann.api.contentwriter.v1.WriteRequestMeta; -import no.nb.nna.veidemann.api.contentwriter.v1.WriteRequestMeta.RecordMeta; -import no.nb.nna.veidemann.api.contentwriter.v1.WriteResponseMeta; -import no.nb.nna.veidemann.commons.client.ContentWriterClient; -import no.nb.nna.veidemann.commons.client.ContentWriterClient.ContentWriterSession; -import no.nb.nna.veidemann.commons.db.ConfigAdapter; -import no.nb.nna.veidemann.commons.db.DbConnectionException; -import no.nb.nna.veidemann.commons.db.DbException; -import no.nb.nna.veidemann.commons.db.DbService; -import no.nb.nna.veidemann.commons.settings.CommonSettings; -import no.nb.nna.veidemann.commons.util.Sha1Digest; -import org.assertj.core.api.AbstractAssert; -import org.assertj.core.api.Assertions; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.jwat.warc.WarcRecord; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.text.ParseException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.jwat.warc.WarcConstants.*; - -public class ContentWriterServiceTestIT { - static ContentWriterClient contentWriterClient; - - static ConfigAdapter db; - - static RethinkDB r = RethinkDB.r; - - @BeforeClass - public static void init() throws DbConnectionException { - String contentWriterHost = System.getProperty("contentwriter.host"); - int contentWriterPort = Integer.parseInt(System.getProperty("contentwriter.port")); - String dbHost = System.getProperty("db.host"); - int dbPort = Integer.parseInt(System.getProperty("db.port")); - System.out.println("Database address: " + dbHost + ":" + dbPort); - - contentWriterClient = new ContentWriterClient(contentWriterHost, contentWriterPort); - - if (!DbService.isConfigured()) { - CommonSettings dbSettings = new CommonSettings() - .withDbHost(dbHost) - .withDbPort(dbPort) - .withDbName("veidemann") - .withDbUser("admin") - .withDbPassword(""); - DbService.configure(dbSettings); - } - db = DbService.getInstance().getConfigAdapter(); - } - - @AfterClass - public static void shutdown() { - contentWriterClient.close(); - } - - @Test - public void write() throws StatusException, InterruptedException, DbException, ParseException { - Map responses = new HashMap<>(); - assertThatCode(() -> { - responses.put("http", writeHttpRecords()); - }).doesNotThrowAnyException(); - WriteResponseMeta httpResponseMeta = responses.get("http"); - String httpResponseWarcId = httpResponseMeta.getRecordMetaOrThrow(1).getWarcId(); - - assertThatCode(() -> { - responses.put("screenshot", writeScreenshotRecord(httpResponseWarcId)); - }).doesNotThrowAnyException(); - WriteResponseMeta screenshotResponseMeta = responses.get("screenshot"); - - writeHttpRecords(); - writeHttpRecords(); - writeDnsRecord(); - - WarcFileSet wfs = WarcInspector.getWarcFiles(); - wfs.listFiles().forEach(wf -> { - System.out.println(wf.getName()); - try (Stream stream = wf.getContent()) { - stream.forEach(r -> { - System.out.println(" - " + r.header.warcRecordIdStr + " " + r.header.versionStr + " " + r.header.warcTypeStr); - }); - } - }); - - wfs.listFiles().forEach(wf -> { - assertThat(wf.getContent()).allSatisfy(r -> { - MyProjectAssertions.assertThat(r) - .hasVersion(1, 0) - .hasValidHeaders(); - }); - }); - - wfs.listFiles().forEach(wf -> { - try (Stream stream = wf.getContent()) { - String fileName = wf.getName(); - stream.filter(r -> r.header.warcTypeStr.equals(RT_WARCINFO)).forEach(r -> { - try (Stream lines = new BufferedReader(new InputStreamReader(r.getPayloadContent())).lines()) { - assertThat(lines.filter(l -> l.startsWith("host: ")).map(l -> l.replace("host: ", ""))) - .allSatisfy(hostName -> { - assertThat(fileName.contains(hostName)).isFalse(); - assertThat(fileName).contains(hostName.replace("-", "_")); - }); - } - }); - } - }); - } - - private WriteResponseMeta writeHttpRecords() throws ParseException, StatusException, InterruptedException { - ContentWriterSession session = contentWriterClient.createSession(); - - Sha1Digest requestBlockDigest = new Sha1Digest(); - Sha1Digest responseBlockDigest = new Sha1Digest(); - Sha1Digest responsePayloadDigest = new Sha1Digest(); - - ByteString requestHeaderData = ByteString.copyFromUtf8("GET /images/logoc.jpg HTTP/1.0\n" + - "User-Agent: Mozilla/5.0 (compatible; heritrix/1.10.0)\n" + - "From: stack@example.org\n" + - "Connection: close\n" + - "Referer: http://www.archive.org/\n" + - "Host: www.archive.org\n" + - "Cookie: PHPSESSID=009d7bb11022f80605aa87e18224d824\n"); - - requestBlockDigest.update(requestHeaderData); - - ByteString responseHeaderData = ByteString.copyFromUtf8("HTTP/1.1 200 OK\n" + - "Date: Tue, 19 Sep 2016 17:18:40 GMT\n" + - "Server: Apache/2.0.54 (Ubuntu)\n" + - "Last-Modified: Mon, 16 Jun 2013 22:28:51 GMT\n" + - "ETag: \"3e45-67e-2ed02ec0\"\n" + - "Accept-Ranges: bytes\n" + - "Content-Length: 37\n" + - "Connection: close\n" + - "Content-Type: text/html\n"); - - ByteString responsePayloadData = ByteString.copyFromUtf8("

test

"); - - responseBlockDigest.update(responseHeaderData); - responseBlockDigest.update('\r', '\n'); - responsePayloadDigest.update(responsePayloadData); - responseBlockDigest.update(responsePayloadData); - - RecordMeta requestMeta = RecordMeta.newBuilder() - .setRecordNum(0) - .setSize(requestHeaderData.size()) - .setBlockDigest(requestBlockDigest.getPrefixedDigestString()) - .setPayloadDigest("sha1:da39a3ee5e6b4b0d3255bfef95601890afd80709") - .setType(RecordType.REQUEST) - .setRecordContentType("application/http; msgtype=request") - .build(); - RecordMeta responseMeta = RecordMeta.newBuilder() - .setRecordNum(1) - .setSize(responseHeaderData.size() + responsePayloadData.size() + 2) - .setBlockDigest(responseBlockDigest.getPrefixedDigestString()) - .setPayloadDigest(responsePayloadDigest.getPrefixedDigestString()) - .setType(RecordType.RESPONSE) - .setRecordContentType("application/http; msgtype=response") - .build(); - WriteRequestMeta meta = WriteRequestMeta.newBuilder() - .setCollectionRef(ConfigRef.newBuilder().setKind(Kind.collection).setId("2fa23773-d7e1-4748-8ab6-9253e470a3f5")) - .setIpAddress("127.0.0.1") - .setTargetUri("http://www.example.com/index.html") - .setFetchTimeStamp(Timestamps.parse("2016-09-19T17:20:24Z")) - .putRecordMeta(0, requestMeta) - .putRecordMeta(1, responseMeta) - .build(); - session.sendMetadata(meta); - - session.sendHeader(Data.newBuilder() - .setRecordNum(0) - .setData(requestHeaderData) - .build()); - - session.sendHeader(Data.newBuilder() - .setRecordNum(1) - .setData(responseHeaderData) - .build()); - - session.sendPayload(Data.newBuilder() - .setRecordNum(1) - .setData(responsePayloadData) - .build()); - - WriteResponseMeta res = null; - try { - res = session.finish(); - } catch (Exception e) { - e.printStackTrace(); - } - assertThat(session.isOpen()).isFalse(); - return res; - } - - private WriteResponseMeta writeScreenshotRecord(String warcId) throws ParseException, StatusException, InterruptedException { - ContentWriterSession session = contentWriterClient.createSession(); - assertThat(session.isOpen()).isTrue(); - - Sha1Digest blockDigest = new Sha1Digest(); - ByteString payloadData = ByteString.copyFromUtf8("binary png"); - blockDigest.update(payloadData); - - RecordMeta screenshotMeta = RecordMeta.newBuilder() - .setRecordNum(0) - .setSize(payloadData.size()) - .setBlockDigest(blockDigest.getPrefixedDigestString()) - .setType(RecordType.RESOURCE) - .setRecordContentType("image/png") - .setSubCollection(SubCollectionType.SCREENSHOT) - .addWarcConcurrentTo(warcId) - .build(); - WriteRequestMeta meta = WriteRequestMeta.newBuilder() - .setCollectionRef(ConfigRef.newBuilder().setKind(Kind.collection).setId("2fa23773-d7e1-4748-8ab6-9253e470a3f5")) - .setIpAddress("127.0.0.1") - .setTargetUri("http://www.example.com/index.html") - .setFetchTimeStamp(Timestamps.parse("2016-09-19T17:20:24Z")) - .putRecordMeta(0, screenshotMeta) - .build(); - session.sendMetadata(meta); - - Data screenshot = Data.newBuilder() - .setRecordNum(0) - .setData(payloadData) - .build(); - session.sendPayload(screenshot); - - WriteResponseMeta res = session.finish(); - assertThat(session.isOpen()).isFalse(); - return res; - } - - private WriteResponseMeta writeDnsRecord() throws ParseException, StatusException, InterruptedException { - ContentWriterSession session = contentWriterClient.createSession(); - assertThat(session.isOpen()).isTrue(); - - Sha1Digest blockDigest = new Sha1Digest(); - ByteString payloadData = ByteString.copyFromUtf8("dns record"); - blockDigest.update(payloadData); - - RecordMeta dnsMeta = RecordMeta.newBuilder() - .setRecordNum(0) - .setType(RecordType.RESOURCE) - .setRecordContentType("text/dns") - .setSize(payloadData.size()) - .setBlockDigest(blockDigest.getPrefixedDigestString()) - .setSubCollection(SubCollectionType.DNS) - .build(); - WriteRequestMeta meta = WriteRequestMeta.newBuilder() - .setTargetUri("dns:www.example.com") - .setFetchTimeStamp(Timestamps.parse("2016-09-19T17:20:24Z")) - .setIpAddress("127.0.0.1") - .setCollectionRef(ConfigRef.newBuilder().setKind(Kind.collection).setId("2fa23773-d7e1-4748-8ab6-9253e470a3f5")) - .putRecordMeta(0, dnsMeta) - .build(); - session.sendMetadata(meta); - - Data dns = Data.newBuilder() - .setRecordNum(0) - .setData(payloadData) - .build(); - session.sendPayload(dns); - - WriteResponseMeta res = session.finish(); - assertThat(session.isOpen()).isFalse(); - return res; - } - - public static class MyProjectAssertions extends Assertions { - public static WarcRecordAssert assertThat(WarcRecord actual) { - return new WarcRecordAssert(actual); - } - } - - public static class WarcRecordAssert extends AbstractAssert { - public WarcRecordAssert(WarcRecord actual) { - super(actual, WarcRecordAssert.class); - } - - public WarcRecordAssert hasVersion(int major, int minor) { - isNotNull(); - if (actual.header.major != major || actual.header.minor != minor) { - failWithMessage("Expected WARC version to be <%d.%d> but was <%d.%d>", major, minor, actual.header.major, actual.header.minor); - } - return this; - } - - public WarcRecordAssert hasValidHeaders() { - isNotNull(); - assertThat(actual.header.warcRecordIdStr).as("%s should not be null", FN_WARC_RECORD_ID).isNotEmpty(); - assertThat(actual.header.warcTypeStr).as("%s should not be null", FN_WARC_TYPE).isNotEmpty(); - assertThat(actual.header.warcDateStr).as("%s should not be null", FN_WARC_DATE).isNotEmpty(); - assertThat(actual.header.contentLengthStr).as("%s should not be null", FN_CONTENT_LENGTH).isNotEmpty(); - assertThat(actual.header.contentTypeStr).as("%s should not be null", FN_CONTENT_TYPE).isNotEmpty(); - - if (!actual.diagnostics.getErrors().isEmpty()) { - System.out.println("ERRORS: " + actual.diagnostics.getErrors() - .stream() - .map(d -> "\n " + d.type.toString() + ":" + d.entity + ":" + Arrays.toString(d.getMessageArgs())) - .collect(Collectors.joining())); - actual.getHeaderList().forEach(h -> System.out.print(" W: " + new String(h.raw))); - } - if (!actual.diagnostics.getWarnings().isEmpty()) { - System.out.println("WARNINGS: " + actual.diagnostics.getWarnings() - .stream() - .map(d -> "\n " + d.type.toString() + ":" + d.entity + ":" + Arrays.toString(d.getMessageArgs())) - .collect(Collectors.joining())); - actual.getHeaderList().forEach(h -> System.out.print(" W: " + new String(h.raw))); - } - assertThat(actual.isCompliant()).as("Record of type '%s' is not compliant", actual.header.warcTypeStr).isTrue(); - - switch (actual.header.warcTypeStr) { - case RT_CONTINUATION: - break; - case RT_CONVERSION: - break; - case RT_METADATA: - break; - case RT_REQUEST: - case RT_RESPONSE: - assertThat(actual.header.warcTargetUriStr) - .as("%s for record type '%s' should not be null", FN_WARC_TARGET_URI, actual.header.warcTypeStr) - .isNotEmpty(); - assertThat(actual.header.warcConcurrentToList) - .as("%s for record type '%s' should not be empty", FN_WARC_CONCURRENT_TO, actual.header.warcTypeStr) - .isNotEmpty(); - assertThat(actual.header.warcBlockDigestStr) - .as("%s for record type '%s' should not be empty", FN_WARC_BLOCK_DIGEST, actual.header.warcTypeStr) - .isNotEmpty(); - assertThat(actual.header.warcPayloadDigestStr) - .as("%s for record type '%s' should not be empty", FN_WARC_PAYLOAD_DIGEST, actual.header.warcTypeStr) - .isNotEmpty(); - assertThat(actual.header.warcIpAddress) - .as("%s for record type '%s' should not be empty", FN_WARC_IP_ADDRESS, actual.header.warcTypeStr) - .isNotEmpty(); - assertThat(actual.header.warcWarcinfoIdStr) - .as("%s for record type '%s' should not be empty", FN_WARC_WARCINFO_ID, actual.header.warcTypeStr) - .isNotEmpty(); - assertThat(actual.isValidBlockDigest) - .as("%s for record type '%s' doesn't validate", FN_WARC_BLOCK_DIGEST, actual.header.warcTypeStr) - .isTrue(); - assertThat(actual.isValidPayloadDigest) - .as("%s for record type '%s' doesn't validate", FN_WARC_PAYLOAD_DIGEST, actual.header.warcTypeStr) - .isTrue(); - break; - case RT_RESOURCE: - assertThat(actual.header.warcTargetUriStr) - .as("%s for record type '%s' should not be null", FN_WARC_TARGET_URI, actual.header.warcTypeStr) - .isNotEmpty(); - if ("text/dns".equals(actual.header.contentTypeStr)) { - assertThat(actual.header.warcConcurrentToList) - .as("%s for record type '%s' should be empty", FN_WARC_CONCURRENT_TO, actual.header.warcTypeStr) - .isEmpty(); - } else { - assertThat(actual.header.warcConcurrentToList) - .as("%s for record type '%s' should not be empty", FN_WARC_CONCURRENT_TO, actual.header.warcTypeStr) - .isNotEmpty(); - } - assertThat(actual.header.warcBlockDigestStr) - .as("%s for record type '%s' should not be empty", FN_WARC_BLOCK_DIGEST, actual.header.warcTypeStr) - .isNotEmpty(); - assertThat(actual.header.warcIpAddress) - .as("%s for record type '%s' should not be empty", FN_WARC_IP_ADDRESS, actual.header.warcTypeStr) - .isNotEmpty(); - assertThat(actual.header.warcWarcinfoIdStr) - .as("%s for record type '%s' should not be empty", FN_WARC_WARCINFO_ID, actual.header.warcTypeStr) - .isNotEmpty(); - assertThat(actual.isValidBlockDigest) - .as("%s for record type '%s' doesn't validate", FN_WARC_BLOCK_DIGEST, actual.header.warcTypeStr) - .isTrue(); - assertThat(actual.header.warcPayloadDigestStr) - .as("%s for record type '%s' should be empty", FN_WARC_PAYLOAD_DIGEST, actual.header.warcTypeStr) - .isNullOrEmpty(); - break; - case RT_REVISIT: - assertThat(actual.header.warcTargetUriStr) - .as("%s for record type '%s' should not be null", FN_WARC_TARGET_URI, actual.header.warcTypeStr) - .isNotEmpty(); - assertThat(actual.header.warcRefersToStr) - .as("%s for record type '%s' should not be empty", FN_WARC_REFERS_TO, actual.header.warcTypeStr) - .isNotEmpty(); - assertThat(actual.header.warcConcurrentToList) - .as("%s for record type '%s' should not be empty", FN_WARC_CONCURRENT_TO, actual.header.warcTypeStr) - .isNotEmpty(); - assertThat(actual.header.warcBlockDigestStr) - .as("%s for record type '%s' should not be empty", FN_WARC_BLOCK_DIGEST, actual.header.warcTypeStr) - .isNotEmpty(); - assertThat(actual.header.warcPayloadDigestStr) - .as("%s for record type '%s' should not be empty", FN_WARC_PAYLOAD_DIGEST, actual.header.warcTypeStr) - .isNotEmpty(); - assertThat(actual.header.warcIpAddress) - .as("%s for record type '%s' should not be empty", FN_WARC_IP_ADDRESS, actual.header.warcTypeStr) - .isNotEmpty(); - assertThat(actual.header.warcWarcinfoIdStr) - .as("%s for record type '%s' should not be empty", FN_WARC_WARCINFO_ID, actual.header.warcTypeStr) - .isNotEmpty(); - assertThat(actual.isValidBlockDigest) - .as("%s for record type '%s' doesn't validate", FN_WARC_BLOCK_DIGEST, actual.header.warcTypeStr) - .isTrue(); - break; - case RT_WARCINFO: - assertThat(actual.header.warcPayloadDigestStr) - .as("%s for record type '%s' should be empty", FN_WARC_PAYLOAD_DIGEST, actual.header.warcTypeStr) - .isNullOrEmpty(); - assertThat(actual.header.warcFilename) - .as("%s for record type '%s' should not be null", FN_WARC_FILENAME, actual.header.warcTypeStr) - .isNotEmpty(); - assertThat(actual.isValidBlockDigest) - .as("%s for record type '%s' doesn't validate", FN_WARC_BLOCK_DIGEST, actual.header.warcTypeStr) - .isTrue(); - break; - default: - failWithMessage("Illegal WARC-Type <%s>", actual.header.warcTypeStr); - } - return this; - } - } -} diff --git a/src/test/java/no/nb/nna/veidemann/contentwriter/ContentwriterServiceTest.java b/src/test/java/no/nb/nna/veidemann/contentwriter/ContentwriterServiceTest.java deleted file mode 100644 index ebdc0c4..0000000 --- a/src/test/java/no/nb/nna/veidemann/contentwriter/ContentwriterServiceTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2017 National Library of Norway. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package no.nb.nna.veidemann.contentwriter; - -import io.grpc.ManagedChannelBuilder; -import io.grpc.StatusException; -import io.grpc.inprocess.InProcessChannelBuilder; -import io.grpc.inprocess.InProcessServerBuilder; -import no.nb.nna.veidemann.commons.client.ContentWriterClient; -import no.nb.nna.veidemann.commons.db.DbService; -import no.nb.nna.veidemann.commons.db.DbServiceSPI; -import no.nb.nna.veidemann.contentwriter.warc.SingleWarcWriter; -import no.nb.nna.veidemann.contentwriter.warc.WarcCollectionRegistry; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import java.net.URISyntaxException; - -import static org.mockito.Mockito.mock; - -/** - * - */ -public class ContentwriterServiceTest { - - private final String uniqueServerName = "in-process server for " + getClass(); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void testSaveEntity() throws StatusException, InterruptedException, URISyntaxException { - DbServiceSPI dbProviderMock = mock(DbServiceSPI.class); - DbService.configure(dbProviderMock); - WarcCollectionRegistry warcCollectionRegistry = mock(WarcCollectionRegistry.class); - SingleWarcWriter singleWarcWriterMock = mock(SingleWarcWriter.class); - - InProcessServerBuilder inProcessServerBuilder = InProcessServerBuilder.forName(uniqueServerName).directExecutor(); - ManagedChannelBuilder inProcessChannelBuilder = InProcessChannelBuilder.forName(uniqueServerName).directExecutor(); - try (ApiServer inProcessServer = new ApiServer(inProcessServerBuilder, warcCollectionRegistry).start(); - ContentWriterClient client = new ContentWriterClient(inProcessChannelBuilder);) { - -// when(warcWriterPoolMock.borrow()).thenReturn(pooledWarcWriterMock); -// when(pooledWarcWriterMock.getWarcWriter()).thenReturn(singleWarcWriterMock); - - -// when(singleWarcWriterMock.writeWarcHeader(any())).thenReturn(new URI("foo:bar")); -// -// ContentWriterSession session1 = client.createSession(); -// ContentWriterSession session2 = client.createSession(); -// -// session1.sendHeader(ByteString.copyFromUtf8("head1")); -// session2.sendHeader(ByteString.copyFromUtf8("head2")); -// session1.sendCrawlLog(CrawlLog.getDefaultInstance()); -// session2.sendCrawlLog(CrawlLog.getDefaultInstance()); -// session1.finish(); -// session2.finish(); - } - } - -} diff --git a/src/test/java/no/nb/nna/veidemann/contentwriter/WarcFile.java b/src/test/java/no/nb/nna/veidemann/contentwriter/WarcFile.java deleted file mode 100644 index b71bd75..0000000 --- a/src/test/java/no/nb/nna/veidemann/contentwriter/WarcFile.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2019 National Library of Norway. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package no.nb.nna.veidemann.contentwriter; - -import okhttp3.HttpUrl; -import okhttp3.Request; -import okhttp3.Response; -import org.jwat.warc.WarcReader; -import org.jwat.warc.WarcReaderFactory; -import org.jwat.warc.WarcRecord; - -import java.io.IOException; -import java.util.Map; -import java.util.Spliterators; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -/** - * - */ -public class WarcFile { - - private String name; - - private long size; - - private String uri; - - WarcFile(Object o) { - if (o instanceof Map) { - Map m = (Map) o; - name = (String) m.get("name"); - size = ((Double) m.get("size")).longValue(); - uri = (String) m.get("uri"); - } else { - throw new IllegalArgumentException("expected java.util.Map, found " + o.getClass()); - } - } - - public String getName() { - return name; - } - - public long getSize() { - return size; - } - - public Stream getContent() { - HttpUrl url = WarcInspector.WARC_SERVER_URL.resolve("warcs/" + name); - Request request = new Request.Builder().url(url).build(); - try { - Response response = WarcInspector.CLIENT.newCall(request).execute(); - if (response.isSuccessful()) { - WarcReader warcReader = WarcReaderFactory.getReader(response.body().byteStream()); - warcReader.setBlockDigestEnabled(true); - warcReader.setPayloadDigestEnabled(true); - return StreamSupport.stream(Spliterators.spliteratorUnknownSize(warcReader.iterator(), 0), false) - .onClose(() -> { - warcReader.close(); - response.close(); - if (!(warcReader.diagnostics.getErrors().isEmpty() && warcReader.diagnostics.getWarnings().isEmpty())) { - System.err.println("WARC file '" + getName() + "' is not valid:"); - System.err.println(" Errors: " + warcReader.diagnostics.getErrors()); - System.err.println(" Warnings: " + warcReader.diagnostics.getWarnings()); - throw new RuntimeException("WARC file '" + getName() + "' is not valid"); - } - }); - } else { - throw new IOException("Unexpected code " + response); - } - } catch (Exception e) { - System.out.println("---------------"); - e.printStackTrace(); - } - return null; - } - - @Override - public String toString() { - return "WarcFile{" + "name=" + name + ", uri=" + uri + ", size=" + size + '}'; - } - -} diff --git a/src/test/java/no/nb/nna/veidemann/contentwriter/WarcFileSet.java b/src/test/java/no/nb/nna/veidemann/contentwriter/WarcFileSet.java deleted file mode 100644 index e22c62e..0000000 --- a/src/test/java/no/nb/nna/veidemann/contentwriter/WarcFileSet.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2019 National Library of Norway. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package no.nb.nna.veidemann.contentwriter; - -import org.jwat.warc.WarcRecord; - -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * - */ -public class WarcFileSet { - - private final List warcFiles; - - public WarcFileSet(Stream fileStream) { - warcFiles = fileStream.collect(Collectors.toList()); - } - - public Stream listFiles() { - return warcFiles.stream(); - } - - public Stream getRecordStream() { - Stream[] streams = listFiles() - .map(f -> f.getContent()).collect(Collectors.toList()).toArray(new Stream[]{}); - return Stream.of(streams).flatMap(s -> s).onClose(() -> { - for (Stream s : streams) { - try { - s.close(); - } catch (Exception e) { - // Nothing we can do except ensure that other streams are closed - // even if one throws an exception. - } - } - }); - } - - public Stream getContentRecordStream() { - return getRecordStream().filter(r -> r.header.warcTargetUriStr != null); - } - - public long getRecordCount() { - return getContentRecordStream().count(); - } - -} diff --git a/src/test/java/no/nb/nna/veidemann/contentwriter/WarcInspector.java b/src/test/java/no/nb/nna/veidemann/contentwriter/WarcInspector.java deleted file mode 100644 index c7d789f..0000000 --- a/src/test/java/no/nb/nna/veidemann/contentwriter/WarcInspector.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2019 National Library of Norway. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package no.nb.nna.veidemann.contentwriter; - -import com.google.common.net.HttpHeaders; -import com.google.gson.Gson; -import okhttp3.HttpUrl; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; - -import java.io.IOException; -import java.io.UncheckedIOException; -import java.util.List; - -/** - * - */ -public class WarcInspector { - - final static OkHttpClient CLIENT = new OkHttpClient.Builder().followRedirects(true).build(); - - final static Gson GSON = new Gson(); - - final static HttpUrl WARC_SERVER_URL; - - static { - String warcServerHost = System.getProperty("contentexplorer.host"); - int warcServerPort = Integer.parseInt(System.getProperty("contentexplorer.port")); - - WARC_SERVER_URL = new HttpUrl.Builder() - .scheme("http") - .host(warcServerHost) - .port(warcServerPort) - .build(); - } - - private WarcInspector() { - } - - public static WarcFileSet getWarcFiles() throws UncheckedIOException { - HttpUrl url = WARC_SERVER_URL.resolve("warcs"); - - Request request = new Request.Builder() - .url(url) - .header(HttpHeaders.ACCEPT, "application/json") - .build(); - - try (Response response = CLIENT.newCall(request).execute();) { - if (response.isSuccessful()) { - return new WarcFileSet(GSON.fromJson(response.body().charStream(), List.class) - .stream().map(m -> new WarcFile(m))); - } else { - throw new IOException("Unexpected code " + response); - } - } catch(IOException ex) { - throw new UncheckedIOException(ex); - } - } - - public static void deleteWarcFiles() { - HttpUrl url = WARC_SERVER_URL.resolve("warcs"); - - Request request = new Request.Builder() - .delete() - .url(url) - .build(); - - try (Response response = CLIENT.newCall(request).execute();) { - if (!response.isSuccessful()) { - throw new IOException("Unexpected code " + response); - } - } catch(IOException ex) { - throw new UncheckedIOException(ex); - } - } - - public static String getWarcHeadersForStorageRef(String storageRef) { - HttpUrl url = WARC_SERVER_URL.resolve("storageref/" + storageRef + "/warcheader"); - - Request request = new Request.Builder() - .url(url) - .build(); - - try (Response response = CLIENT.newCall(request).execute();) { - if (response.isSuccessful()) { - return response.body().string(); - } else { - throw new IOException("Unexpected code " + response); - } - } catch(IOException ex) { - throw new UncheckedIOException(ex); - } - } - - public static byte[] getWarcContentForStorageRef(String storageRef) { - HttpUrl url = WARC_SERVER_URL.resolve("storageref/" + storageRef); - - Request request = new Request.Builder() - .url(url) - .build(); - - try (Response response = CLIENT.newCall(request).execute();) { - if (response.isSuccessful()) { - return response.body().bytes(); - } else { - throw new IOException("Unexpected code " + response); - } - } catch(IOException ex) { - throw new UncheckedIOException(ex); - } - } -} diff --git a/src/test/java/no/nb/nna/veidemann/contentwriter/WriteSessionContextBuilder.java b/src/test/java/no/nb/nna/veidemann/contentwriter/WriteSessionContextBuilder.java deleted file mode 100644 index a43ea05..0000000 --- a/src/test/java/no/nb/nna/veidemann/contentwriter/WriteSessionContextBuilder.java +++ /dev/null @@ -1,29 +0,0 @@ -package no.nb.nna.veidemann.contentwriter; - -import no.nb.nna.veidemann.api.config.v1.ConfigObject; -import no.nb.nna.veidemann.api.contentwriter.v1.WriteRequestMeta; - -public class WriteSessionContextBuilder { - - private WriteRequestMeta.Builder writeRequestMeta; - private ConfigObject collectionConfig; - - public WriteSessionContextBuilder withWriteRequestMeta(WriteRequestMeta.Builder writeRequestMeta) { - this.writeRequestMeta = writeRequestMeta; - return this; - } - - public WriteSessionContextBuilder withCollectionConfig(ConfigObject collectionConfig) { - this.collectionConfig = collectionConfig; - return this; - } - - public WriteSessionContext build() { - WriteSessionContext context = new WriteSessionContext(); - - context.collectionConfig = collectionConfig; - context.writeRequestMeta = writeRequestMeta; - - return context; - } -} diff --git a/src/test/java/no/nb/nna/veidemann/contentwriter/warc/SingleWarcWriterTest.java b/src/test/java/no/nb/nna/veidemann/contentwriter/warc/SingleWarcWriterTest.java deleted file mode 100644 index f2d8293..0000000 --- a/src/test/java/no/nb/nna/veidemann/contentwriter/warc/SingleWarcWriterTest.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright 2017 National Library of Norway. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package no.nb.nna.veidemann.contentwriter.warc; - -import com.google.protobuf.ByteString; -import no.nb.nna.veidemann.api.config.v1.Collection; -import no.nb.nna.veidemann.api.config.v1.ConfigObject; -import no.nb.nna.veidemann.api.contentwriter.v1.RecordType; -import no.nb.nna.veidemann.api.contentwriter.v1.WriteRequestMeta; -import no.nb.nna.veidemann.commons.db.ExecutionsAdapter; -import no.nb.nna.veidemann.commons.db.DbService; -import no.nb.nna.veidemann.commons.db.DbServiceSPI; -import no.nb.nna.veidemann.contentwriter.ContentBuffer; -import no.nb.nna.veidemann.contentwriter.WriteSessionContext; -import no.nb.nna.veidemann.contentwriter.WriteSessionContextBuilder; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -import java.io.File; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -/** - * - */ -public class SingleWarcWriterTest { - - private final static String requestHeader = "Host: elg.no\n" + - "User-Agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:69.0) Gecko/20100101 Firefox/69.0\n" + - "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\n" + - "Accept-Language: nb-NO,nb;q=0.9,no-NO;q=0.8,no;q=0.6,nn-NO;q=0.5,nn;q=0.4,en-US;q=0.3,en;q=0.1\n" + - "Accept-Encoding: gzip, deflate\n" + - "Connection: keep-alive\n" + - "Upgrade-Insecure-Requests: 1\n"; - - private final static String responseHeader = "HTTP/1.1 200 OK\n" + - "Date: Thu, 03 Oct 2019 09:17:44 GMT\n" + - "Content-Type: text/html\n" + - "Transfer-Encoding: chunked\n" + - "Connection: keep-alive\n" + - "Set-Cookie: __cfduid=deafaee9d9fb85ec39631049d132a1e481570094263; expires=Fri, 02-Oct-20 09:17:43 GMT; path=/; domain=.elg.no; HttpOnly\n" + - "Last-Modified: Wed, 11 Sep 2019 10:56:04 GMT\n" + - "CF-Cache-Status: DYNAMIC\n" + - "Server: cloudflare\n" + - "CF-RAY: 51fdd31d6a85d895-CPH\n" + - "Content-Encoding: gzip\n"; - - private final static String responsePayload = "\n" + - "\n" + - "\n" + - "\n" + - "\n" + - "\n" + - "\n" + - "\n" + - "

www.elg.no

\n" + - "\n" + - "

Elger er gromme dyr.
\n" + - "Elgkalvene er mat for bl.a. ulv.

\n" + - "

Last ned Vivaldi på vivaldi.com

\n" + - "\n" + - "\n"; - - private static final String hostName = "test-host"; - - private static final String filePrefix = "test"; - - - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); - - /** - * Test of write method, of class SingleWarcWriter. - */ - @Test - public void testWrite() throws Exception { - DbServiceSPI dbProviderMock = mock(DbServiceSPI.class); - when(dbProviderMock.getExecutionsAdapter()).thenReturn(mock(ExecutionsAdapter.class)); - DbService.configure(dbProviderMock); - - final File targetDir = temporaryFolder.getRoot(); - final boolean compress = false; - - final Collection collection = Collection.newBuilder() - .setCompress(compress) - .setFileSize(2048) - .build(); - - final ConfigObject collectionConfig = ConfigObject.newBuilder() - .setCollection(collection) - .build(); - - - final WriteRequestMeta.Builder writeRequestMeta = WriteRequestMeta.newBuilder() - .setTargetUri("http://elg.no") - .setIpAddress("104.24.117.137"); - - final WriteSessionContext context = new WriteSessionContextBuilder() - .withWriteRequestMeta(writeRequestMeta) - .withCollectionConfig(collectionConfig) - .build(); - - // Request - ByteString header0 = ByteString.copyFromUtf8(requestHeader); - - WriteSessionContext.RecordData recordData0 = context.getRecordData(0); - ContentBuffer contentBuffer0 = recordData0.getContentBuffer(); - contentBuffer0.setHeader(header0); - - WriteRequestMeta.RecordMeta rm0 = WriteRequestMeta.RecordMeta.newBuilder() - .setSize(contentBuffer0.getTotalSize()) - .setType(RecordType.REQUEST) - .build(); - writeRequestMeta.putRecordMeta(0, rm0); - - // Response - ByteString header1 = ByteString.copyFromUtf8(responseHeader); - ByteString payload1 = ByteString.copyFromUtf8(responsePayload); - - WriteSessionContext.RecordData recordData1 = context.getRecordData(1); - ContentBuffer contentBuffer1 = recordData1.getContentBuffer(); - contentBuffer1.setHeader(header1); - contentBuffer1.addPayload(payload1); - - WriteRequestMeta.RecordMeta rm1 = WriteRequestMeta.RecordMeta.newBuilder() - .setType(RecordType.RESPONSE) - .setRecordContentType("text/html") - .setSize(contentBuffer1.getTotalSize()) - .build(); - - writeRequestMeta.putRecordMeta(1, rm1); - - try (SingleWarcWriter writer = new SingleWarcWriter(collectionConfig, null, filePrefix, targetDir, hostName)) { - for (Integer recordNum : context.getRecordNums()) { - try (WriteSessionContext.RecordData recordData = context.getRecordData(recordNum)) { - writer.writeRecord(recordData); - } catch (Exception e) { - e.printStackTrace(System.err); - throw e; - } - } - } - - - final File[] files = targetDir.listFiles(); - assertThat(files).isNotNull(); - for (final File f : files) { - assertThat(f).hasExtension(compress ? "gz" : "warc"); - } - } -} diff --git a/src/test/java/no/nb/nna/veidemann/contentwriter/warc/WarcCollectionTest.java b/src/test/java/no/nb/nna/veidemann/contentwriter/warc/WarcCollectionTest.java deleted file mode 100644 index 2bba3cc..0000000 --- a/src/test/java/no/nb/nna/veidemann/contentwriter/warc/WarcCollectionTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2019 National Library of Norway. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package no.nb.nna.veidemann.contentwriter.warc; - -import no.nb.nna.veidemann.api.config.v1.Collection.RotationPolicy; -import no.nb.nna.veidemann.api.config.v1.ConfigObject; -import no.nb.nna.veidemann.db.ProtoUtils; -import org.junit.Test; - -import java.time.OffsetDateTime; - -import static org.assertj.core.api.Assertions.assertThat; - -public class WarcCollectionTest { - - @Test - public void shouldFlushFiles() { - ConfigObject.Builder config = ConfigObject.newBuilder(); - config.getCollectionBuilder().setFileRotationPolicy(RotationPolicy.NONE); - - WarcCollection col = new WarcCollection(config.build()); - OffsetDateTime now = ProtoUtils.getNowOdt(); - - assertThat(col.shouldFlushFiles(config.build(), now)).isFalse(); - OffsetDateTime tomorrow = now.plusDays(1); - assertThat(col.shouldFlushFiles(config.build(), tomorrow)).isFalse(); - - config.getCollectionBuilder().setFileRotationPolicy(RotationPolicy.DAILY); - assertThat(col.shouldFlushFiles(config.build(), now)).isTrue(); - assertThat(col.shouldFlushFiles(config.build(), tomorrow)).isTrue(); - - col = new WarcCollection(config.build()); - assertThat(col.shouldFlushFiles(config.build(), now)).isFalse(); - assertThat(col.shouldFlushFiles(config.build(), tomorrow)).isTrue(); - } -} \ No newline at end of file diff --git a/src/test/resources/application.conf b/src/test/resources/application.conf deleted file mode 100644 index 88996cf..0000000 --- a/src/test/resources/application.conf +++ /dev/null @@ -1,25 +0,0 @@ -logTraffic=false - -# The port the server listens to. -apiPort=8080 -apiPort=${?API_PORT} - -# Where to put WARC files -warcDir="."; -warcDir=${?WARC_DIR} - -warcWriterPoolSize=2 -warcWriterPoolSize=${?WARC_WRITER_POOL_SIZE} - -# Where to put temporary files -workDir="." -workDir=${?WORK_DIR} - -# Regular expression matching url's which are allowed to do cross origin resource requests -corsAllowedOriginPattern="" - -hostName="unknown" -hostName=${?HOST_NAME} - -terminationGracePeriodSeconds=60 -terminationGracePeriodSeconds=${?TERMINATION_GRACE_PERIOD_SECONDS} diff --git a/src/test/resources/log4j2.xml b/src/test/resources/log4j2.xml deleted file mode 100644 index 0526386..0000000 --- a/src/test/resources/log4j2.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/telemetry/metrics.go b/telemetry/metrics.go new file mode 100644 index 0000000..fecbe9a --- /dev/null +++ b/telemetry/metrics.go @@ -0,0 +1,67 @@ +/* + * Copyright 2020 National Library of Norway. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package telemetry + +import ( + "github.com/prometheus/client_golang/prometheus" +) + +var ( + CanonicalizationsTotal = prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: metricsNs, + Subsystem: metricsSubsystem, + Name: "canonicalizations_total", + Help: "Total URIs canonicalized", + }) + + ScopechecksTotal = prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: metricsNs, + Subsystem: metricsSubsystem, + Name: "scopechecks_total", + Help: "Total URIs checked for scope inclusion", + }) + + ScopecheckResponseTotal = prometheus.NewCounterVec(prometheus.CounterOpts{ + Namespace: metricsNs, + Subsystem: metricsSubsystem, + Name: "scopecheck_response_total", + Help: "Total scopecheck responses for each response code", + }, + []string{"code"}, + ) + + CompileScriptSeconds = prometheus.NewHistogram(prometheus.HistogramOpts{ + Namespace: metricsNs, + Subsystem: metricsSubsystem, + Name: "script_compile_seconds", + Help: "Time for compiling a script in seconds", + Buckets: []float64{.005, .01, .025, .05, .075, .1, .25, .5, .75, 1, 2.5, 5, 7.5, 10, 20, 30, 40, 50, 60, 120, 180, 240}, + }) + + ExecuteScriptSeconds = prometheus.NewHistogram(prometheus.HistogramOpts{ + Namespace: metricsNs, + Subsystem: metricsSubsystem, + Name: "script_execute_seconds", + Help: "Time for executing a script in seconds", + Buckets: []float64{.005, .01, .025, .05, .075, .1, .25, .5, .75, 1, 2.5, 5, 7.5, 10, 20, 30, 40, 50, 60, 120, 180, 240}, + }) +) + +const ( + metricsNs = "veidemann" + metricsSubsystem = "scopeservice" +) diff --git a/telemetry/metrics_server.go b/telemetry/metrics_server.go new file mode 100644 index 0000000..2a0271f --- /dev/null +++ b/telemetry/metrics_server.go @@ -0,0 +1,87 @@ +/* + * Copyright 2020 National Library of Norway. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package telemetry + +import ( + "context" + "fmt" + "github.com/pkg/errors" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/collectors" + "github.com/prometheus/client_golang/prometheus/promhttp" + "github.com/rs/zerolog/log" + "net/http" + "sync" + "time" +) + +var once sync.Once + +// MetricsServer is the Prometheus metrics endpoint for the Browser Controller +type MetricsServer struct { + addr string + path string + server *http.Server +} + +// NewMetricsServer returns a new instance of MetricsServer listening on the given port +func NewMetricsServer(listenInterface string, listenPort int, path string) *MetricsServer { + a := &MetricsServer{ + addr: fmt.Sprintf("%s:%d", listenInterface, listenPort), + path: path, + } + once.Do(func() { + prometheus.MustRegister( + CanonicalizationsTotal, + ScopechecksTotal, + ScopecheckResponseTotal, + CompileScriptSeconds, + ExecuteScriptSeconds, + collectors.NewBuildInfoCollector(), + ) + }) + + return a +} + +func (a *MetricsServer) Start() error { + router := http.NewServeMux() + router.Handle(a.path, promhttp.Handler()) + + a.server = &http.Server{ + Addr: a.addr, + Handler: router, + ReadTimeout: 5 * time.Second, + WriteTimeout: 5 * time.Second, + IdleTimeout: 5 * time.Second, + } + + log.Info().Msgf("Metrics server listening on address: %s", a.addr) + err := a.server.ListenAndServe() + if err != nil && !errors.Is(err, http.ErrServerClosed) { + return fmt.Errorf("failed to listen on %s: %w", a.addr, err) + } + return nil +} + +func (a *MetricsServer) Close() { + log.Info().Msgf("Shutting down Metrics server") + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + a.server.SetKeepAlivesEnabled(false) + _ = a.server.Shutdown(ctx) +} diff --git a/telemetry/tracer.go b/telemetry/tracer.go new file mode 100644 index 0000000..fe67d24 --- /dev/null +++ b/telemetry/tracer.go @@ -0,0 +1,43 @@ +/* + * Copyright 2020 National Library of Norway. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package telemetry + +import ( + "github.com/opentracing/opentracing-go" + "github.com/uber/jaeger-client-go/config" + "github.com/uber/jaeger-client-go/log" + "io" +) + +// Init returns an instance of Jaeger Tracer that samples 100% of traces and logs all spans to stdout. +func InitTracer(service string) (opentracing.Tracer, io.Closer) { + cfg, err := config.FromEnv() + if err != nil { + log.StdLogger.Infof("ERROR: cannot init Jaeger from environment: %v", err) + return nil, nil + } + if cfg.ServiceName == "" { + cfg.ServiceName = service + } + + tracer, closer, err := cfg.NewTracer(config.Logger(log.StdLogger)) + if err != nil { + log.StdLogger.Infof("ERROR: cannot init Jaeger: %v", err) + return nil, nil + } + return tracer, closer +}