Skip to content

Commit

Permalink
Added priority selector to add replication screen (#1396)
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>

Co-authored-by: Benjamin Perez <benjamin@bexsoft.net>
  • Loading branch information
bexsoft and Benjamin Perez committed Jan 14, 2022
1 parent 826cb41 commit 257f02c
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 9 deletions.
3 changes: 3 additions & 0 deletions models/multi_bucket_replication.go

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

Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import React, { useState } from "react";
import React, { useState, useEffect } from "react";
import { connect } from "react-redux";
import { Theme } from "@mui/material/styles";
import createStyles from "@mui/styles/createStyles";
Expand All @@ -28,7 +28,7 @@ import {
modalStyleUtils,
spacingUtils,
} from "../../Common/FormComponents/common/styleLibrary";
import { BulkReplicationResponse } from "../types";
import { BucketReplicationRule, BulkReplicationResponse } from "../types";
import { setModalErrorSnackMessage } from "../../../../actions";
import { ErrorResponseHandler } from "../../../../common/types";
import InputBoxWrapper from "../../Common/FormComponents/InputBoxWrapper/InputBoxWrapper";
Expand All @@ -46,6 +46,7 @@ interface IReplicationModal {
classes: any;
bucketName: string;
setModalErrorSnackMessage: typeof setModalErrorSnackMessage;
setReplicationRules: BucketReplicationRule[];
}

const styles = (theme: Theme) =>
Expand Down Expand Up @@ -81,8 +82,10 @@ const AddReplicationModal = ({
classes,
bucketName,
setModalErrorSnackMessage,
setReplicationRules,
}: IReplicationModal) => {
const [addLoading, setAddLoading] = useState<boolean>(false);
const [priority, setPriority] = useState<string>("1");
const [accessKey, setAccessKey] = useState<string>("");
const [secretKey, setSecretKey] = useState<string>("");
const [targetURL, setTargetURL] = useState<string>("");
Expand All @@ -99,6 +102,23 @@ const AddReplicationModal = ({
const [bandwidthUnit, setBandwidthUnit] = useState<string>("Gi");
const [healthCheck, setHealthCheck] = useState<string>("60");

useEffect(() => {
if (setReplicationRules.length === 0) {
setPriority("1");
return;
}

const greatestValue = setReplicationRules.reduce((prevAcc, currValue) => {
if (currValue.priority > prevAcc) {
return currValue.priority;
}
return prevAcc;
}, 0);

const nextPriority = greatestValue + 1;
setPriority(nextPriority.toString());
}, [setReplicationRules]);

const addRecord = () => {
const replicate = [
{
Expand Down Expand Up @@ -127,6 +147,7 @@ const AddReplicationModal = ({
tags: tags,
replicateDeleteMarkers: repDeleteMarker,
replicateDeletes: repDelete,
priority: parseInt(priority),
};

api
Expand Down Expand Up @@ -184,6 +205,20 @@ const AddReplicationModal = ({
>
<Grid container>
<Grid item xs={12} className={classes.modalFormScrollable}>
<Grid item xs={12} className={classes.formFieldRow}>
<InputBoxWrapper
id="priority"
name="priority"
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.validity.valid) {
setPriority(e.target.value);
}
}}
label="Priority"
value={priority}
pattern={"[0-9]*"}
/>
</Grid>
<Grid item xs={12} className={classes.formFieldRow}>
<InputBoxWrapper
id="targetURL"
Expand Down
Expand Up @@ -159,7 +159,7 @@ const BucketReplicationPanel = ({
{
type: "delete",
onClick: confirmDeleteReplication,
disableButtonFunction: () => replicationRules.length > 1,
disableButtonFunction: () => replicationRules.length === 1,
},
];

Expand All @@ -170,6 +170,7 @@ const BucketReplicationPanel = ({
closeModalAndRefresh={closeAddReplication}
open={openSetReplication}
bucketName={bucketName}
setReplicationRules={replicationRules}
/>
)}

Expand Down
18 changes: 12 additions & 6 deletions restapi/admin_remote_buckets.go
Expand Up @@ -269,7 +269,7 @@ func addRemoteBucket(ctx context.Context, client MinioAdmin, params models.Creat
return bucketARN, err
}

func addBucketReplicationItem(ctx context.Context, session *models.Principal, minClient minioClient, bucketName, prefix, destinationARN string, repDelMark, repDels, repMeta bool, tags string) error {
func addBucketReplicationItem(ctx context.Context, session *models.Principal, minClient minioClient, bucketName, prefix, destinationARN string, repDelMark, repDels, repMeta bool, tags string, priority int32) error {
// we will tolerate this call failing
cfg, err := minClient.getBucketReplication(ctx, bucketName)
if err != nil {
Expand All @@ -278,12 +278,17 @@ func addBucketReplicationItem(ctx context.Context, session *models.Principal, mi

// add rule
maxPrio := 0
for _, r := range cfg.Rules {
if r.Priority > maxPrio {
maxPrio = r.Priority

if priority <= 0 { // We pick next priority by default
for _, r := range cfg.Rules {
if r.Priority > maxPrio {
maxPrio = r.Priority
}
}
maxPrio++
} else { // User picked priority, we try to set this manually
maxPrio = int(priority)
}
maxPrio++

s3Client, err := newS3BucketClient(session, bucketName, prefix)
if err != nil {
Expand Down Expand Up @@ -366,7 +371,8 @@ func setMultiBucketReplication(ctx context.Context, session *models.Principal, c
params.Body.ReplicateDeleteMarkers,
params.Body.ReplicateDeletes,
params.Body.ReplicateMetadata,
params.Body.Tags)
params.Body.Tags,
params.Body.Priority)
}

var errorReturn = ""
Expand Down
10 changes: 10 additions & 0 deletions restapi/embedded_spec.go

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

4 changes: 4 additions & 0 deletions swagger-console.yml
Expand Up @@ -2967,6 +2967,10 @@ definitions:
type: boolean
replicateMetadata:
type: boolean
priority:
type: integer
format: int32
default: 0
bucketsRelation:
type: array
minLength: 1
Expand Down

0 comments on commit 257f02c

Please sign in to comment.