use of org.onlab.util.ItemNotFoundException in project onos by opennetworkinglab.
the class K8sManagementWebResource method syncStates.
/**
* Synchronizes the all states with kubernetes API server.
*
* @return 200 OK with sync result, 404 not found
* @throws InterruptedException exception
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("sync/states")
public Response syncStates() {
K8sApiConfig config = configService.apiConfigs().stream().findAny().orElse(null);
if (config == null) {
throw new ItemNotFoundException("Failed to find valid kubernetes API configuration.");
}
KubernetesClient client = K8sNetworkingUtil.k8sClient(config);
if (client == null) {
throw new ItemNotFoundException("Failed to connect to kubernetes API server.");
}
client.namespaces().list().getItems().forEach(ns -> {
if (namespaceAdminService.namespace(ns.getMetadata().getUid()) != null) {
namespaceAdminService.updateNamespace(ns);
} else {
namespaceAdminService.createNamespace(ns);
}
});
client.services().inAnyNamespace().list().getItems().forEach(svc -> {
if (serviceAdminService.service(svc.getMetadata().getUid()) != null) {
serviceAdminService.updateService(svc);
} else {
serviceAdminService.createService(svc);
}
});
client.endpoints().inAnyNamespace().list().getItems().forEach(ep -> {
if (endpointsAdminService.endpoints(ep.getMetadata().getUid()) != null) {
endpointsAdminService.updateEndpoints(ep);
} else {
endpointsAdminService.createEndpoints(ep);
}
});
client.pods().inAnyNamespace().list().getItems().forEach(pod -> {
if (podAdminService.pod(pod.getMetadata().getUid()) != null) {
podAdminService.updatePod(pod);
} else {
podAdminService.createPod(pod);
}
syncPortFromPod(pod, networkAdminService);
});
client.extensions().ingresses().inAnyNamespace().list().getItems().forEach(ingress -> {
if (ingressAdminService.ingress(ingress.getMetadata().getUid()) != null) {
ingressAdminService.updateIngress(ingress);
} else {
ingressAdminService.createIngress(ingress);
}
});
client.network().networkPolicies().inAnyNamespace().list().getItems().forEach(policy -> {
if (policyAdminService.networkPolicy(policy.getMetadata().getUid()) != null) {
policyAdminService.updateNetworkPolicy(policy);
} else {
policyAdminService.createNetworkPolicy(policy);
}
});
return ok(mapper().createObjectNode()).build();
}
use of org.onlab.util.ItemNotFoundException in project onos by opennetworkinglab.
the class MappingsWebResource method getMappingsByDeviceId.
/**
* Gets mapping entries of a device. Returns array of all mappings for the
* specified device.
*
* @param deviceId device identifier
* @param type mapping store type
* @return 200 OK with a collection of mappings of given device
*
* @onos.rsModel MappingEntries
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/{type}")
public Response getMappingsByDeviceId(@PathParam("deviceId") String deviceId, @PathParam("type") String type) {
Device device = deviceService.getDevice(DeviceId.deviceId(deviceId));
if (device == null) {
throw new ItemNotFoundException(DEVICE_NOT_FOUND);
}
final Iterable<MappingEntry> mappingEntries = mappingService.getMappingEntries(getTypeEnum(type), device.id());
if (mappingEntries == null || !mappingEntries.iterator().hasNext()) {
return ok(root).build();
}
for (final MappingEntry entry : mappingEntries) {
mappingsNode.add(codec(MappingEntry.class).encode(entry, this));
}
return ok(root).build();
}
use of org.onlab.util.ItemNotFoundException in project onos by opennetworkinglab.
the class AlarmManager method updateBookkeepingFields.
@Override
public Alarm updateBookkeepingFields(AlarmId id, boolean clear, boolean isAcknowledged, String assignedUser) {
checkNotNull(id, "Alarm id is null");
Alarm found = store.getAlarm(id);
if (found == null) {
throw new ItemNotFoundException("Alarm with id " + id + " found");
}
long now = System.currentTimeMillis();
DefaultAlarm.Builder alarmBuilder = new DefaultAlarm.Builder(found).withTimeUpdated(now);
if (found.cleared() != clear) {
alarmBuilder.clear().withTimeCleared(now);
}
if (found.acknowledged() != isAcknowledged) {
alarmBuilder.withAcknowledged(isAcknowledged);
}
if (assignedUser != null && !found.assignedUser().equals(assignedUser)) {
alarmBuilder.withAssignedUser(assignedUser);
}
DefaultAlarm updated = alarmBuilder.build();
store.createOrUpdateAlarm(updated);
return updated;
}
use of org.onlab.util.ItemNotFoundException in project onos by opennetworkinglab.
the class OpenstackManagementWebResource method syncStates.
/**
* Synchronizes the network states with openstack.
*
* @return 200 OK with sync result, 404 not found
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("sync/states")
public Response syncStates() {
Map<String, String> headerMap = new HashMap();
headerMap.put(HTTP_HEADER_ACCEPT, HTTP_HEADER_VALUE_JSON);
Optional<OpenstackNode> node = osNodeAdminService.nodes(CONTROLLER).stream().findFirst();
if (!node.isPresent()) {
log.error(AUTH_INFO_NOT_FOUND);
throw new ItemNotFoundException(AUTH_INFO_NOT_FOUND);
}
OSClient osClient = OpenstackNetworkingUtil.getConnectedClient(node.get());
if (osClient == null) {
log.error(AUTH_INFO_NOT_CORRECT);
throw new ItemNotFoundException(AUTH_INFO_NOT_CORRECT);
}
try {
osClient.headers(headerMap).networking().securitygroup().list().forEach(osSg -> {
if (osSgAdminService.securityGroup(osSg.getId()) != null) {
osSgAdminService.updateSecurityGroup(osSg);
} else {
osSgAdminService.createSecurityGroup(osSg);
}
});
} catch (Exception e) {
log.warn("Failed to retrieve security group due to {}", e.getMessage());
return Response.serverError().build();
}
try {
osClient.headers(headerMap).networking().network().list().forEach(osNet -> {
if (osNetAdminService.network(osNet.getId()) != null) {
osNetAdminService.updateNetwork(osNet);
} else {
osNetAdminService.createNetwork(osNet);
}
});
} catch (Exception e) {
log.warn("Failed to retrieve network due to {}", e.getMessage());
return Response.serverError().build();
}
try {
osClient.headers(headerMap).networking().subnet().list().forEach(osSubnet -> {
if (osNetAdminService.subnet(osSubnet.getId()) != null) {
osNetAdminService.updateSubnet(osSubnet);
} else {
osNetAdminService.createSubnet(osSubnet);
}
});
} catch (Exception e) {
log.warn("Failed to retrieve subnet due to {}", e.getMessage());
return Response.serverError().build();
}
try {
osClient.headers(headerMap).networking().port().list().forEach(osPort -> {
if (osNetAdminService.port(osPort.getId()) != null) {
osNetAdminService.updatePort(osPort);
} else {
osNetAdminService.createPort(osPort);
}
});
} catch (Exception e) {
log.warn("Failed to retrieve port due to {}", e.getMessage());
return Response.serverError().build();
}
try {
osClient.headers(headerMap).networking().router().list().forEach(osRouter -> {
if (osRouterAdminService.router(osRouter.getId()) != null) {
osRouterAdminService.updateRouter(osRouter);
} else {
osRouterAdminService.createRouter(osRouter);
}
osNetAdminService.ports().stream().filter(osPort -> Objects.equals(osPort.getDeviceId(), osRouter.getId()) && Objects.equals(osPort.getDeviceOwner(), DEVICE_OWNER_IFACE)).forEach(osPort -> addRouterIface(osPort, osRouterAdminService));
});
} catch (Exception e) {
log.warn("Failed to retrieve router due to {}", e.getMessage());
return Response.serverError().build();
}
try {
osClient.headers(headerMap).networking().floatingip().list().forEach(osFloating -> {
if (osRouterAdminService.floatingIp(osFloating.getId()) != null) {
osRouterAdminService.updateFloatingIp(osFloating);
} else {
osRouterAdminService.createFloatingIp(osFloating);
}
});
} catch (Exception e) {
log.warn("Failed to retrieve floating IP due to {}", e.getMessage());
return Response.serverError().build();
}
return ok(mapper().createObjectNode()).build();
}
use of org.onlab.util.ItemNotFoundException in project onos by opennetworkinglab.
the class OpenstackManagementWebResource method purgeRulesBase.
private boolean purgeRulesBase() {
ApplicationId appId = coreService.getAppId(Constants.OPENSTACK_NETWORKING_APP_ID);
if (appId == null) {
throw new ItemNotFoundException("application not found");
}
flowRuleService.removeFlowRulesById(appId);
boolean result = true;
long timeoutExpiredMs = System.currentTimeMillis() + TIMEOUT_MS;
// we make sure all flow rules are removed from the store
while (stream(flowRuleService.getFlowEntriesById(appId).spliterator(), false).count() > 0) {
long waitMs = timeoutExpiredMs - System.currentTimeMillis();
try {
sleep(SLEEP_MS);
} catch (InterruptedException e) {
log.error("Exception caused during rule purging...");
}
if (stream(flowRuleService.getFlowEntriesById(appId).spliterator(), false).count() == 0) {
break;
} else {
flowRuleService.removeFlowRulesById(appId);
log.info("Failed to purging flow rules, retrying rule purging...");
}
if (waitMs <= 0) {
result = false;
break;
}
}
if (result) {
log.info("Successfully purged flow rules!");
} else {
log.warn("Failed to purge flow rules.");
}
return result;
}
Aggregations