|
@@ -8,10 +8,12 @@ import io.kubernetes.client.models.V1LimitRangeList;
|
|
|
import io.kubernetes.client.models.V1Status;
|
|
import io.kubernetes.client.models.V1Status;
|
|
|
import nju.seec.SEECdemo.logic.api.k8s.LimitRangeApi;
|
|
import nju.seec.SEECdemo.logic.api.k8s.LimitRangeApi;
|
|
|
import nju.seec.SEECdemo.logic.api.k8s.exception.K8sApiException;
|
|
import nju.seec.SEECdemo.logic.api.k8s.exception.K8sApiException;
|
|
|
-import nju.seec.SEECdemo.logic.api.k8s.vo.LimitRange;
|
|
|
|
|
|
|
+import nju.seec.SEECdemo.logic.api.k8s.model.LimitRange;
|
|
|
|
|
+import nju.seec.SEECdemo.logic.api.k8s.vo.LimitRangeVO;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
@@ -24,14 +26,14 @@ public class LimitRangeApiImpl implements LimitRangeApi {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public V1LimitRange toLimitRange(String namespace, String name, Map<String, Integer> _default, Map<String, Integer> defaultRequest, Map<String, Integer> max, Map<String, Integer> min) {
|
|
public V1LimitRange toLimitRange(String namespace, String name, Map<String, Integer> _default, Map<String, Integer> defaultRequest, Map<String, Integer> max, Map<String, Integer> min) {
|
|
|
- LimitRange limitRange = new LimitRange();
|
|
|
|
|
- limitRange.setName(name);
|
|
|
|
|
- limitRange.setNamespace(namespace);
|
|
|
|
|
- limitRange.set_default(_default);
|
|
|
|
|
- limitRange.setDefault_request(defaultRequest);
|
|
|
|
|
- limitRange.setMax(max);
|
|
|
|
|
- limitRange.setMin(min);
|
|
|
|
|
- return limitRange.toV1LimitRange();
|
|
|
|
|
|
|
+ LimitRangeVO limitRangeVO = new LimitRangeVO();
|
|
|
|
|
+ limitRangeVO.setName(name);
|
|
|
|
|
+ limitRangeVO.setNamespace(namespace);
|
|
|
|
|
+ limitRangeVO.set_default(_default);
|
|
|
|
|
+ limitRangeVO.setDefault_request(defaultRequest);
|
|
|
|
|
+ limitRangeVO.setMax(max);
|
|
|
|
|
+ limitRangeVO.setMin(min);
|
|
|
|
|
+ return limitRangeVO.toV1LimitRange();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -56,6 +58,12 @@ public class LimitRangeApiImpl implements LimitRangeApi {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public LimitRange createLimitRange(String namespace, LimitRange limitRange) throws K8sApiException {
|
|
|
|
|
+ V1LimitRange v1LimitRange = createLimitRange(namespace, limitRange.toV1LimitRange());
|
|
|
|
|
+ return limitRange;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void deleteLimitRange(String namespace, String name) throws K8sApiException {
|
|
public void deleteLimitRange(String namespace, String name) throws K8sApiException {
|
|
|
V1DeleteOptions body = new V1DeleteOptions();
|
|
V1DeleteOptions body = new V1DeleteOptions();
|
|
@@ -72,27 +80,29 @@ public class LimitRangeApiImpl implements LimitRangeApi {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public List<V1LimitRange> getLimitRangeList(String namespace) throws K8sApiException {
|
|
|
|
|
|
|
+ public List<LimitRange> getLimitRangeList(String namespace) throws K8sApiException {
|
|
|
try {
|
|
try {
|
|
|
V1LimitRangeList limitRangeList = coreV1Api.listNamespacedLimitRange(namespace, "OK", "", "", false, "", 5, "", 5, false);
|
|
V1LimitRangeList limitRangeList = coreV1Api.listNamespacedLimitRange(namespace, "OK", "", "", false, "", 5, "", 5, false);
|
|
|
- List<V1LimitRange> result = limitRangeList.getItems();
|
|
|
|
|
- if (result.isEmpty()) {
|
|
|
|
|
|
|
+ List<V1LimitRange> itemList = limitRangeList.getItems();
|
|
|
|
|
+ if (itemList.isEmpty()) {
|
|
|
throw new K8sApiException(K8sApiException.NOT_FOUND);
|
|
throw new K8sApiException(K8sApiException.NOT_FOUND);
|
|
|
} else {
|
|
} else {
|
|
|
|
|
+ List<LimitRange> result = new ArrayList<>();
|
|
|
|
|
+ for (V1LimitRange v1LimitRange : itemList)
|
|
|
|
|
+ result.add(LimitRange.toLimitRange(v1LimitRange));
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
} catch (ApiException e) {
|
|
} catch (ApiException e) {
|
|
|
//如果namespace不存在也不会抛出异常,会返回一个空的list
|
|
//如果namespace不存在也不会抛出异常,会返回一个空的list
|
|
|
throw K8sApiException.K8s_SYSTEM_ERROR_EXCEPTION;
|
|
throw K8sApiException.K8s_SYSTEM_ERROR_EXCEPTION;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public V1LimitRange getLimitRangeByName(String namespace, String name) throws K8sApiException {
|
|
|
|
|
- List<V1LimitRange> list = getLimitRangeList(namespace);
|
|
|
|
|
- for (V1LimitRange limitRange : list) {
|
|
|
|
|
- if (limitRange.getMetadata().getName().equals(name)) {
|
|
|
|
|
|
|
+ public LimitRange getLimitRangeByName(String namespace, String name) throws K8sApiException {
|
|
|
|
|
+ List<LimitRange> list = getLimitRangeList(namespace);
|
|
|
|
|
+ for (LimitRange limitRange : list) {
|
|
|
|
|
+ if (limitRange.getName().equals(name)) {
|
|
|
return limitRange;
|
|
return limitRange;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -105,4 +115,12 @@ public class LimitRangeApiImpl implements LimitRangeApi {
|
|
|
deleteLimitRange(namespace, name);
|
|
deleteLimitRange(namespace, name);
|
|
|
return createLimitRange(namespace, body);
|
|
return createLimitRange(namespace, body);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public LimitRange updateLimitRange(String namespace, String name, LimitRange body) throws K8sApiException {
|
|
|
|
|
+ deleteLimitRange(namespace, name);
|
|
|
|
|
+ return createLimitRange(namespace, body);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|