Search in sources :

Example 11 with StreamSpecification

use of co.cask.cdap.api.data.stream.StreamSpecification in project cdap by caskdata.

the class InMemoryStreamMetaStore method listStreams.

@Override
public synchronized Multimap<NamespaceId, StreamSpecification> listStreams() throws Exception {
    ImmutableMultimap.Builder<NamespaceId, StreamSpecification> builder = ImmutableMultimap.builder();
    for (String namespaceId : streams.keySet()) {
        synchronized (streams) {
            Collection<String> streamNames = streams.get(namespaceId);
            builder.putAll(new NamespaceId(namespaceId), Collections2.transform(streamNames, new Function<String, StreamSpecification>() {

                @Nullable
                @Override
                public StreamSpecification apply(String input) {
                    return new StreamSpecification.Builder().setName(input).create();
                }
            }));
        }
    }
    return builder.build();
}
Also used : Function(com.google.common.base.Function) StreamSpecification(co.cask.cdap.api.data.stream.StreamSpecification) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) NamespaceId(co.cask.cdap.proto.id.NamespaceId)

Example 12 with StreamSpecification

use of co.cask.cdap.api.data.stream.StreamSpecification in project cdap by caskdata.

the class LocalStreamService method runOneIteration.

@Override
protected void runOneIteration() throws Exception {
    // Get stream size - which will be the entire size - and send a notification if the size is big enough
    for (Map.Entry<NamespaceId, StreamSpecification> streamSpecEntry : streamMetaStore.listStreams().entries()) {
        StreamId streamId = streamSpecEntry.getKey().stream(streamSpecEntry.getValue().getName());
        StreamSizeAggregator streamSizeAggregator = aggregators.get(streamId);
        try {
            if (streamSizeAggregator == null) {
                // First time that we see this Stream here
                StreamConfig config;
                try {
                    config = streamAdmin.getConfig(streamId);
                } catch (FileNotFoundException e) {
                    // this is a stream that has no configuration: ignore it to avoid flooding the logs with exceptions
                    continue;
                }
                streamSizeAggregator = createSizeAggregator(streamId, 0, config.getNotificationThresholdMB());
            }
            streamSizeAggregator.checkAggregatedSize();
        } catch (Exception e) {
            // Need to catch and not to propagate the exception, otherwise this scheduled service will be terminated
            // Just log the exception here as the next run iteration should have the problem fixed
            LOG.warn("Exception in aggregating stream size for {}", streamId, e);
        }
    }
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) StreamSpecification(co.cask.cdap.api.data.stream.StreamSpecification) FileNotFoundException(java.io.FileNotFoundException) StreamConfig(co.cask.cdap.data2.transaction.stream.StreamConfig) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) NotificationFeedException(co.cask.cdap.notifications.feeds.NotificationFeedException) FileNotFoundException(java.io.FileNotFoundException)

Example 13 with StreamSpecification

use of co.cask.cdap.api.data.stream.StreamSpecification in project cdap by caskdata.

the class ApplicationDetail method fromSpec.

public static ApplicationDetail fromSpec(ApplicationSpecification spec, @Nullable String ownerPrincipal) {
    List<ProgramRecord> programs = new ArrayList<>();
    for (ProgramSpecification programSpec : spec.getFlows().values()) {
        programs.add(new ProgramRecord(ProgramType.FLOW, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getMapReduce().values()) {
        programs.add(new ProgramRecord(ProgramType.MAPREDUCE, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getServices().values()) {
        programs.add(new ProgramRecord(ProgramType.SERVICE, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getSpark().values()) {
        programs.add(new ProgramRecord(ProgramType.SPARK, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getWorkers().values()) {
        programs.add(new ProgramRecord(ProgramType.WORKER, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getWorkflows().values()) {
        programs.add(new ProgramRecord(ProgramType.WORKFLOW, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    List<StreamDetail> streams = new ArrayList<>();
    for (StreamSpecification streamSpec : spec.getStreams().values()) {
        streams.add(new StreamDetail(streamSpec.getName()));
    }
    List<DatasetDetail> datasets = new ArrayList<>();
    for (DatasetCreationSpec datasetSpec : spec.getDatasets().values()) {
        datasets.add(new DatasetDetail(datasetSpec.getInstanceName(), datasetSpec.getTypeName()));
    }
    List<PluginDetail> plugins = new ArrayList<>();
    for (Map.Entry<String, Plugin> pluginEnty : spec.getPlugins().entrySet()) {
        plugins.add(new PluginDetail(pluginEnty.getKey(), pluginEnty.getValue().getPluginClass().getName(), pluginEnty.getValue().getPluginClass().getType()));
    }
    // this is only required if there are old apps lying around that failed to get upgrading during
    // the upgrade to v3.2 for some reason. In those cases artifact id will be null until they re-deploy the app.
    // in the meantime, we don't want this api call to null pointer exception.
    ArtifactSummary summary = spec.getArtifactId() == null ? new ArtifactSummary(spec.getName(), null) : ArtifactSummary.from(spec.getArtifactId());
    return new ApplicationDetail(spec.getName(), spec.getAppVersion(), spec.getDescription(), spec.getConfiguration(), streams, datasets, programs, plugins, summary, ownerPrincipal);
}
Also used : ProgramSpecification(co.cask.cdap.api.ProgramSpecification) StreamSpecification(co.cask.cdap.api.data.stream.StreamSpecification) ArrayList(java.util.ArrayList) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) DatasetCreationSpec(co.cask.cdap.internal.dataset.DatasetCreationSpec) Map(java.util.Map) Plugin(co.cask.cdap.api.plugin.Plugin)

Example 14 with StreamSpecification

use of co.cask.cdap.api.data.stream.StreamSpecification in project cdap by caskdata.

the class CDAPEntities method collect.

@Override
public void collect() throws Exception {
    reset();
    List<NamespaceMeta> namespaceMetas;
    namespaceMetas = nsQueryAdmin.list();
    namespaces = namespaceMetas.size();
    for (NamespaceMeta meta : namespaceMetas) {
        List<ApplicationRecord> appRecords = appLifecycleService.getApps(meta.getNamespaceId(), Predicates.<ApplicationRecord>alwaysTrue());
        apps += appRecords.size();
        Set<ProgramType> programTypes = EnumSet.of(ProgramType.FLOW, ProgramType.MAPREDUCE, ProgramType.SERVICE, ProgramType.SPARK, ProgramType.WORKER, ProgramType.WORKFLOW);
        for (ProgramType programType : programTypes) {
            programs += programLifecycleService.list(meta.getNamespaceId(), programType).size();
        }
        artifacts += artifactRepository.getArtifactSummaries(meta.getNamespaceId(), true).size();
        datasets += dsFramework.getInstances(meta.getNamespaceId()).size();
        List<StreamSpecification> streamSpecs = streamAdmin.listStreams(meta.getNamespaceId());
        streams += streamSpecs.size();
        for (StreamSpecification streamSpec : streamSpecs) {
            StreamId streamId = meta.getNamespaceId().stream(streamSpec.getName());
            streamViews += streamAdmin.listViews(streamId).size();
        }
    }
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) StreamSpecification(co.cask.cdap.api.data.stream.StreamSpecification) ProgramType(co.cask.cdap.proto.ProgramType) ApplicationRecord(co.cask.cdap.proto.ApplicationRecord)

Aggregations

StreamSpecification (co.cask.cdap.api.data.stream.StreamSpecification)14 StreamId (co.cask.cdap.proto.id.StreamId)7 NamespaceId (co.cask.cdap.proto.id.NamespaceId)6 Map (java.util.Map)4 DatasetCreationSpec (co.cask.cdap.internal.dataset.DatasetCreationSpec)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 Plugin (co.cask.cdap.api.plugin.Plugin)2 StreamConfig (co.cask.cdap.data2.transaction.stream.StreamConfig)2 NotificationFeedException (co.cask.cdap.notifications.feeds.NotificationFeedException)2 FileNotFoundException (java.io.FileNotFoundException)2 ArrayList (java.util.ArrayList)2 ProgramSpecification (co.cask.cdap.api.ProgramSpecification)1 ArtifactId (co.cask.cdap.api.artifact.ArtifactId)1 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)1 DataSetException (co.cask.cdap.api.dataset.DataSetException)1 DatasetSpecification (co.cask.cdap.api.dataset.DatasetSpecification)1 FlowSpecification (co.cask.cdap.api.flow.FlowSpecification)1 MapReduceSpecification (co.cask.cdap.api.mapreduce.MapReduceSpecification)1 ScheduleSpecification (co.cask.cdap.api.schedule.ScheduleSpecification)1 ServiceSpecification (co.cask.cdap.api.service.ServiceSpecification)1