Skip to content

Commit

Permalink
ResourceGroup interfaces for V2
Browse files Browse the repository at this point in the history
Signed-off-by: yhmo <[email protected]>
  • Loading branch information
yhmo committed Dec 26, 2024
1 parent d0cc726 commit 439298f
Show file tree
Hide file tree
Showing 16 changed files with 653 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.
*/

package io.milvus.common.resourcegroup;

import lombok.Data;
import lombok.experimental.SuperBuilder;

@Data
@SuperBuilder
public class NodeInfo {
private Long nodeId;
private String address;
private String hostname;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
/*
* 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.
*/

package io.milvus.common.resourcegroup;

import java.util.stream.Collectors;
import java.util.List;
import java.util.ArrayList;
import java.util.List;
import lombok.NonNull;
import lombok.Getter;

Expand All @@ -12,10 +31,12 @@ public class ResourceGroupConfig {
private final ResourceGroupLimit limits;
private final List<ResourceGroupTransfer> from;
private final List<ResourceGroupTransfer> to;
private final ResourceGroupNodeFilter nodeFilter;

private ResourceGroupConfig(Builder builder) {
this.requests = builder.requests;
this.limits = builder.limits;
this.nodeFilter = builder.nodeFilter;

if (null == builder.from) {
this.from = new ArrayList<>();
Expand All @@ -39,6 +60,7 @@ public static final class Builder {
private ResourceGroupLimit limits;
private List<ResourceGroupTransfer> from;
private List<ResourceGroupTransfer> to;
private ResourceGroupNodeFilter nodeFilter;

private Builder() {
}
Expand Down Expand Up @@ -67,7 +89,7 @@ public Builder withLimits(@NonNull ResourceGroupLimit limits) {

/**
* Set the transfer from list.
*
*
* @param from missing node should be transfer from given resource group at high priority in repeated list.
* @return <code>Builder</code>
*/
Expand All @@ -78,7 +100,7 @@ public Builder withFrom(@NonNull List<ResourceGroupTransfer> from) {

/**
* Set the transfer to list.
*
*
* @param to redundant node should be transfer to given resource group at high priority in repeated list.
* @return <code>Builder</code>
*/
Expand All @@ -87,6 +109,17 @@ public Builder withTo(@NonNull List<ResourceGroupTransfer> to) {
return this;
}

/**
* Set the node filter.
* @param nodeFilter if node filter set, resource group will prefer to accept node which match node filter.
* @return <code>Builder</code>
*/

public Builder withNodeFilter(@NonNull ResourceGroupNodeFilter nodeFilter) {
this.nodeFilter = nodeFilter;
return this;
}

public ResourceGroupConfig build() {
return new ResourceGroupConfig(this);
}
Expand All @@ -101,12 +134,14 @@ public ResourceGroupConfig(@NonNull io.milvus.grpc.ResourceGroupConfig grpcConfi
this.to = grpcConfig.getTransferToList().stream()
.map(transfer -> new ResourceGroupTransfer(transfer))
.collect(Collectors.toList());
this.nodeFilter = new ResourceGroupNodeFilter(grpcConfig.getNodeFilter());
}

public @NonNull io.milvus.grpc.ResourceGroupConfig toGRPC() {
io.milvus.grpc.ResourceGroupConfig.Builder builder = io.milvus.grpc.ResourceGroupConfig.newBuilder()
.setRequests(io.milvus.grpc.ResourceGroupLimit.newBuilder().setNodeNum(requests.getNodeNum()))
.setLimits(io.milvus.grpc.ResourceGroupLimit.newBuilder().setNodeNum(limits.getNodeNum()));
.setLimits(io.milvus.grpc.ResourceGroupLimit.newBuilder().setNodeNum(limits.getNodeNum()))
.setNodeFilter(nodeFilter.toGRPC());
for (ResourceGroupTransfer transfer : from) {
builder.addTransferFrom(transfer.toGRPC());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
package io.milvus.common.resourcegroup;
/*
* 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.
*/

import org.jetbrains.annotations.NotNull;
package io.milvus.common.resourcegroup;

import lombok.Getter;
import lombok.NonNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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.
*/

package io.milvus.common.resourcegroup;

import io.milvus.grpc.KeyValuePair;
import io.milvus.param.ParamUtils;
import lombok.Getter;
import lombok.NonNull;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Getter
public class ResourceGroupNodeFilter {
private final Map<String, String> nodeLabels;

private ResourceGroupNodeFilter(Builder builder) {
this.nodeLabels = builder.nodeLabels;
}

public static Builder newBuilder() {
return new Builder();
}

public static final class Builder {
private Map<String, String> nodeLabels = new HashMap<>();
private Builder() {
}

/**
* Set the node label filter
* @param key label name
* @param value label value
* @return <code>Builder</code>
*/
public Builder withNodeLabel(@NonNull String key, @NonNull String value) {
this.nodeLabels.put(key, value);
return this;
}

public ResourceGroupNodeFilter build() {
return new ResourceGroupNodeFilter(this);
}
}

/**
* Transfer to grpc
* @return io.milvus.grpc.ResourceGroupNodeFilter
*/
public @NonNull io.milvus.grpc.ResourceGroupNodeFilter toGRPC() {
List<KeyValuePair> pair = ParamUtils.AssembleKvPair(nodeLabels);
return io.milvus.grpc.ResourceGroupNodeFilter.newBuilder()
.addAllNodeLabels(pair)
.build();
}

/**
* Constructor from grpc
* @param filter grpc filter object
*/
public ResourceGroupNodeFilter(io.milvus.grpc.ResourceGroupNodeFilter filter) {
this.nodeLabels = filter.getNodeLabelsList().stream().collect(Collectors.toMap(KeyValuePair::getKey, KeyValuePair::getValue));
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* 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.
*/

package io.milvus.common.resourcegroup;

import lombok.Getter;
Expand Down
Loading

0 comments on commit 439298f

Please sign in to comment.