Add a set of interfaces for k8s pod, service, endpoint

Change-Id: Ie67c5d1a0678bdd651dac24363ab3feab5098919
This commit is contained in:
Jian Li 2019-02-19 11:18:54 +09:00
parent 1cee988ec6
commit d893a66459
20 changed files with 811 additions and 1 deletions

View File

@ -4,6 +4,11 @@ BUNDLES = [
"@commons_net//jar",
"@k8s_client//jar",
"@k8s_model//jar",
"@okhttp//jar",
"@okio//jar",
"@logging_interceptor//jar",
"@jackson_dataformat_yaml//jar",
"@snakeyaml//jar",
]
onos_app(

View File

@ -1,4 +1,12 @@
COMPILE_DEPS = CORE_DEPS
COMPILE_DEPS = CORE_DEPS + [
"@k8s_client//jar",
"@k8s_model//jar",
"@okhttp//jar",
"@okio//jar",
"@logging_interceptor//jar",
"@jackson_dataformat_yaml//jar",
"@snakeyaml//jar",
]
TEST_DEPS = TEST_ADAPTERS + [
"//core/api:onos-api-tests",

View File

@ -0,0 +1,50 @@
/*
* Copyright 2019-present Open Networking Foundation
*
* 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 org.onosproject.k8snetworking.api;
import io.fabric8.kubernetes.api.model.Endpoints;
/**
* Service for administering the inventory of kubernetes endpoint.
*/
public interface K8sEndpointsAdminService extends K8sEndpointsService {
/**
* Creates kubernetes endpoints with the given information.
*
* @param endpoints the new kubernetes endpoints
*/
void createEndpoints(Endpoints endpoints);
/**
* Updates the kubernetes endpoints with the given information.
*
* @param endpoints the updated kubernetes endpoints
*/
void updateEndpoints(Endpoints endpoints);
/**
* Removes the kubernetes endpoints.
*
* @param uid kubernetes endpoint UID
*/
void removeEndpoints(String uid);
/**
* Clears the existing endpoints.
*/
void clear();
}

View File

@ -0,0 +1,56 @@
/*
* Copyright 2019-present Open Networking Foundation
*
* 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 org.onosproject.k8snetworking.api;
import io.fabric8.kubernetes.api.model.Endpoints;
import org.onosproject.event.AbstractEvent;
/**
* Describes kubernetes endpoints event.
*/
public class K8sEndpointsEvent extends AbstractEvent<K8sEndpointsEvent.Type, Endpoints> {
/**
* Creates an event of a given type for the specified kubernetes endpoints.
*
* @param type kubernetes endpoints event type
* @param subject kubernetes endpoints
*/
public K8sEndpointsEvent(Type type, Endpoints subject) {
super(type, subject);
}
/**
* Kubernetes endpoints events.
*/
public enum Type {
/**
* Signifies that a new kubernetes endpoints is created.
*/
K8S_ENDPOINTS_CREATED,
/**
* Signifies that the kubernetes endpoints is updated.
*/
K8S_ENDPOINTS_UPDATED,
/**
* Signifies that the kubernetes endpoints is removed.
*/
K8S_ENDPOINTS_REMOVED,
}
}

View File

@ -0,0 +1,24 @@
/*
* Copyright 2019-present Open Networking Foundation
*
* 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 org.onosproject.k8snetworking.api;
import org.onosproject.event.EventListener;
/**
* Listener for kubernetes endpoints event.
*/
public interface K8sEndpointsListener extends EventListener<K8sEndpointsEvent> {
}

View File

@ -0,0 +1,43 @@
/*
* Copyright 2019-present Open Networking Foundation
*
* 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 org.onosproject.k8snetworking.api;
import io.fabric8.kubernetes.api.model.Endpoints;
import org.onosproject.event.ListenerService;
import java.util.Set;
/**
* Service for interacting with the inventory of kubernetes endpoints.
*/
public interface K8sEndpointsService
extends ListenerService<K8sEndpointsEvent, K8sEndpointsListener> {
/**
* Returns the kubernetes endpoints with the supplied endpoints UID.
*
* @param uid endpoint UID
* @return kubernetes endpoints
*/
Endpoints endpoints(String uid);
/**
* Returns all kubernetes endpoints registered.
*
* @return set of kubernetes endpoints
*/
Set<Endpoints> endpointses();
}

View File

@ -0,0 +1,70 @@
/*
* Copyright 2019-present Open Networking Foundation
*
* 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 org.onosproject.k8snetworking.api;
import io.fabric8.kubernetes.api.model.Endpoints;
import org.onosproject.store.Store;
import java.util.Set;
/**
* Manages inventory of kubernetes endpoints; not intended for direct use.
*/
public interface K8sEndpointsStore
extends Store<K8sEndpointsEvent, K8sEndpointsStoreDelegate> {
/**
* Creates the new kubernetes endpoints.
*
* @param endpoints kubernetes endpoints
*/
void createEndpoints(Endpoints endpoints);
/**
* Updates the kubernetes endpoints.
*
* @param endpoints kubernetes endpoints
*/
void updateEndpoints(Endpoints endpoints);
/**
* Removes the kubernetes endpoints with the given endpoints UID.
*
* @param uid kubernetes endpoints UID
* @return removed kubernetes endpoints; null if failed
*/
Endpoints removeEndpoints(String uid);
/**
* Returns the kubernetes endpoints with the given endpoints UID.
*
* @param uid kubernetes endpoints UID
* @return kubernetes endpoints; null if not found
*/
Endpoints endpoints(String uid);
/**
* Returns all kubernetes endpoints.
*
* @return set of kubernetes endpoints
*/
Set<Endpoints> endpointses();
/**
* Removes all kubernetes endpoints.
*/
void clear();
}

View File

@ -0,0 +1,24 @@
/*
* Copyright 2019-present Open Networking Foundation
*
* 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 org.onosproject.k8snetworking.api;
import org.onosproject.store.StoreDelegate;
/**
* Kubernetes endpoints store delegate abstraction.
*/
public interface K8sEndpointsStoreDelegate extends StoreDelegate<K8sEndpointsEvent> {
}

View File

@ -0,0 +1,50 @@
/*
* Copyright 2019-present Open Networking Foundation
*
* 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 org.onosproject.k8snetworking.api;
import io.fabric8.kubernetes.api.model.Pod;
/**
* Service for administering the inventory of kubernetes service.
*/
public interface K8sPodAdminService extends K8sPodService {
/**
* Creates a kubernetes service with the given information.
*
* @param pod the new kubernetes pod
*/
void createPod(Pod pod);
/**
* Updates the kubernetes pod with the given information.
*
* @param pod the updated kubernetes pod
*/
void updatePod(Pod pod);
/**
* Removes the kubernetes pod.
*
* @param uid kubernetes pod UID
*/
void removePod(String uid);
/**
* Clears the existing pods.
*/
void clear();
}

View File

@ -0,0 +1,53 @@
/*
* Copyright 2019-present Open Networking Foundation
*
* 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 org.onosproject.k8snetworking.api;
import io.fabric8.kubernetes.api.model.Pod;
import org.onosproject.event.AbstractEvent;
public class K8sPodEvent extends AbstractEvent<K8sPodEvent.Type, Pod> {
/**
* Creates an event of a given type for the specified kubernetes pod.
*
* @param type kubernetes pod event type
* @param subject kubernetes pod
*/
protected K8sPodEvent(Type type, Pod subject) {
super(type, subject);
}
/**
* Kubernetes pod events.
*/
public enum Type {
/**
* Signifies that a new kubernetes pod is created.
*/
K8S_POD_CREATED,
/**
* Signifies that the kubernetes pod is updated.
*/
K8S_POD_UPDATED,
/**
* Signifies that the kubernetes pod is removed.
*/
K8S_POD_REMOVED,
}
}

View File

@ -0,0 +1,24 @@
/*
* Copyright 2019-present Open Networking Foundation
*
* 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 org.onosproject.k8snetworking.api;
import org.onosproject.event.EventListener;
/**
* Listener for kubernetes pod event.
*/
public interface K8sPodListener extends EventListener<K8sPodEvent> {
}

View File

@ -0,0 +1,43 @@
/*
* Copyright 2019-present Open Networking Foundation
*
* 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 org.onosproject.k8snetworking.api;
import io.fabric8.kubernetes.api.model.Pod;
import org.onosproject.event.ListenerService;
import java.util.Set;
/**
* Service for interacting with the inventory of kubernetes service.
*/
public interface K8sPodService
extends ListenerService<K8sPodEvent, K8sPodListener> {
/**
* Returns the kubernetes pod with the supplied pod UID.
*
* @param uid pod UID
* @return kubernetes pod
*/
Pod pod(String uid);
/**
* Returns all kubernetes pods registered.
*
* @return set of kubernetes pods
*/
Set<Pod> pods();
}

View File

@ -0,0 +1,69 @@
/*
* Copyright 2019-present Open Networking Foundation
*
* 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 org.onosproject.k8snetworking.api;
import io.fabric8.kubernetes.api.model.Pod;
import org.onosproject.store.Store;
import java.util.Set;
/**
* Manages inventory of kubernetes pod; not intended for direct use.
*/
public interface K8sPodStore extends Store<K8sPodEvent, K8sPodStoreDelegate> {
/**
* Creates the new kubernetes pod.
*
* @param pod kubernetes pod
*/
void createPod(Pod pod);
/**
* Updates the kubernetes pod.
*
* @param pod kubernetes pod
*/
void updatePod(Pod pod);
/**
* Removes the kubernetes pod with the given pod UID.
*
* @param uid kubernetes pod UID
* @return removed kubernetes pod; null if failed
*/
Pod removePod(String uid);
/**
* Returns the kubernetes pod with the given pod UID.
*
* @param uid kubernetes pod UID
* @return kubernetes pod; null if not found
*/
Pod pod(String uid);
/**
* Returns all kubernetes pods.
*
* @return set of kubernetes pods
*/
Set<Pod> pods();
/**
* Removes all kubernetes pods.
*/
void clear();
}

View File

@ -0,0 +1,24 @@
/*
* Copyright 2019-present Open Networking Foundation
*
* 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 org.onosproject.k8snetworking.api;
import org.onosproject.store.StoreDelegate;
/**
* Kubernetes pod store delegate abstraction.
*/
public interface K8sPodStoreDelegate extends StoreDelegate<K8sPodEvent> {
}

View File

@ -0,0 +1,50 @@
/*
* Copyright 2019-present Open Networking Foundation
*
* 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 org.onosproject.k8snetworking.api;
import io.fabric8.kubernetes.api.model.Service;
/**
* Service for administering the inventory of kubernetes service.
*/
public interface K8sServiceAdminService extends K8sServiceService {
/**
* Creates a kubernetes service with the given information.
*
* @param service the new kubernetes service
*/
void createService(Service service);
/**
* Updates the kubernetes service with the given information.
*
* @param service the updated kubernetes service
*/
void updateService(Service service);
/**
* Removes the kubernetes service.
*
* @param uid kubernetes service UID
*/
void removeService(String uid);
/**
* Clears the existing services.
*/
void clear();
}

View File

@ -0,0 +1,56 @@
/*
* Copyright 2019-present Open Networking Foundation
*
* 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 org.onosproject.k8snetworking.api;
import io.fabric8.kubernetes.api.model.Service;
import org.onosproject.event.AbstractEvent;
/**
* Describes kubernetes service event.
*/
public class K8sServiceEvent extends AbstractEvent<K8sServiceEvent.Type, Service> {
/**
* Creates an event of a given type for the specified kubernetes service.
*
* @param type kubernetes service event type
* @param subject kubernetes service
*/
public K8sServiceEvent(Type type, Service subject) {
super(type, subject);
}
/**
* Kubernetes service events.
*/
public enum Type {
/**
* Signifies that a new kubernetes service is created.
*/
K8S_SERVICE_CREATED,
/**
* Signifies that the kubernetes service is updated.
*/
K8S_SERVICE_UPDATED,
/**
* Signifies that the kubernetes service is removed.
*/
K8S_SERVICE_REMOVED,
}
}

View File

@ -0,0 +1,24 @@
/*
* Copyright 2019-present Open Networking Foundation
*
* 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 org.onosproject.k8snetworking.api;
import org.onosproject.event.EventListener;
/**
* Listener for kubernetes service event.
*/
public interface K8sServiceListener extends EventListener<K8sServiceEvent> {
}

View File

@ -0,0 +1,43 @@
/*
* Copyright 2019-present Open Networking Foundation
*
* 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 org.onosproject.k8snetworking.api;
import io.fabric8.kubernetes.api.model.Service;
import org.onosproject.event.ListenerService;
import java.util.Set;
/**
* Service for interacting with the inventory of kubernetes service.
*/
public interface K8sServiceService
extends ListenerService<K8sServiceEvent, K8sServiceListener> {
/**
* Returns the kubernetes service with the supplied service UID.
*
* @param uid service UID
* @return kubernetes service
*/
Service service(String uid);
/**
* Returns all kubernetes services registered.
*
* @return set of kubernetes services
*/
Set<Service> services();
}

View File

@ -0,0 +1,70 @@
/*
* Copyright 2019-present Open Networking Foundation
*
* 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 org.onosproject.k8snetworking.api;
import io.fabric8.kubernetes.api.model.Service;
import org.onosproject.store.Store;
import java.util.Set;
/**
* Manages inventory of kubernetes service; not intended for direct use.
*/
public interface K8sServiceStore
extends Store<K8sServiceEvent, K8sServiceStoreDelegate> {
/**
* Creates the new kubernetes service.
*
* @param service kubernetes service
*/
void createService(Service service);
/**
* Updates the kubernetes service.
*
* @param service kubernetes service
*/
void updateService(Service service);
/**
* Removes the kubernetes service with the given service UID.
*
* @param uid kubernetes service UID
* @return removed kubernetes service; null if failed
*/
Service removeService(String uid);
/**
* Returns the kubernetes service with the given service UID.
*
* @param uid kubernetes service UID
* @return kubernetes service; null if not found
*/
Service service(String uid);
/**
* Returns all kubernetes services.
*
* @return set of kubernetes services
*/
Set<Service> services();
/**
* Removes all kubernetes services.
*/
void clear();
}

View File

@ -0,0 +1,24 @@
/*
* Copyright 2019-present Open Networking Foundation
*
* 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 org.onosproject.k8snetworking.api;
import org.onosproject.store.StoreDelegate;
/**
* Kubernetes service store delegate abstraction.
*/
public interface K8sServiceStoreDelegate extends StoreDelegate<K8sServiceEvent> {
}