Determines if a streaming distribution exists for a given space

@throws UnsupportedTaskException if no distribution exists
488289
protected void checkThatStreamingServiceIsEnabled(String spaceId, String taskName) {
        // Verify that streaming is enabled
        Map<String, String> spaceProperties = s3Provider.getSpaceProperties(spaceId);
        if (!spaceProperties.containsKey(HLS_STREAMING_HOST_PROP)) {
            throw new UnsupportedTaskException(
                taskName,
                "The " + taskName + " task can only be used after a space " +
                "has been configured to enable HLS streaming. Use " +
                StorageTaskConstants.ENABLE_HLS_TASK_NAME +
                " to enable HLS streaming on this space.");
        }
    }
212118
def space_exists(args):
    
    # The return value is the INVERSE of UNIX exit status semantics, (where
    # 0 = good/true, 1 = bad/false), so to check existence in UNIX one would do
    #   if ! fissfc space_exists blah ; then
    #      ...
    #   fi
    try:
        r = fapi.get_workspace(args.project, args.workspace)
        fapi._check_response_code(r, 200)
        exists = True
    except FireCloudServerError as e:
        if e.code == 404:
            exists = False
        else:
            raise
    if fcconfig.verbosity:
        result = "DOES NOT" if not exists else "DOES"
        eprint('Space <%s> %s exist in project <%s>' %
                                (args.workspace, result, args.project))
    return exists
183918
protected List<StreamingDistributionSummary> getAllExistingDistributions(String bucketName) {

        List<StreamingDistributionSummary> distListForBucket = new ArrayList<>();

        StreamingDistributionList distList =
            cfClient.listStreamingDistributions(new ListStreamingDistributionsRequest())
                    .getStreamingDistributionList();

        List<StreamingDistributionSummary> streamingDistList = distList.getItems();
        while (distList.isTruncated()) {
            distList = cfClient.listStreamingDistributions(
                new ListStreamingDistributionsRequest().withMarker(distList.getNextMarker()))
                               .getStreamingDistributionList();
            streamingDistList.addAll(distList.getItems());
        }

        for (StreamingDistributionSummary distSummary : streamingDistList) {
            if (isDistFromBucket(bucketName, distSummary)) {
                distListForBucket.add(distSummary);
            }
        }

        return distListForBucket;
    }
347830
private void doPreemptionNow() {
    int totalShare = nodeManager.getAllocatedCpuForType(type);
    poolGroupManager.distributeShare(totalShare);
    for (PoolGroupSchedulable poolGroup : poolGroupManager.getPoolGroups()) {
      poolGroup.distributeShare();
    }
    int tasksToPreempt = countTasksShouldPreempt();
    if (tasksToPreempt > 0) {
      LOG.info("Found " + tasksToPreempt + " " + type + " tasks to preempt");
      preemptTasks(tasksToPreempt);
    }
  }
737152
public String performTask(String taskParameters) {
        GetSignedUrlTaskParameters taskParams =
            GetSignedUrlTaskParameters.deserialize(taskParameters);

        String spaceId = taskParams.getSpaceId();
        String contentId = taskParams.getContentId();
        String resourcePrefix = taskParams.getResourcePrefix();
        String ipAddress = taskParams.getIpAddress();
        int minutesToExpire = taskParams.getMinutesToExpire();
        if (minutesToExpire <= 0) {
            minutesToExpire = DEFAULT_MINUTES_TO_EXPIRE;
        }

        log.info("Performing " + TASK_NAME + " task with parameters: spaceId=" + spaceId +
                 ", contentId=" + contentId + ", resourcePrefix=" + resourcePrefix +
                 ", minutesToExpire=" + minutesToExpire + ", ipAddress=" + ipAddress);

        // Will throw if bucket does not exist
        String bucketName = unwrappedS3Provider.getBucketName(spaceId);
        GetSignedUrlTaskResult taskResult = new GetSignedUrlTaskResult();

        // Ensure that streaming service is on
        checkThatStreamingServiceIsEnabled(spaceId, TASK_NAME);

        // Retrieve the existing distribution for the given space
        StreamingDistributionSummary existingDist =
            getExistingDistribution(bucketName);
        if (null == existingDist) {
            throw new UnsupportedTaskException(TASK_NAME,
                                               "The " + TASK_NAME + " task can only be used after a space " +
                                               "has been configured to enable secure streaming. Use " +
                                               StorageTaskConstants.ENABLE_STREAMING_TASK_NAME +
                                               " to enable secure streaming on this space.");
        }
        String domainName = existingDist.getDomainName();

        // Verify that this is a secure distribution
        if (existingDist.getTrustedSigners().getItems().isEmpty()) {
            throw new UnsupportedTaskException(TASK_NAME,
                                               "The " + TASK_NAME + " task cannot be used to request a " +
                                               "stream from an open distribution. Use " +
                                               StorageTaskConstants.GET_URL_TASK_NAME + " instead.");
        }

        // Make sure resourcePrefix is a valid string
        if (null == resourcePrefix) {
            resourcePrefix = "";
        }

        // Define expiration date/time
        Calendar expireCalendar = Calendar.getInstance();
        expireCalendar.add(Calendar.MINUTE, minutesToExpire);

        try {

            File cfKeyPathFile = getCfKeyPathFile(this.cfKeyPath);
            String signedUrl =
                CloudFrontUrlSigner.getSignedURLWithCustomPolicy(
                    SignerUtils.Protocol.rtmp,
                    domainName,
                    cfKeyPathFile,
                    contentId,
                    cfKeyId,
                    expireCalendar.getTime(),
                    null,
                    ipAddress);
            taskResult.setSignedUrl("rtmp://" + domainName + "/cfx/st/" +
                                    resourcePrefix + signedUrl);
        } catch (InvalidKeySpecException | IOException e) {
            throw new RuntimeException("Error encountered attempting to sign URL for" +
                                       " task " + TASK_NAME + ": " + e.getMessage(), e);
        }

        String toReturn = taskResult.serialize();
        log.info("Result of " + TASK_NAME + " task: " + toReturn);
        return toReturn;
    }
600547
protected StreamingDistributionSummary getExistingDistribution(String bucketName) {

        List<StreamingDistributionSummary> dists =
            getAllExistingDistributions(bucketName);
        if (dists.isEmpty()) {
            return null;
        } else {
            return dists.get(0);
        }
    }
890678
public void distributeShare() {
    if (needRedistributed) {
      ScheduleComparator sc = configManager.getPoolGroupComparator(getName());
      Schedulable.distributeShare(getShare(), snapshotPools, sc);
    }
    needRedistributed = false;
  }
409534
private boolean hasEnoughDiskSpace(ClusterNode node) {
    int total = node.getTotal().diskGB;
    int free = node.getFree().diskGB;
    if (free < nodeReservedDiskGB) {
      if (LOG.isDebugEnabled()) {
        LOG.debug(node.getHost() + " not enough disk space." +
          " totalMB:" + total +
          " free:" + free +
          " limit:" + nodeReservedDiskGB);
      }
      return false;
    }
    return true;
  }
1340961
@Override
	public boolean exists() {
		// Return false if any of the resources in this aggregated resource
		// does not exist
		boolean result = true;
		for (IResource resource : resources) {
			if (!resource.exists()) {
				result = false;
				break;
			}
		}
		return result;
	}
356449
def verify_space_available(self, search_pattern=r"(\d+) \w+ free"):
        """"""
        if self.direction == "put":
            space_avail = self.remote_space_available(search_pattern=search_pattern)
        elif self.direction == "get":
            space_avail = self.local_space_available()
        if space_avail > self.file_size:
            return True
        return False
824710
public boolean writeToStream(SendfileOutputStream os, 
                               long offset, long length,
                               long []blockAddresses, long blockLength)
    throws IOException
  {
    throw new UnsupportedOperationException(getClass().getName());
  }
465234
public static boolean checkHasNextSafely(Iterator iterator) {
        try {
            /* Throw a ServiceConfigurationError if a provider-configuration file violates the specified format,
            or if it names a provider class that cannot be found and instantiated, or if the result of
            instantiating the class is not assignable to the service type, or if any other kind of exception
            or error is thrown as the next provider is located and instantiated.
            @see http://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html#iterator()
            */
            return iterator.hasNext();
        } catch (Exception | ServiceConfigurationError e) {
            LOGGER.trace("Can't load some service using Java SPI", e);
            LOGGER.error(e.getMessage());
            return false;
        }
    }
490734
private AFTPClient actionExistsDir() throws PageException, IOException {
	required("directory", directory);

	AFTPClient client = getClient();
	boolean res = existsDir(client, directory);
	Struct cfftp = writeCfftp(client);

	cfftp.setEL(RETURN_VALUE, Caster.toBoolean(res));
	cfftp.setEL(SUCCEEDED, Boolean.TRUE);

	stoponerror = false;
	return client;
    }
1181419
public static void assertNoWorkspacesOpen(String msg, boolean allowScopedOut) throws ND4JWorkspaceException {
        if (Nd4j.getWorkspaceManager().anyWorkspaceActiveForCurrentThread()) {

            MemoryWorkspace currWs = Nd4j.getMemoryManager().getCurrentWorkspace();
            if(allowScopedOut && (currWs == null || currWs instanceof DummyWorkspace))
                return; //Open WS but we've scoped out

            List<MemoryWorkspace> l = Nd4j.getWorkspaceManager().getAllWorkspacesForCurrentThread();
            List<String> workspaces = new ArrayList<>(l.size());
            for (MemoryWorkspace ws : l) {
                if(ws.isScopeActive()) {
                    workspaces.add(ws.getId());
                }
            }
            throw new ND4JWorkspaceException(msg + " - Open/active workspaces: " + workspaces);
        }
    }
963298
private boolean tryWhitespace() throws SAXException, IOException {
        char c;
        c = readCh();
        if (isWhitespace(c)) {
            skipWhitespace();
            return true;
        } else {
            unread(c);
            return false;
        }
    }
683756
@Override
	public CompletableFuture<Acknowledge> updatePartitions(
			final ExecutionAttemptID executionAttemptID,
			Iterable<PartitionInfo> partitionInfos,
			Time timeout) {
		final Task task = taskSlotTable.getTask(executionAttemptID);

		if (task != null) {
			for (final PartitionInfo partitionInfo: partitionInfos) {
				IntermediateDataSetID intermediateResultPartitionID = partitionInfo.getIntermediateDataSetID();

				final SingleInputGate singleInputGate = task.getInputGateById(intermediateResultPartitionID);

				if (singleInputGate != null) {
					// Run asynchronously because it might be blocking
					getRpcService().execute(
						() -> {
							try {
								singleInputGate.updateInputChannel(partitionInfo.getInputChannelDeploymentDescriptor());
							} catch (IOException | InterruptedException e) {
								log.error("Could not update input data location for task {}. Trying to fail task.", task.getTaskInfo().getTaskName(), e);

								try {
									task.failExternally(e);
								} catch (RuntimeException re) {
									// TODO: Check whether we need this or make exception in failExtenally checked
									log.error("Failed canceling task with execution ID {} after task update failure.", executionAttemptID, re);
								}
							}
						});
				} else {
					return FutureUtils.completedExceptionally(
						new PartitionException("No reader with ID " + intermediateResultPartitionID +
							" for task " + executionAttemptID + " was found."));
				}
			}

			return CompletableFuture.completedFuture(Acknowledge.get());
		} else {
			log.debug("Discard update for input partitions of task {}. Task is no longer running.", executionAttemptID);
			return CompletableFuture.completedFuture(Acknowledge.get());
		}
	}
708814
def check_if_exists(self):
        """"""
        if self.req is None:
            return False
        try:
            self.satisfied_by = pkg_resources.get_distribution(self.req)
        except pkg_resources.DistributionNotFound:
            return False
        except pkg_resources.VersionConflict:
            self.conflicts_with = pkg_resources.get_distribution(self.req.project_name)
        return True