Given a BundlesField, request Snapshots for each of its filesets and create BundleAdaptors.
193137
def hydrate_bundles(bundles_field, glob_match_error_behavior):
  """"""
  path_globs_with_match_errors = [
    pg.copy(glob_match_error_behavior=glob_match_error_behavior)
    for pg in bundles_field.path_globs_list
  ]
  snapshot_list = yield [Get(Snapshot, PathGlobs, pg) for pg in path_globs_with_match_errors]

  spec_path = bundles_field.address.spec_path

  bundles = []
  zipped = zip(bundles_field.bundles,
               bundles_field.filespecs_list,
               snapshot_list)
  for bundle, filespecs, snapshot in zipped:
    rel_spec_path = getattr(bundle, 'rel_path', spec_path)
    kwargs = bundle.kwargs()
    # NB: We `include_dirs=True` because bundle filesets frequently specify directories in order
    # to trigger a (deprecated) default inclusion of their recursive contents. See the related
    # deprecation in `pants.backend.jvm.tasks.bundle_create`.
    kwargs['fileset'] = _eager_fileset_with_spec(rel_spec_path,
                                                 filespecs,
                                                 snapshot,
                                                 include_dirs=True)
    bundles.append(BundleAdaptor(**kwargs))
  yield HydratedField('bundles', bundles)
1161558
def symlink_bundles(self, app, bundle_dir):
    
    for bundle_counter, bundle in enumerate(app.bundles):
      count = 0
      for path, relpath in bundle.filemap.items():
        bundle_path = os.path.join(bundle_dir, relpath)
        count += 1
        if os.path.exists(bundle_path):
          continue

        if os.path.isfile(path):
          safe_mkdir(os.path.dirname(bundle_path))
          os.symlink(path, bundle_path)
        elif os.path.isdir(path):
          safe_mkdir(bundle_path)

      if count == 0:
        raise TargetDefinitionException(app.target,
                                        'Bundle index {} of "bundles" field '
                                        'does not match any files.'.format(bundle_counter))
1092733
private void createViewForSelectSpecificFields(Map<String, MapReduce> views)
    {
        if (views.get(CouchDBConstants.FIELDS) == null)
        {
            MapReduce mapr = new MapReduce();
            mapr.setMap("function(doc){for(field in doc){emit(field, doc[field]);}}");
            views.put(CouchDBConstants.FIELDS, mapr);
        }
    }
414852
private JoinableResourceBundle getBundleFromName(String bundleName, List<JoinableResourceBundle> bundles) {

		JoinableResourceBundle bundle = null;
		List<String> names = new ArrayList<>();
		names.add(bundleName);
		List<JoinableResourceBundle> result = getBundlesFromName(names, bundles);
		if (!result.isEmpty()) {
			bundle = result.get(0);
		}
		return bundle;
	}
1374993
def get_fieldsets(self, request, obj=None):
        '''  '''
        # If subclass declares fieldsets, this is respected
        if (hasattr(self, 'declared_fieldset') and self.declared_fieldsets) \
           or not self.base_fieldsets:
            return super(PolymorphicChildModelAdmin, self).get_fieldsets(request, obj)

        other_fields = self.get_subclass_fields(request, obj)

        if other_fields:
            return (
                (self.extra_fieldset_title, {'fields': other_fields}),
            ) + self.base_fieldsets
        else:
            return self.base_fieldsets
138785
def bundle_new(args, l, rc):
    """"""

    from ambry.orm.exc import ConflictError

    d = dict(
        dataset=args.dataset,
        revision=args.revision,
        source=args.source,
        bspace=args.space,
        subset=args.subset,
        btime=args.time,
        variation=args.variation)

    try:
        ambry_account = rc.accounts.get('ambry', {})
    except:
        ambry_account = None

    if not ambry_account:
        fatal("Failed to get an accounts.ambry entry from the configuration. ")

    if not ambry_account.get('name') or not ambry_account.get('email'):
        fatal('Must set accounts.ambry.email and accounts.ambry.name n account config file')

    if args.dryrun:
        from ..identity import Identity
        d['revision'] = 1
        d['id'] = 'dXXX'
        print(str(Identity.from_dict(d)))
        return

    try:
        b = l.new_bundle(assignment_class=args.key, **d)

        if ambry_account:
            b.metadata.contacts.wrangler = ambry_account

        b.build_source_files.bundle_meta.objects_to_record()
        b.commit()

    except ConflictError:
        fatal("Can't create dataset; one with a conflicting name already exists")

    print(b.identity.fqname)
683028
public void build(List<JoinableResourceBundle> bundlesToBuild, boolean forceWriteBundleMapping,
			StopWatch stopWatch) {

		stopProcessIfNeeded();

		if (LOGGER.isInfoEnabled()) {
			LOGGER.info("Starting bundle processing");
		}

		notifyStartBundlingProcess();

		boolean mappingFileExists = resourceBundleHandler.isExistingMappingFile();
		boolean processBundleFlag = !config.getUseBundleMapping() || !mappingFileExists;

		// Global preprocessing
		executeGlobalPreprocessing(bundlesToBuild, processBundleFlag, stopWatch);

		for (JoinableResourceBundle bundle : bundlesToBuild) {

			stopProcessIfNeeded();

			if (stopWatch != null) {
				stopWatch.start("Processing bundle '" + bundle.getName() + "'");
			}

			if (!ThreadLocalJawrContext.isBundleProcessingAtBuildTime() && null != bundle.getAlternateProductionURL()) {
				if (LOGGER.isDebugEnabled()) {
					LOGGER.debug("No bundle generated for '" + bundle.getId()
							+ "' because a production URL is defined for this bundle.");
				}
			}
			if (bundle instanceof CompositeResourceBundle) {
				joinAndStoreCompositeResourcebundle((CompositeResourceBundle) bundle);
			} else {
				joinAndStoreBundle(bundle);
			}

			if (config.getUseBundleMapping()) {
				JoinableResourceBundlePropertySerializer.serializeInProperties(bundle,
						resourceBundleHandler.getResourceType(), bundleMapping);
			}

			bundle.setDirty(false);

			if (stopWatch != null) {
				stopWatch.stop();
			}
		}

		executeGlobalPostProcessing(processBundleFlag, stopWatch);
		storeJawrBundleMapping(resourceBundleHandler.isExistingMappingFile(), true);

		// Update the watcher with the path to watch
		try {
			if (watcher != null) {
				watcher.initPathToResourceBundleMap(bundlesToBuild);
			}
		} catch (IOException e) {
			throw new BundlingProcessException(e);
		}

		notifyEndBundlingProcess();
		if (LOGGER.isInfoEnabled()) {
			LOGGER.info("End of bundle processing");
		}

	}
1061244
public void addRequiredBundles(String... requiredBundles) {
		String oldBundles = mainAttributes.get(REQUIRE_BUNDLE);
		if (oldBundles == null)
			oldBundles = "";
		BundleList oldResultList = BundleList.fromInput(oldBundles, newline);
		BundleList resultList = BundleList.fromInput(oldBundles, newline);
		for (String bundle : requiredBundles) {
			Bundle newBundle = Bundle.fromInput(bundle);
			if (name != null && name.equals(newBundle.getName()))
				continue;
			resultList.mergeInto(newBundle);
		}
		String result = resultList.toString();
		boolean changed = !oldResultList.toString().equals(result);
		modified |= changed;
		if (changed)
			mainAttributes.put(REQUIRE_BUNDLE, result);
	}
343834
def bundle(self, ref, capture_exceptions=False):
        """"""
        from ..orm.exc import NotFoundError

        if isinstance(ref, Dataset):
            ds = ref
        else:
            try:
                ds = self._db.dataset(ref)
            except NotFoundError:
                ds = None

        if not ds:
            try:
                p = self.partition(ref)
                ds = p._bundle.dataset
            except NotFoundError:
                ds = None

        if not ds:
            raise NotFoundError('Failed to find dataset for ref: {}'.format(ref))

        b = Bundle(ds, self)
        b.capture_exceptions = capture_exceptions

        return b
652000
def snapshots
      return @snapshots if @snapshots

      @snapshots = []
      @files.each do |f|
        io = File.open(f)
        @parser.read(io)
        @snapshots << @parser.snapshot
      end

      return @snapshots
    end
998288
def index_bundle(self, bundle, force=False):
        
        from ambry.orm.dataset import Dataset

        dataset = bundle if isinstance(bundle, Dataset) else bundle.dataset

        self.index_dataset(dataset, force)

        for partition in dataset.partitions:
            self.index_partition(partition, force)
1081966
public void installBundles(final BundleContext bContext,
                               final BundleList bundleList,
                               final BundleInstallStatus installStatus,
                               final int minStartLevel, final int defaultStartLevel,
                               final int defaultInitialStartLevel,
                               final WsLocationAdmin locSvc) {

        if (bundleList == null || bundleList.isEmpty())
            return;
        final FrameworkWiring fwkWiring = featureManager.bundleContext.getBundle(Constants.SYSTEM_BUNDLE_LOCATION).adapt(FrameworkWiring.class);
        final File bootFile = getBootJar();
        bundleList.foreach(new BundleList.FeatureResourceHandler() {
            @Override
            @FFDCIgnore({ IllegalStateException.class, Exception.class })
            public boolean handle(FeatureResource fr) {
                Bundle bundle = null;
                WsResource resource = null;
                String urlString = fr.getLocation();

                try {
                    String bundleRepositoryType = fr.getBundleRepositoryType();
                    BundleRepositoryHolder bundleRepositoryHolder = featureManager.getBundleRepositoryHolder(bundleRepositoryType);
                    if (bundleRepositoryHolder == null) {
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                            Tr.debug(tc, "Bundle repository not found for type=" + bundleRepositoryType);
                        }
                        Tr.error(tc, "UPDATE_MISSING_BUNDLE_ERROR", fr.getMatchString());
                        installStatus.addMissingBundle(fr);
                        return true;
                    }
                    // Get the product name for which the bundles are being installed.
                    String productName = bundleRepositoryHolder.getFeatureType();

                    if (libertyBoot) {
                        bundle = installLibertyBootBundle(productName, fr, fwkWiring);
                    } else {
                        bundle = installFeatureBundle(urlString, productName, bundleRepositoryHolder, fr);
                    }
                    if (bundle == null) {
                        return true;
                    }

                    BundleStartLevel bsl = bundle.adapt(BundleStartLevel.class);
                    BundleRevision bRev = bundle.adapt(BundleRevision.class);

                    int level = 0;

                    // For non-fragment bundles set the bundle startLevel then
                    // add to the list of bundles to be started.
                    // The order is important because the bundles are sorted by
                    // start level to preserve the start level ordering during
                    // dynamic feature additions.
                    if ((bRev.getTypes() & BundleRevision.TYPE_FRAGMENT) != BundleRevision.TYPE_FRAGMENT) {

                        level = bsl.getStartLevel();

                        // Set the start level on the bundle to the selected value
                        // if it hasn't been set before
                        if (level == defaultInitialStartLevel) {
                            int sl = fr.getStartLevel();
                            int newLevel = (sl == 0) ? defaultStartLevel : (sl < minStartLevel) ? minStartLevel : sl;
                            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                Tr.debug(this, tc, "Changing the start level of bundle {0} from {1} to the current level of {2}", bundle, level, newLevel);
                            }
                            level = newLevel;
                            bsl.setStartLevel(level);
                        }

                        installStatus.addBundleToStart(bundle);
                    }

                    // need to get a resource for the bundle list createAssociation
                    // call, if we end up with a null resource then bad things
                    // happen, like we fail to uninstall bundles when we should
                    File bundleFile = getBundleFile(bundle);
                    resource = locSvc.asResource(bundleFile, bundleFile.isFile());

                    // Update bundle list with resolved information
                    bundleList.createAssociation(fr, bundle, resource, level);
                } catch (IllegalStateException e) {
                    // The framework is stopping: this is an expected but not ideal occurrence.
                    installStatus.markContextInvalid(e);
                    return false;
                } catch (Exception e) {
                    // We encountered an error installing a bundle, add it to
                    // the status, and continue. The caller will handle as appropriate
                    installStatus.addInstallException("INSTALL " + urlString + " (resolved from: " + fr + ")", e);
                }
                return true;
            }

            private File getBundleFile(Bundle bundle) {
                if (libertyBoot) {
                    return bootFile;
                }
                // make sure we have a File for the bundle that is already
                // installed. Get this by processing the location. We
                // need to get past the reference:file: part of the URL.
                String location = bundle.getLocation();
                int index = location.indexOf(BUNDLE_LOC_REFERENCE_TAG);
                location = location.substring(index + BUNDLE_LOC_REFERENCE_TAG.length());
                // This file path is URL form, convert it back to a valid system File path
                return new File(URI.create(location));
            }

            private Bundle installLibertyBootBundle(String productName, FeatureResource fr, FrameworkWiring fwkWiring) throws BundleException, IOException {
                //getting the LibertyBootRuntime instance and installing the boot bundle
                LibertyBootRuntime libertyBoot = featureManager.getLibertyBoot();
                if (libertyBoot == null) {
                    throw new IllegalStateException("No LibertBootRuntime service available!");
                }

                Bundle bundle = libertyBoot.installBootBundle(fr.getSymbolicName(), fr.getVersionRange(), BUNDLE_LOC_FEATURE_TAG);
                if (bundle == null) {
                    installStatus.addMissingBundle(fr);
                    return null;
                }

                Region productRegion = getProductRegion(productName);
                Region current = featureManager.getDigraph().getRegion(bundle);
                if (!productRegion.equals(current)) {
                    current.removeBundle(bundle);
                    productRegion.addBundle(bundle);
                }
                return bundle;
            }

            private Bundle installFeatureBundle(String urlString, String productName, BundleRepositoryHolder bundleRepositoryHolder,
                                                FeatureResource fr) throws BundleException, IOException {
                Bundle bundle = fetchInstalledBundle(urlString, productName);
                if (bundle == null) {
                    ContentBasedLocalBundleRepository lbr = bundleRepositoryHolder.getBundleRepository();
                    // Try to find the file, hopefully using the cached path
                    File bundleFile = lbr.selectBundle(urlString, fr.getSymbolicName(), fr.getVersionRange());

                    if (bundleFile == null) {
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                            Tr.debug(tc, "Bundle not matched", lbr, fr);
                        }
                        Tr.error(tc, "UPDATE_MISSING_BUNDLE_ERROR", fr.getMatchString());
                        installStatus.addMissingBundle(fr);
                        return null;
                    }

                    // Get URL from filename
                    URI uri = bundleFile.toURI();
                    urlString = uri.toURL().toString();

                    urlString = PathUtils.normalize(urlString);

                    // Install this bundle as a "reference"-- this means that the
                    // framework will not copy this bundle into it's private cache,
                    // it will run from the actual jar (wherever it is).
                    urlString = BUNDLE_LOC_REFERENCE_TAG + urlString;

                    // Get the bundle location.
                    // The location format being returned must match the format in SchemaBundle and BundleList.
                    String location = getBundleLocation(urlString, productName);

                    Region productRegion = getProductRegion(productName);
                    // Bundle will just be returned if something from this location exists already.
                    bundle = productRegion.installBundleAtLocation(location, new URL(urlString).openStream());
                }
                return bundle;
            }

            private Bundle fetchInstalledBundle(String urlString, String productName) {
                // We install bundles as references so we need to ensure that we add reference: to the file url.
                String location = getBundleLocation(BUNDLE_LOC_REFERENCE_TAG + urlString, productName);
                Bundle b = featureManager.bundleContext.getBundle(location);

                if (b != null && b.getState() == Bundle.UNINSTALLED) {
                    b = null;
                }

                return b;
            }
        });
    }
907704
@Override
    public ExtendedSnapshotWriter newSnapshotWriter() throws StorageException {
        checkInitialized();

        try {
            return new SnapshotFileWriter(snapshotsDirectory);
        } catch (Exception e) {
            throw new StorageException("fail create snapshot request", e);
        }
    }
366918
@Override
	protected List<JoinableResourceBundle> filterBundlesToRender(List<JoinableResourceBundle> bundles) {
		List<JoinableResourceBundle> filteredBundles = new ArrayList<>();
		for (JoinableResourceBundle bundle : bundles) {
			if (bundle.getInclusionPattern().isIncludeOnDebug()) {
				filteredBundles.add(bundle);
			}
		}
		return filteredBundles;
	}
613937
protected synchronized void snapshotAll() {
        snapshotsManager.getAll().forEach(s -> {
            RepositorySnapshotter.SnapshotIdentifier id = s.prepare();
            s.snapshot(repository.getData(), id);
            s.commit(journalsStorage.getLastStoreVersion(), id);
        });
    }
624620
def snapshots():
    '''
    
    '''
    try:
        return _("collector").Inspector(cachedir=__opts__['cachedir'],
                                        piddir=os.path.dirname(__opts__['pidfile'])).db.list()
    except InspectorSnapshotException as err:
        raise CommandExecutionError(err)
    except Exception as err:
        log.error(_get_error_message(err))
        raise Exception(err)
54878
private void initResourceBundlesFromFullMapping(List<JoinableResourceBundle> resourceBundles) {

		if (LOGGER.isInfoEnabled()) {
			LOGGER.info("Building bundles from the full bundle mapping. Only modified bundles will be processed.");
		}
		Properties mappingProperties = resourceBundleHandler.getJawrBundleMapping();
		FullMappingPropertiesBasedBundlesHandlerFactory factory = new FullMappingPropertiesBasedBundlesHandlerFactory(
				resourceType, resourceReaderHandler, jawrConfig.getGeneratorRegistry(), chainFactory);

		resourceBundles.addAll(factory.getResourceBundles(mappingProperties));
	}