idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
22,000 | public void setAttribute ( String name , String value ) { if ( value != null ) getElement ( ) . setAttribute ( name , value ) ; else getElement ( ) . removeAttribute ( name ) ; } | Helper method to set the value of an attribute on this Element | 44 | 12 |
22,001 | protected Element getElement ( String name , int index ) { List < Element > children = getElement ( ) . getChildren ( name ) ; if ( children . size ( ) > index ) return children . get ( index ) ; else return null ; } | Helper method to retrieve a child element with a particular name and index | 52 | 13 |
22,002 | private static @ NotNull TimeUnit pickUnit ( final @ NotNull Duration iso ) { final long millis = iso . toMillis ( ) ; // Special-case values under 1 second if ( millis < 1000 ) return TimeUnit . MILLISECONDS ; final long SECOND = 1000 ; final long MINUTE = 60 * SECOND ; final long HOUR = 60 * MINUTE ; final long DAY = 24 * HOUR ; if ( millis % DAY == 0 ) return TimeUnit . DAYS ; else if ( millis % HOUR == 0 ) return TimeUnit . HOURS ; else if ( millis % MINUTE == 0 ) return TimeUnit . MINUTES ; else if ( millis % SECOND == 0 ) return TimeUnit . SECONDS ; else return TimeUnit . MILLISECONDS ; } | Identify the largest unit that can accurately represent the provided duration | 176 | 12 |
22,003 | @ SuppressWarnings ( "unchecked" ) public Iterator < T > iterator ( ) { final List < T > services = new ArrayList < T > ( ) ; if ( m_serviceTracker != null ) { final Object [ ] trackedServices = m_serviceTracker . getServices ( ) ; if ( trackedServices != null ) { for ( Object trackedService : trackedServices ) { services . add ( ( T ) trackedService ) ; } } } return Collections . unmodifiableCollection ( services ) . iterator ( ) ; } | Returns an iterator over the tracked services at the call point in time . Note that a susequent call can produce a different list of services as the services are dynamic . If there are no services available returns an empty iterator . | 113 | 44 |
22,004 | public < T > T get ( Class < T > clazz , final String name ) { JAXBNamedResourceFactory < T > cached = cachedReferences . get ( name ) ; if ( cached == null ) { cached = new JAXBNamedResourceFactory < T > ( this . config , this . factory , name , clazz ) ; cachedReferences . put ( name , cached ) ; } return cached . get ( ) ; } | Resolve the JAXB resource permitting caching behind the scenes | 91 | 12 |
22,005 | public < T > T getOnce ( final Class < T > clazz , final String name ) { return new JAXBNamedResourceFactory < T > ( this . config , this . factory , name , clazz ) . get ( ) ; } | Resolve the JAXB resource once without caching anything | 52 | 11 |
22,006 | public static String pretty ( final Source source ) { StreamResult result = new StreamResult ( new StringWriter ( ) ) ; pretty ( source , result ) ; return result . getWriter ( ) . toString ( ) ; } | Serialise the provided source to a pretty - printed String with the default indent settings | 46 | 16 |
22,007 | public static void pretty ( final Source input , final StreamResult output ) { try { // Configure transformer Transformer transformer = TransformerFactory . newInstance ( ) . newTransformer ( ) ; transformer . setOutputProperty ( OutputKeys . ENCODING , "utf-8" ) ; transformer . setOutputProperty ( OutputKeys . OMIT_XML_DECLARATION , "no" ) ; transformer . setOutputProperty ( OutputKeys . INDENT , "yes" ) ; transformer . setOutputProperty ( "{http://xml.apache.org/xslt}indent-amount" , Integer . toString ( DEFAULT_INDENT ) ) ; transformer . transform ( input , output ) ; } catch ( Throwable t ) { throw new RuntimeException ( "Error during pretty-print operation" , t ) ; } } | Serialise the provided source to the provided destination pretty - printing with the default indent settings | 176 | 17 |
22,008 | @ Override public void process ( Writer writer ) { try { template . process ( data , writer ) ; } catch ( IOException e ) { throw new RuntimeException ( "Error writing template to writer" , e ) ; } catch ( TemplateException e ) { throw new RuntimeException ( e . getMessage ( ) , e ) ; } } | Render the template to a Writer | 71 | 6 |
22,009 | private void storeWithSubscribers ( final List < LogLineTableEntity > lines ) { synchronized ( subscribers ) { if ( subscribers . isEmpty ( ) ) return ; // No subscribers, ignore call for ( LogSubscriber subscriber : subscribers ) { subscriber . append ( lines ) ; } if ( System . currentTimeMillis ( ) > nextSubscriberPurge ) { purgeIdleSubscribers ( ) ; nextSubscriberPurge = System . currentTimeMillis ( ) + purgeSubscriberInterval . getMilliseconds ( ) ; } } } | Makes the provided log lines available to all log tail subscribers | 121 | 12 |
22,010 | @ Provides @ SessionScoped public UserLogin getLogin ( @ Named ( JAXRS_SERVER_WEBAUTH_PROVIDER ) CurrentUser user ) { return ( UserLogin ) user ; } | Auto - cast the user manager s CurrentUser to a UserLogin | 42 | 13 |
22,011 | public final IPluginInterface getPlugin ( final String name ) throws UnknownPluginException { PluginDefinition pluginDef = pluginsDefinitionsMap . get ( name ) ; if ( pluginDef == null ) { throw new UnknownPluginException ( name ) ; } try { IPluginInterface pluginInterface = pluginDef . getPluginInterface ( ) ; if ( pluginInterface == null ) { pluginInterface = pluginDef . getPluginClass ( ) . newInstance ( ) ; } return new PluginProxy ( pluginInterface , pluginDef ) ; } catch ( Exception e ) { // FIXME : handle this exception e . printStackTrace ( ) ; } return null ; } | Returns the implementation of the plugin identified by the given name . | 133 | 12 |
22,012 | public static org . w3c . dom . Element convert ( org . jdom2 . Element node ) throws JDOMException { if ( node == null ) return null ; // Convert null->null try { DOMOutputter outputter = new DOMOutputter ( ) ; return outputter . output ( node ) ; } catch ( JDOMException e ) { throw new RuntimeException ( "Error converting JDOM to DOM: " + e . getMessage ( ) , e ) ; } } | Convert a JDOM Element to a DOM Element | 101 | 10 |
22,013 | public static org . jdom2 . Element convert ( org . w3c . dom . Element node ) { if ( node == null ) return null ; // Convert null->null DOMBuilder builder = new DOMBuilder ( ) ; return builder . build ( node ) ; } | Convert a DOM Element to a JDOM Element | 56 | 10 |
22,014 | public static synchronized void register ( Class < ? > clazz , boolean indexable ) { if ( ! resources . containsKey ( clazz ) ) { resources . put ( clazz , new RestResource ( clazz ) ) ; // Optionally register this service as Indexable if ( indexable ) { IndexableServiceRegistry . register ( clazz ) ; } revision ++ ; } } | Register a new resource - N . B . currently this resource cannot be safely unregistered without restarting the webapp | 80 | 23 |
22,015 | public void validate ( final Node document ) throws SchemaValidationException { try { final Validator validator = schema . newValidator ( ) ; validator . validate ( new DOMSource ( document ) ) ; } catch ( SAXException | IOException e ) { throw new SchemaValidationException ( e . getMessage ( ) , e ) ; } } | Validate some XML against this schema | 76 | 7 |
22,016 | @ Override public String parse ( final String threshold , final RangeConfig tc ) { tc . setNegativeInfinity ( true ) ; if ( threshold . startsWith ( INFINITY ) ) { return threshold . substring ( INFINITY . length ( ) ) ; } else { return threshold . substring ( NEG_INFINITY . length ( ) ) ; } } | Parses the threshold to remove the matched - inf or inf string . | 79 | 15 |
22,017 | @ SuppressWarnings ( "rawtypes" ) private static void inject ( final Class c , final IPluginInterface plugin , final IJNRPEExecutionContext context ) throws IllegalAccessException { final Field [ ] fields = c . getDeclaredFields ( ) ; for ( final Field f : fields ) { final Annotation an = f . getAnnotation ( Inject . class ) ; if ( an != null ) { final boolean isAccessible = f . isAccessible ( ) ; if ( ! isAccessible ) { // Change accessible flag if necessary f . setAccessible ( true ) ; } f . set ( plugin , context ) ; if ( ! isAccessible ) { // Restore accessible flag if necessary f . setAccessible ( false ) ; } } } } | Perform the real injection . | 165 | 6 |
22,018 | @ SuppressWarnings ( "rawtypes" ) public static void inject ( final IPluginInterface plugin , final IJNRPEExecutionContext context ) { try { Class clazz = plugin . getClass ( ) ; inject ( clazz , plugin , context ) ; while ( IPluginInterface . class . isAssignableFrom ( clazz . getSuperclass ( ) ) ) { clazz = clazz . getSuperclass ( ) ; inject ( clazz , plugin , context ) ; } } catch ( Exception e ) { throw new Error ( e . getMessage ( ) , e ) ; } } | Inject JNRPE code inside the passed in plugin . The annotation is searched in the whole hierarchy . | 128 | 21 |
22,019 | @ Override public String parse ( final String threshold , final RangeConfig tc ) throws RangeException { StringBuilder numberString = new StringBuilder ( ) ; for ( int i = 0 ; i < threshold . length ( ) ; i ++ ) { if ( Character . isDigit ( threshold . charAt ( i ) ) ) { numberString . append ( threshold . charAt ( i ) ) ; continue ; } if ( threshold . charAt ( i ) == ' ' ) { if ( numberString . toString ( ) . endsWith ( "." ) ) { numberString . deleteCharAt ( numberString . length ( ) - 1 ) ; break ; } else { numberString . append ( threshold . charAt ( i ) ) ; continue ; } } if ( threshold . charAt ( i ) == ' ' || threshold . charAt ( i ) == ' ' ) { if ( numberString . length ( ) == 0 ) { numberString . append ( threshold . charAt ( i ) ) ; continue ; } else { throw new RangeException ( "Unexpected '" + threshold . charAt ( i ) + "' sign parsing boundary" ) ; } } // throw new InvalidRangeSyntaxException(this, // threshold.substring(numberString.length())); break ; } if ( numberString . length ( ) != 0 && ! justSign ( numberString . toString ( ) ) ) { BigDecimal bd = new BigDecimal ( numberString . toString ( ) ) ; setBoundary ( tc , bd ) ; return threshold . substring ( numberString . length ( ) ) ; } else { throw new InvalidRangeSyntaxException ( this , threshold ) ; } } | Parses the threshold to remove the matched number string . | 354 | 12 |
22,020 | public boolean assessMatch ( final OgnlContext ognlContext ) throws OgnlException { if ( ! inputRun ) { throw new IllegalArgumentException ( "Attempted to match on a rule whose rulesets input has not yet been produced" ) ; } final Object result = condition . run ( ognlContext , ognlContext ) ; if ( result == null || ! Boolean . class . isAssignableFrom ( result . getClass ( ) ) ) { throw new IllegalArgumentException ( "Expression " + condition . getOriginalExpression ( ) + " did not return a boolean value" ) ; } matches = ( Boolean ) result ; return matches ; } | returns true if the rules condition holds should not be called until after the rule sets input has been produced | 144 | 21 |
22,021 | public static KeyStore loadCertificates ( final File pemFile ) { try ( final PemReader pem = new PemReader ( new FileReader ( pemFile ) ) ) { final KeyStore ks = createEmptyKeyStore ( ) ; int certIndex = 0 ; Object obj ; while ( ( obj = parse ( pem . readPemObject ( ) ) ) != null ) { if ( obj instanceof Certificate ) { final Certificate cert = ( Certificate ) obj ; ks . setCertificateEntry ( "cert" + Integer . toString ( certIndex ++ ) , cert ) ; } else { throw new RuntimeException ( "Unknown PEM contents: " + obj + ". Expected a Certificate" ) ; } } return ks ; } catch ( Exception e ) { throw new RuntimeException ( "Error parsing PEM " + pemFile , e ) ; } } | Load one or more X . 509 Certificates from a PEM file | 187 | 16 |
22,022 | public T get ( ) { T value = get ( null ) ; if ( value == null ) throw new RuntimeException ( "Missing property for JAXB resource: " + name ) ; else return value ; } | Resolve this property reference to a deserialised JAXB value | 44 | 14 |
22,023 | private T loadResourceValue ( final URL resource ) { try ( final InputStream is = resource . openStream ( ) ) { cached = null ; // Prevent the old value from being used return setCached ( clazz . cast ( factory . getInstance ( clazz ) . deserialise ( is ) ) ) ; } catch ( IOException e ) { throw new RuntimeException ( "Error loading JAXB resource " + name + " " + clazz + " from " + resource , e ) ; } } | Load from a classpath resource ; reloads every time | 107 | 11 |
22,024 | private void analyze ( final List < Metric > metrics , final long elapsed , final Date now , final Date date ) { long diff = 0 ; boolean behind = false ; if ( now . before ( date ) ) { behind = true ; diff = date . getTime ( ) - now . getTime ( ) ; } else if ( now . after ( date ) ) { diff = now . getTime ( ) - date . getTime ( ) ; } Elapsed elapsedTime = new Elapsed ( diff , TimeUnit . MILLISECOND ) ; String msg = getMessage ( elapsedTime ) ; if ( diff > TimeUnit . SECOND . convert ( 1 ) ) { if ( behind ) { msg += "behind" ; } else { msg += "ahead" ; } } metrics . add ( new Metric ( "offset" , msg , new BigDecimal ( TimeUnit . MILLISECOND . convert ( diff , TimeUnit . SECOND ) ) , null , null ) ) ; metrics . add ( new Metric ( "time" , "" , new BigDecimal ( TimeUnit . MILLISECOND . convert ( elapsed , TimeUnit . SECOND ) ) , null , null ) ) ; } | Analizes the data and produces the metrics . | 253 | 10 |
22,025 | @ Override public String parse ( final String threshold , final RangeConfig tc ) { tc . setPositiveInfinity ( true ) ; if ( threshold . startsWith ( INFINITY ) ) { return threshold . substring ( INFINITY . length ( ) ) ; } else { return threshold . substring ( POS_INFINITY . length ( ) ) ; } } | Parses the threshold to remove the matched inf or + inf string . | 78 | 15 |
22,026 | public static String sha1hmac ( String key , String plaintext ) { return sha1hmac ( key , plaintext , ENCODE_HEX ) ; } | Performs HMAC - SHA1 on the UTF - 8 byte representation of strings | 38 | 16 |
22,027 | public static String sha1hmac ( String key , String plaintext , int encoding ) { byte [ ] signature = sha1hmac ( key . getBytes ( ) , plaintext . getBytes ( ) ) ; return encode ( signature , encoding ) ; } | Performs HMAC - SHA1 on the UTF - 8 byte representation of strings returning the hexidecimal hash as a result | 56 | 26 |
22,028 | private void register ( final Bundle bundle ) { LOG . debug ( "Scanning bundle [" + bundle . getSymbolicName ( ) + "]" ) ; final List < T > resources = m_scanner . scan ( bundle ) ; m_mappings . put ( bundle , resources ) ; if ( resources != null && resources . size ( ) > 0 ) { LOG . debug ( "Found resources " + resources ) ; for ( final BundleObserver < T > observer : m_observers ) { try { //here the executor service completes the job in an extra thread. executorService . submit ( new Runnable ( ) { public void run ( ) { try { observer . addingEntries ( bundle , Collections . unmodifiableList ( resources ) ) ; } catch ( Throwable t ) { LOG . error ( "Exception in executor thread" , t ) ; } } } ) ; } catch ( Throwable ignore ) { LOG . error ( "Ignored exception during register" , ignore ) ; } } } } | Scans entries using the bundle scanner and registers the result of scanning process . Then notify the observers . If an exception appears during notification it is ignored . | 218 | 30 |
22,029 | private void unregister ( final Bundle bundle ) { if ( bundle == null ) return ; // no need to go any further, system probably stopped. LOG . debug ( "Releasing bundle [" + bundle . getSymbolicName ( ) + "]" ) ; final List < T > resources = m_mappings . get ( bundle ) ; if ( resources != null && resources . size ( ) > 0 ) { LOG . debug ( "Un-registering " + resources ) ; for ( BundleObserver < T > observer : m_observers ) { try { observer . removingEntries ( bundle , Collections . unmodifiableList ( resources ) ) ; } catch ( Throwable ignore ) { LOG . error ( "Ignored exception during un-register" , ignore ) ; } } } m_mappings . remove ( bundle ) ; } | Un - registers each entry from the unregistered bundle by first notifying the observers . If an exception appears during notification it is ignored . | 177 | 27 |
22,030 | public static void verifyChain ( List < X509Certificate > chain ) { if ( chain == null || chain . isEmpty ( ) ) throw new IllegalArgumentException ( "Must provide a chain that is non-null and non-empty" ) ; for ( int i = 0 ; i < chain . size ( ) ; i ++ ) { final X509Certificate certificate = chain . get ( i ) ; final int issuerIndex = ( i != 0 ) ? i - 1 : 0 ; // The index of the issuer is the previous cert (& the root must, of course, sign itself) final X509Certificate issuer = chain . get ( issuerIndex ) ; // Verify the certificate was indeed issued by the previous certificate in the chain try { certificate . verify ( issuer . getPublicKey ( ) ) ; } catch ( GeneralSecurityException e ) { final String msg = "Failure verifying " + certificate + " against claimed issuer " + issuer ; throw new IllegalArgumentException ( msg + ": " + e . getMessage ( ) , e ) ; } } } | Verifies that a certificate chain is valid | 222 | 8 |
22,031 | public static void main ( String args [ ] ) { String home = "/home/user1/content/myfolder" ; String file = "/home/user1/figures/fig.png" ; System . out . println ( "home = " + home ) ; System . out . println ( "file = " + file ) ; System . out . println ( "path = " + getRelativePath ( new File ( home ) , new File ( file ) ) ) ; } | test the function | 102 | 3 |
22,032 | private InjectingEntityResolver createEntityResolver ( EntityResolver resolver ) { if ( getEntities ( ) != null ) { return new InjectingEntityResolver ( getEntities ( ) , resolver , getType ( ) , getLog ( ) ) ; } else { return null ; } } | Creates an XML entity resolver . | 67 | 8 |
22,033 | protected URL getNonDefaultStylesheetURL ( ) { if ( getNonDefaultStylesheetLocation ( ) != null ) { URL url = this . getClass ( ) . getClassLoader ( ) . getResource ( getNonDefaultStylesheetLocation ( ) ) ; return url ; } else { return null ; } } | Returns the URL of the default stylesheet . | 68 | 9 |
22,034 | private String [ ] scanIncludedFiles ( ) { final DirectoryScanner scanner = new DirectoryScanner ( ) ; scanner . setBasedir ( sourceDirectory ) ; scanner . setIncludes ( new String [ ] { inputFilename } ) ; scanner . scan ( ) ; return scanner . getIncludedFiles ( ) ; } | Returns the list of docbook files to include . | 66 | 10 |
22,035 | void setHTTPResponse ( HTTPResponse resp ) { lock . lock ( ) ; try { if ( response != null ) { throw ( new IllegalStateException ( "HTTPResponse was already set" ) ) ; } response = resp ; ready . signalAll ( ) ; } finally { lock . unlock ( ) ; } } | Set the HTTPResponse instance . | 74 | 9 |
22,036 | HTTPResponse getHTTPResponse ( ) { lock . lock ( ) ; try { while ( response == null ) { try { ready . await ( ) ; } catch ( InterruptedException intx ) { LOG . log ( Level . FINEST , "Interrupted" , intx ) ; } } return response ; } finally { lock . unlock ( ) ; } } | Get the HTTPResponse instance . | 81 | 9 |
22,037 | private static List < String > loadServicesImplementations ( final Class < ? > ofClass ) { List < String > result = new ArrayList < String > ( ) ; // Allow a sysprop to specify the first candidate String override = System . getProperty ( ofClass . getName ( ) ) ; if ( override != null ) { result . add ( override ) ; } ClassLoader loader = ServiceLib . class . getClassLoader ( ) ; URL url = loader . getResource ( "org.igniterealtime.jbosh/" + ofClass . getName ( ) ) ; if ( url == null ) { // Early-out return result ; } InputStream inStream = null ; InputStreamReader reader = null ; BufferedReader bReader = null ; try { inStream = url . openStream ( ) ; reader = new InputStreamReader ( inStream ) ; bReader = new BufferedReader ( reader ) ; String line ; while ( ( line = bReader . readLine ( ) ) != null ) { if ( ! line . matches ( "\\s*(#.*)?" ) ) { // not a comment or blank line result . add ( line . trim ( ) ) ; } } } catch ( IOException iox ) { LOG . log ( Level . WARNING , "Could not load services descriptor: " + url . toString ( ) , iox ) ; } finally { finalClose ( bReader ) ; finalClose ( reader ) ; finalClose ( inStream ) ; } return result ; } | Generates a list of implementation class names by using the Jar SPI technique . The order in which the class names occur in the service manifest is significant . | 319 | 30 |
22,038 | private static < T > T attemptLoad ( final Class < T > ofClass , final String className ) { if ( LOG . isLoggable ( Level . FINEST ) ) { LOG . finest ( "Attempting service load: " + className ) ; } Level level ; Throwable thrown ; try { Class < ? > clazz = Class . forName ( className ) ; if ( ! ofClass . isAssignableFrom ( clazz ) ) { if ( LOG . isLoggable ( Level . WARNING ) ) { LOG . warning ( clazz . getName ( ) + " is not assignable to " + ofClass . getName ( ) ) ; } return null ; } return ofClass . cast ( clazz . newInstance ( ) ) ; } catch ( LinkageError ex ) { level = Level . FINEST ; thrown = ex ; } catch ( ClassNotFoundException ex ) { level = Level . FINEST ; thrown = ex ; } catch ( InstantiationException ex ) { level = Level . WARNING ; thrown = ex ; } catch ( IllegalAccessException ex ) { level = Level . WARNING ; thrown = ex ; } LOG . log ( level , "Could not load " + ofClass . getSimpleName ( ) + " instance: " + className , thrown ) ; return null ; } | Attempts to load the specified implementation class . Attempts will fail if - for example - the implementation depends on a class not found on the classpath . | 278 | 30 |
22,039 | private static void finalClose ( final Closeable closeMe ) { if ( closeMe != null ) { try { closeMe . close ( ) ; } catch ( IOException iox ) { LOG . log ( Level . FINEST , "Could not close: " + closeMe , iox ) ; } } } | Check and close a closeable object trapping and ignoring any exception that might result . | 65 | 16 |
22,040 | public synchronized ConfigurationAgent getConfigurationAgent ( ) { if ( this . configurationAgent == null ) { if ( isService ) { this . configurationAgent = new ConfigurationAgent ( this . serviceName , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version , this . serviceKey ) ; } else { this . configurationAgent = new ConfigurationAgent ( this . username , this . password , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version ) ; } } return this . configurationAgent ; } | Returns a ConfigurationAgent with which requests regarding Configurations can be sent to the NFVO . | 136 | 18 |
22,041 | public synchronized NetworkServiceDescriptorAgent getNetworkServiceDescriptorAgent ( ) { if ( this . networkServiceDescriptorAgent == null ) { if ( isService ) { this . networkServiceDescriptorAgent = new NetworkServiceDescriptorAgent ( this . serviceName , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version , this . serviceKey ) ; } else { this . networkServiceDescriptorAgent = new NetworkServiceDescriptorAgent ( this . username , this . password , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version ) ; } } return this . networkServiceDescriptorAgent ; } | Returns a NetworkServiceDescriptorAgent with which requests regarding NetworkServiceDescriptors can be sent to the NFVO . | 168 | 25 |
22,042 | public synchronized NetworkServiceRecordAgent getNetworkServiceRecordAgent ( ) { if ( this . networkServiceRecordAgent == null ) { if ( isService ) { this . networkServiceRecordAgent = new NetworkServiceRecordAgent ( this . serviceName , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version , this . serviceKey ) ; } else { this . networkServiceRecordAgent = new NetworkServiceRecordAgent ( this . username , this . password , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version ) ; } } return this . networkServiceRecordAgent ; } | Returns a NetworkServiceRecordAgent with which requests regarding NetworkServiceRecords can be sent to the NFVO . | 152 | 22 |
22,043 | public synchronized VimInstanceAgent getVimInstanceAgent ( ) { if ( this . vimInstanceAgent == null ) { if ( isService ) { this . vimInstanceAgent = new VimInstanceAgent ( this . serviceName , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version , this . serviceKey ) ; } else { this . vimInstanceAgent = new VimInstanceAgent ( this . username , this . password , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version ) ; } } return this . vimInstanceAgent ; } | Returns a VimInstanceAgent with which requests regarding VimInstances can be sent to the NFVO . | 145 | 20 |
22,044 | public synchronized VirtualLinkAgent getVirtualLinkAgent ( ) { if ( this . virtualLinkAgent == null ) { if ( isService ) { this . virtualLinkAgent = new VirtualLinkAgent ( this . serviceName , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version , this . serviceKey ) ; } else { this . virtualLinkAgent = new VirtualLinkAgent ( this . username , this . password , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version ) ; } } return this . virtualLinkAgent ; } | Returns a VirtualLinkAgent with which requests regarding VirtualLinks can be sent to the NFVO . | 144 | 19 |
22,045 | public synchronized VirtualNetworkFunctionDescriptorAgent getVirtualNetworkFunctionDescriptorRestAgent ( ) { if ( this . virtualNetworkFunctionDescriptorAgent == null ) { if ( isService ) { this . virtualNetworkFunctionDescriptorAgent = new VirtualNetworkFunctionDescriptorAgent ( this . serviceName , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version , this . serviceKey ) ; } else { this . virtualNetworkFunctionDescriptorAgent = new VirtualNetworkFunctionDescriptorAgent ( this . username , this . password , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version ) ; } } return this . virtualNetworkFunctionDescriptorAgent ; } | Returns a VirtualNetworkFunctionDescriptorAgent with which requests regarding VirtualNetworkFunctionDescriptors can be sent to the NFVO . | 177 | 27 |
22,046 | public synchronized VNFFGAgent getVNFFGAgent ( ) { if ( this . vnffgAgent == null ) { if ( isService ) { this . vnffgAgent = new VNFFGAgent ( this . serviceName , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version , this . serviceKey ) ; } else { this . vnffgAgent = new VNFFGAgent ( this . username , this . password , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version ) ; } } return this . vnffgAgent ; } | Returns a VNFFGAgent with which requests regarding VNFFGAgent can be sent to the NFVO . | 160 | 24 |
22,047 | public synchronized EventAgent getEventAgent ( ) { if ( this . eventAgent == null ) { if ( isService ) { this . eventAgent = new EventAgent ( this . serviceName , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version , this . serviceKey ) ; } else { this . eventAgent = new EventAgent ( this . username , this . password , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version ) ; } } return this . eventAgent ; } | Returns an EventAgent with which requests regarding Events can be sent to the NFVO . | 136 | 17 |
22,048 | public synchronized VNFPackageAgent getVNFPackageAgent ( ) { if ( this . vnfPackageAgent == null ) { if ( isService ) { this . vnfPackageAgent = new VNFPackageAgent ( this . serviceName , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version , this . serviceKey ) ; } else { this . vnfPackageAgent = new VNFPackageAgent ( this . username , this . password , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version ) ; } } return this . vnfPackageAgent ; } | Returns a VNFPackageAgent with which requests regarding VNFPackages can be sent to the NFVO . | 164 | 25 |
22,049 | public synchronized ProjectAgent getProjectAgent ( ) { if ( this . projectAgent == null ) { if ( isService ) { this . projectAgent = new ProjectAgent ( this . serviceName , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version , this . serviceKey ) ; } else { this . projectAgent = new ProjectAgent ( this . username , this . password , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version ) ; } } return this . projectAgent ; } | Returns a ProjectAgent with which requests regarding Projects can be sent to the NFVO . | 136 | 17 |
22,050 | public synchronized UserAgent getUserAgent ( ) { if ( this . userAgent == null ) { if ( isService ) { this . userAgent = new UserAgent ( this . serviceName , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version , this . serviceKey ) ; } else { this . userAgent = new UserAgent ( this . username , this . password , this . projectId , this . sslEnabled , this . nfvoIp , this . nfvoPort , this . version ) ; } } return this . userAgent ; } | Returns a UserAgent with which requests regarding Users can be sent to the NFVO . | 136 | 17 |
22,051 | private String getProjectIdForProjectName ( String projectName ) throws SDKException { String projectId = this . getProjectAgent ( ) . findAll ( ) . stream ( ) . filter ( p -> p . getName ( ) . equals ( projectName ) ) . findFirst ( ) . orElseThrow ( ( ) -> new SDKException ( "Did not find a Project named " + projectName , null , "Did not find a Project named " + projectName ) ) . getId ( ) ; this . projectAgent = null ; return projectId ; } | Return the project id for a given project name . | 117 | 10 |
22,052 | private void resetAgents ( ) { this . configurationAgent = null ; this . keyAgent = null ; this . userAgent = null ; this . vnfPackageAgent = null ; this . projectAgent = null ; this . eventAgent = null ; this . vnffgAgent = null ; this . virtualNetworkFunctionDescriptorAgent = null ; this . virtualLinkAgent = null ; this . vimInstanceAgent = null ; this . networkServiceDescriptorAgent = null ; this . networkServiceRecordAgent = null ; this . serviceAgent = null ; } | Set all the agent objects to null . | 119 | 8 |
22,053 | @ Help ( help = "Get all the VirtualNetworkFunctionDescriptors of a NetworkServiceDescriptor with specific id" ) @ Deprecated public List < VirtualNetworkFunctionDescriptor > getVirtualNetworkFunctionDescriptors ( final String idNSD ) throws SDKException { String url = idNSD + "/vnfdescriptors" ; return Arrays . asList ( ( VirtualNetworkFunctionDescriptor [ ] ) requestGetAll ( url , VirtualNetworkFunctionDescriptor . class ) ) ; } | Get all VirtualNetworkFunctionDescriptors contained in a NetworkServiceDescriptor specified by its ID . | 109 | 21 |
22,054 | @ Help ( help = "Get a specific VirtualNetworkFunctionDescriptor of a particular NetworkServiceDescriptor specified by their IDs" ) @ Deprecated public VirtualNetworkFunctionDescriptor getVirtualNetworkFunctionDescriptor ( final String idNSD , final String idVfn ) throws SDKException { String url = idNSD + "/vnfdescriptors" + "/" + idVfn ; return ( VirtualNetworkFunctionDescriptor ) requestGet ( url , VirtualNetworkFunctionDescriptor . class ) ; } | Return a VirtualNetworkFunctionDescriptor that is contained in a particular NetworkServiceDescriptor . | 111 | 20 |
22,055 | @ Help ( help = "Delete the VirtualNetworkFunctionDescriptor of a NetworkServiceDescriptor with specific id" ) @ Deprecated public void deleteVirtualNetworkFunctionDescriptors ( final String idNSD , final String idVnf ) throws SDKException { String url = idNSD + "/vnfdescriptors" + "/" + idVnf ; requestDelete ( url ) ; } | Delete a specific VirtualNetworkFunctionDescriptor that is contained in a particular NetworkServiceDescriptor . | 87 | 21 |
22,056 | @ Help ( help = "create the VirtualNetworkFunctionDescriptor of a NetworkServiceDescriptor with specific id" ) @ Deprecated public VirtualNetworkFunctionDescriptor createVNFD ( final String idNSD , final VirtualNetworkFunctionDescriptor virtualNetworkFunctionDescriptor ) throws SDKException { String url = idNSD + "/vnfdescriptors" + "/" ; return ( VirtualNetworkFunctionDescriptor ) requestPost ( url , virtualNetworkFunctionDescriptor ) ; } | Create a VirtualNetworkFunctionDescriptor in a specific NetworkServiceDescriptor . | 107 | 17 |
22,057 | @ Help ( help = "Update the VirtualNetworkFunctionDescriptor of a NetworkServiceDescriptor with specific id" ) @ Deprecated public VirtualNetworkFunctionDescriptor updateVNFD ( final String idNSD , final String idVfn , final VirtualNetworkFunctionDescriptor virtualNetworkFunctionDescriptor ) throws SDKException { String url = idNSD + "/vnfdescriptors" + "/" + idVfn ; return ( VirtualNetworkFunctionDescriptor ) requestPut ( url , virtualNetworkFunctionDescriptor ) ; } | Update a specific VirtualNetworkFunctionDescriptor that is contained in a particular NetworkServiceDescriptor . | 117 | 21 |
22,058 | @ Help ( help = "Get all the VirtualNetworkFunctionDescriptor Dependency of a NetworkServiceDescriptor with specific id" ) public List < VNFDependency > getVNFDependencies ( final String idNSD ) throws SDKException { String url = idNSD + "/vnfdependencies" ; return Arrays . asList ( ( VNFDependency [ ] ) requestGetAll ( url , VNFDependency . class ) ) ; } | Return a List with all the VNFDependencies that are contained in a specific NetworkServiceDescriptor . | 103 | 23 |
22,059 | @ Help ( help = "get the VirtualNetworkFunctionDescriptor dependency with specific id of a NetworkServiceDescriptor with specific id" ) public VNFDependency getVNFDependency ( final String idNSD , final String idVnfd ) throws SDKException { String url = idNSD + "/vnfdependencies" + "/" + idVnfd ; return ( VNFDependency ) requestGet ( url , VNFDependency . class ) ; } | Return a specific VNFDependency that is contained in a particular NetworkServiceDescriptor . | 106 | 20 |
22,060 | @ Help ( help = "Delete the VirtualNetworkFunctionDescriptor dependency of a NetworkServiceDescriptor with specific id" ) public void deleteVNFDependency ( final String idNSD , final String idVnfd ) throws SDKException { String url = idNSD + "/vnfdependencies" + "/" + idVnfd ; requestDelete ( url ) ; } | Delete a VNFDependency . | 83 | 8 |
22,061 | @ Help ( help = "Create the VirtualNetworkFunctionDescriptor dependency of a NetworkServiceDescriptor with specific id" ) public VNFDependency createVNFDependency ( final String idNSD , final VNFDependency vnfDependency ) throws SDKException { String url = idNSD + "/vnfdependencies" + "/" ; return ( VNFDependency ) requestPost ( url , vnfDependency ) ; } | Add a new VNFDependency to a specific NetworkServiceDescriptor . | 103 | 17 |
22,062 | @ Help ( help = "Update the VirtualNetworkFunctionDescriptor dependency of a NetworkServiceDescriptor with specific id" ) public VNFDependency updateVNFD ( final String idNSD , final String idVnfDep , final VNFDependency vnfDependency ) throws SDKException { String url = idNSD + "/vnfdependencies" + "/" + idVnfDep ; return ( VNFDependency ) requestPut ( url , vnfDependency ) ; } | Update a specific VNFDependency which is contained in a particular NetworkServiceDescriptor . | 115 | 20 |
22,063 | @ Help ( help = "Get all the PhysicalNetworkFunctionDescriptors of a NetworkServiceDescriptor with specific id" ) public List < PhysicalNetworkFunctionDescriptor > getPhysicalNetworkFunctionDescriptors ( final String idNSD ) throws SDKException { String url = idNSD + "/pnfdescriptors" ; return Arrays . asList ( ( PhysicalNetworkFunctionDescriptor [ ] ) requestGetAll ( url , PhysicalNetworkFunctionDescriptor . class ) ) ; } | Returns the List of PhysicalNetworkFunctionDescriptors that are contained in a specific NetworkServiceDescriptor . | 105 | 22 |
22,064 | @ Help ( help = "Get the PhysicalNetworkFunctionDescriptor with specific id of a NetworkServiceDescriptor with specific id" ) public PhysicalNetworkFunctionDescriptor getPhysicalNetworkFunctionDescriptor ( final String idNsd , final String idPnf ) throws SDKException { String url = idNsd + "/pnfdescriptors" + "/" + idPnf ; return ( PhysicalNetworkFunctionDescriptor ) requestGetWithStatusAccepted ( url , PhysicalNetworkFunctionDescriptor . class ) ; } | Returns a specific PhysicalNetworkFunctionDescriptor that is contained in a particular NetworkServiceDescriptor . | 113 | 21 |
22,065 | @ Help ( help = "Delete the PhysicalNetworkFunctionDescriptor of a NetworkServiceDescriptor with specific id" ) public void deletePhysicalNetworkFunctionDescriptor ( final String idNsd , final String idPnf ) throws SDKException { String url = idNsd + "/pnfdescriptors" + "/" + idPnf ; requestDelete ( url ) ; } | Delete a specific PhysicalNetworkFunctionDescriptor which is contained in a particular NetworkServiceDescriptor . | 83 | 21 |
22,066 | @ Help ( help = "Create the PhysicalNetworkFunctionDescriptor of a NetworkServiceDescriptor with specific id" ) public PhysicalNetworkFunctionDescriptor createPhysicalNetworkFunctionDescriptor ( final String idNsd , final PhysicalNetworkFunctionDescriptor physicalNetworkFunctionDescriptor ) throws SDKException { String url = idNsd + "/pnfdescriptors" ; return ( PhysicalNetworkFunctionDescriptor ) requestPost ( url , physicalNetworkFunctionDescriptor ) ; } | Create a new PhysicalNetworkFunctionDescriptor in a NetworkServiceDescriptor | 103 | 16 |
22,067 | @ Help ( help = "Update the PhysicalNetworkFunctionDescriptor of a NetworkServiceDescriptor with specific id" ) public PhysicalNetworkFunctionDescriptor updatePNFD ( final String idNsd , final String idPnf , final PhysicalNetworkFunctionDescriptor physicalNetworkFunctionDescriptor ) throws SDKException { String url = idNsd + "/pnfdescriptors" + "/" + idPnf ; return ( PhysicalNetworkFunctionDescriptor ) requestPut ( url , physicalNetworkFunctionDescriptor ) ; } | Update a PhysicalNetworkFunctionDescriptor . | 114 | 9 |
22,068 | @ Help ( help = "Get all the Security of a NetworkServiceDescriptor with specific id" ) public Security getSecurities ( final String idNsd ) throws SDKException { String url = idNsd + "/security" ; return ( ( Security ) requestGet ( url , Security . class ) ) ; } | Returns a List of all Security objects that are contained in a specific NetworkServiceDescriptor . | 66 | 19 |
22,069 | @ Help ( help = "Delete the Security of a NetworkServiceDescriptor with specific id" ) public void deleteSecurity ( final String idNsd , final String idSecurity ) throws SDKException { String url = idNsd + "/security" + "/" + idSecurity ; requestDelete ( url ) ; } | Delete a Security object . | 65 | 5 |
22,070 | @ Help ( help = "Create the Security of a NetworkServiceDescriptor with specific id" ) public Security createSecurity ( final String idNSD , final Security security ) throws SDKException { String url = idNSD + "/security" + "/" ; return ( Security ) requestPost ( url , security ) ; } | Add a new Security object to a NetworkServiceDescriptor . | 67 | 13 |
22,071 | @ Help ( help = "Update the Security of a NetworkServiceDescriptor with specific id" ) public Security updateSecurity ( final String idNSD , final String idSecurity , final Security updatedSecurity ) throws SDKException { String url = idNSD + "/security" + "/" + idSecurity ; return ( Security ) requestPut ( url , updatedSecurity ) ; } | Update a Security object of a specific NetworkServiceDescriptor . | 77 | 13 |
22,072 | private static SAXParser getSAXParser ( ) { SoftReference < SAXParser > ref = PARSER . get ( ) ; SAXParser result = ref . get ( ) ; if ( result == null ) { Exception thrown ; try { result = SAX_FACTORY . newSAXParser ( ) ; ref = new SoftReference < SAXParser > ( result ) ; PARSER . set ( ref ) ; return result ; } catch ( ParserConfigurationException ex ) { thrown = ex ; } catch ( SAXException ex ) { thrown = ex ; } throw ( new IllegalStateException ( "Could not create SAX parser" , thrown ) ) ; } else { result . reset ( ) ; return result ; } } | Gets a SAXParser for use in parsing incoming messages . | 156 | 13 |
22,073 | protected String resolveResourceContextPath ( HttpServletRequest request , String resource ) { final String resourceContextPath = this . getResourceServerContextPath ( ) ; this . logger . debug ( "Attempting to locate resource serving webapp with context path: {}" , resourceContextPath ) ; //Try to resolve the final ServletContext resourceContext = this . servletContext . getContext ( resourceContextPath ) ; if ( resourceContext == null || ! resourceContextPath . equals ( resourceContext . getContextPath ( ) ) ) { this . logger . warn ( "Could not find resource serving webapp under context path {} ensure the resource server is deployed and cross context dispatching is enable for this web application" , resourceContextPath ) ; return request . getContextPath ( ) ; } this . logger . debug ( "Found resource serving webapp at: {}" , resourceContextPath ) ; URL url = null ; try { url = resourceContext . getResource ( resource ) ; } catch ( MalformedURLException e ) { //Ignore } if ( url == null ) { this . logger . debug ( "Resource serving webapp {} doesn't contain resource {} Falling back to the local resource." , resourceContextPath , resource ) ; return request . getContextPath ( ) ; } this . logger . debug ( "Resource serving webapp {} contains resource {} Using resource server." , resourceContextPath , resource ) ; return resourceContextPath ; } | If the resource serving servlet context is available and the resource is available in the context create a URL to the resource in that context . If not create a local URL for the requested resource . | 302 | 38 |
22,074 | protected String getResourceServerContextPath ( ) { final String resourceContextPath = this . servletContext . getInitParameter ( RESOURCE_CONTEXT_INIT_PARAM ) ; if ( resourceContextPath == null ) { // if no resource context path was defined in the web.xml, use the // default return DEFAULT_RESOURCE_CONTEXT ; } if ( ! resourceContextPath . startsWith ( "/" ) ) { // ensure that our context starts with a slash return "/" . concat ( resourceContextPath ) ; } return resourceContextPath ; } | Determine the context name of the resource serving webapp | 120 | 12 |
22,075 | private static TerminalBindingCondition create ( final String condition , final String message ) { return createWithCode ( condition , message , null ) ; } | Helper method to call the helper method to add entries . | 30 | 11 |
22,076 | private static TerminalBindingCondition createWithCode ( final String condition , final String message , final Integer code ) { if ( condition == null ) { throw ( new IllegalArgumentException ( "condition may not be null" ) ) ; } if ( message == null ) { throw ( new IllegalArgumentException ( "message may not be null" ) ) ; } if ( COND_TO_INSTANCE . get ( condition ) != null ) { throw ( new IllegalStateException ( "Multiple definitions of condition: " + condition ) ) ; } TerminalBindingCondition result = new TerminalBindingCondition ( condition , message ) ; COND_TO_INSTANCE . put ( condition , result ) ; if ( code != null ) { if ( CODE_TO_INSTANCE . get ( code ) != null ) { throw ( new IllegalStateException ( "Multiple definitions of code: " + code ) ) ; } CODE_TO_INSTANCE . put ( code , result ) ; } return result ; } | Helper method to add entries . | 208 | 6 |
22,077 | @ Help ( help = "Creates a new service" ) public String create ( String serviceName , List < String > roles ) throws SDKException { HashMap < String , Object > requestBody = new HashMap <> ( ) ; requestBody . put ( "name" , serviceName ) ; requestBody . put ( "roles" , roles ) ; return new String ( ( byte [ ] ) requestPost ( "create" , requestBody , MediaType . APPLICATION_OCTET_STREAM_VALUE , MediaType . APPLICATION_JSON_VALUE ) ) ; } | Creates a new service . | 122 | 6 |
22,078 | public static String getVersion ( String path , Class < ? > klass ) { try { final InputStream in = klass . getClassLoader ( ) . getResourceAsStream ( path ) ; if ( in != null ) { try { final BufferedReader reader = new BufferedReader ( new InputStreamReader ( in ) ) ; String line = reader . readLine ( ) ; while ( line != null ) { if ( line . startsWith ( "version" ) ) { return line . split ( "=" ) [ 1 ] ; } line = reader . readLine ( ) ; } } finally { in . close ( ) ; } } } catch ( IOException e ) { LOG . error ( "Could not read package version using path " + path + ":" , e ) ; } return "unknown" ; } | Attempts to get a version property from a specified resource | 171 | 10 |
22,079 | public static BodyQName create ( final String uri , final String local ) { return createWithPrefix ( uri , local , null ) ; } | Creates a new qualified name using a namespace URI and local name . | 32 | 14 |
22,080 | public static BodyQName createWithPrefix ( final String uri , final String local , final String prefix ) { if ( uri == null || uri . length ( ) == 0 ) { throw ( new IllegalArgumentException ( "URI is required and may not be null/empty" ) ) ; } if ( local == null || local . length ( ) == 0 ) { throw ( new IllegalArgumentException ( "Local arg is required and may not be null/empty" ) ) ; } if ( prefix == null || prefix . length ( ) == 0 ) { return new BodyQName ( new QName ( uri , local ) ) ; } else { return new BodyQName ( new QName ( uri , local , prefix ) ) ; } } | Creates a new qualified name using a namespace URI and local name along with an optional prefix . | 161 | 19 |
22,081 | public static boolean methodsAreEqual ( Method m1 , Method m2 ) { if ( ! m1 . getName ( ) . equals ( m2 . getName ( ) ) ) return false ; if ( ! m1 . getReturnType ( ) . equals ( m2 . getReturnType ( ) ) ) return false ; if ( ! Objects . deepEquals ( m1 . getParameterTypes ( ) , m2 . getParameterTypes ( ) ) ) return false ; return true ; } | Returns true if the two passed methods are equal . Methods are in this case regarded as equal if they take the same parameter types return the same return type and share the same name . | 104 | 36 |
22,082 | @ Help ( help = "Create the object of type {#}" ) public T create ( final T object ) throws SDKException { return ( T ) requestPost ( object ) ; } | Sends a request for creating an instance of type T to the NFVO API . | 38 | 17 |
22,083 | @ Help ( help = "Find all the objects of type {#}" ) public List < T > findAll ( ) throws SDKException { return Arrays . asList ( ( T [ ] ) requestGet ( null , clazz ) ) ; } | Sends a request for finding all instances of type T to the NFVO API . | 52 | 17 |
22,084 | @ Help ( help = "Find the object of type {#} through the id" ) public T findById ( final String id ) throws SDKException { return ( T ) requestGet ( id , clazz ) ; } | Sends a request to the NFVO API for finding an instance of type T specified by it s ID . | 46 | 22 |
22,085 | @ Help ( help = "Update the object of type {#} passing the new object and the id of the old object" ) public T update ( final T object , final String id ) throws SDKException { return ( T ) requestPut ( id , object ) ; } | Sends a request to the NFVO API for updating an instance of type T specified by its ID . | 56 | 21 |
22,086 | public String requestPost ( final String id ) throws SDKException { CloseableHttpResponse response = null ; HttpPost httpPost = null ; checkToken ( ) ; try { log . debug ( "pathUrl: " + pathUrl ) ; log . debug ( "id: " + pathUrl + "/" + id ) ; // call the api here log . debug ( "Executing post on: " + this . pathUrl + "/" + id ) ; httpPost = new HttpPost ( this . pathUrl + "/" + id ) ; preparePostHeader ( httpPost , "application/json" , "application/json" ) ; response = httpClient . execute ( httpPost ) ; // check response status RestUtils . checkStatus ( response , HttpURLConnection . HTTP_CREATED ) ; // return the response of the request String result = "" ; if ( response . getEntity ( ) != null ) { result = EntityUtils . toString ( response . getEntity ( ) ) ; } closeResponseObject ( response ) ; log . trace ( "received: " + result ) ; httpPost . releaseConnection ( ) ; return result ; } catch ( IOException e ) { // catch request exceptions here log . error ( e . getMessage ( ) , e ) ; if ( httpPost != null ) { httpPost . releaseConnection ( ) ; } throw new SDKException ( "Could not http-post or open the object properly" , e . getStackTrace ( ) , "Could not http-post or open the object properly because: " + e . getMessage ( ) ) ; } catch ( SDKException e ) { if ( response . getStatusLine ( ) . getStatusCode ( ) == HttpStatus . SC_UNAUTHORIZED ) { token = null ; if ( httpPost != null ) { httpPost . releaseConnection ( ) ; } return requestPost ( id ) ; } else { if ( httpPost != null ) { httpPost . releaseConnection ( ) ; } try { throw new SDKException ( "Status is " + response . getStatusLine ( ) . getStatusCode ( ) , new StackTraceElement [ 0 ] , EntityUtils . toString ( response . getEntity ( ) ) ) ; } catch ( IOException e1 ) { e1 . printStackTrace ( ) ; throw new SDKException ( "Status is " + response . getStatusLine ( ) . getStatusCode ( ) , new StackTraceElement [ 0 ] , "could not provide reason because: " + e . getMessage ( ) ) ; } } } } | Does the POST Request | 546 | 4 |
22,087 | private void preparePostHeader ( HttpPost httpPost , String acceptMimeType , String contentMimeType ) { if ( acceptMimeType != null && ! acceptMimeType . equals ( "" ) ) { httpPost . setHeader ( new BasicHeader ( "accept" , acceptMimeType ) ) ; } if ( contentMimeType != null && ! contentMimeType . equals ( "" ) ) { httpPost . setHeader ( new BasicHeader ( "Content-Type" , contentMimeType ) ) ; } httpPost . setHeader ( new BasicHeader ( "project-id" , projectId ) ) ; if ( token != null && bearerToken != null ) { httpPost . setHeader ( new BasicHeader ( "authorization" , bearerToken . replaceAll ( "\"" , "" ) ) ) ; } } | Add accept content - type projectId and token headers to an HttpPost object . | 178 | 17 |
22,088 | public VNFPackage requestPostPackage ( final File f ) throws SDKException { CloseableHttpResponse response = null ; HttpPost httpPost = null ; checkToken ( ) ; try { log . debug ( "Executing post on " + pathUrl ) ; httpPost = new HttpPost ( this . pathUrl ) ; preparePostHeader ( httpPost , "application/json" , null ) ; MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder . create ( ) ; multipartEntityBuilder . addBinaryBody ( "file" , f ) ; httpPost . setEntity ( multipartEntityBuilder . build ( ) ) ; response = httpClient . execute ( httpPost ) ; // check response status RestUtils . checkStatus ( response , HttpURLConnection . HTTP_OK ) ; // return the response of the request String result = "" ; if ( response . getEntity ( ) != null ) { try { result = EntityUtils . toString ( response . getEntity ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } int statusCode = response . getStatusLine ( ) . getStatusCode ( ) ; closeResponseObject ( response ) ; httpPost . releaseConnection ( ) ; if ( statusCode != HttpURLConnection . HTTP_NO_CONTENT ) { JsonParser jsonParser = new JsonParser ( ) ; JsonElement jsonElement = jsonParser . parse ( result ) ; result = mapper . toJson ( jsonElement ) ; log . debug ( "Uploaded the VNFPackage" ) ; log . trace ( "received: " + result ) ; log . trace ( "Casting it into: " + VNFPackage . class ) ; return mapper . fromJson ( result , VNFPackage . class ) ; } return null ; } catch ( IOException e ) { httpPost . releaseConnection ( ) ; throw new SDKException ( "Could not create VNFPackage from file " + f . getName ( ) , e . getStackTrace ( ) , e . getMessage ( ) ) ; } catch ( SDKException e ) { if ( response != null && response . getStatusLine ( ) . getStatusCode ( ) == HttpStatus . SC_UNAUTHORIZED ) { token = null ; if ( httpPost != null ) { httpPost . releaseConnection ( ) ; } closeResponseObject ( response ) ; return requestPostPackage ( f ) ; } else { if ( httpPost != null ) { httpPost . releaseConnection ( ) ; } try { throw new SDKException ( "Status is " + response . getStatusLine ( ) . getStatusCode ( ) , new StackTraceElement [ 0 ] , EntityUtils . toString ( response . getEntity ( ) ) ) ; } catch ( IOException e1 ) { e1 . printStackTrace ( ) ; throw new SDKException ( "Status is " + response . getStatusLine ( ) . getStatusCode ( ) , new StackTraceElement [ 0 ] , "could not provide reason because: " + e . getMessage ( ) ) ; } } } } | Used to upload tar files to the NFVO for creating VNFPackages . | 678 | 17 |
22,089 | public void requestDelete ( final String id ) throws SDKException { CloseableHttpResponse response = null ; HttpDelete httpDelete = null ; checkToken ( ) ; try { log . debug ( "pathUrl: " + pathUrl ) ; log . debug ( "id: " + pathUrl + "/" + id ) ; // call the api here log . info ( "Executing delete on: " + this . pathUrl + "/" + id ) ; httpDelete = new HttpDelete ( this . pathUrl + "/" + id ) ; httpDelete . setHeader ( new BasicHeader ( "project-id" , projectId ) ) ; if ( token != null ) { httpDelete . setHeader ( new BasicHeader ( "authorization" , bearerToken . replaceAll ( "\"" , "" ) ) ) ; } response = httpClient . execute ( httpDelete ) ; // check response status RestUtils . checkStatus ( response , HttpURLConnection . HTTP_NO_CONTENT ) ; httpDelete . releaseConnection ( ) ; // return the response of the request } catch ( IOException e ) { // catch request exceptions here log . error ( e . getMessage ( ) , e ) ; if ( httpDelete != null ) { httpDelete . releaseConnection ( ) ; } throw new SDKException ( "Could not http-delete" , e . getStackTrace ( ) , e . getMessage ( ) ) ; } catch ( SDKException e ) { if ( response != null && ( response . getStatusLine ( ) . getStatusCode ( ) == HttpStatus . SC_UNAUTHORIZED ) ) { token = null ; if ( httpDelete != null ) { httpDelete . releaseConnection ( ) ; } requestDelete ( id ) ; return ; } throw new SDKException ( "Could not http-delete or the api response was wrong" , e . getStackTrace ( ) , e . getMessage ( ) ) ; } finally { if ( httpDelete != null ) { httpDelete . releaseConnection ( ) ; } } } | Executes a http delete with to a given id | 432 | 10 |
22,090 | public Object requestGet ( final String id , Class type ) throws SDKException { String url = this . pathUrl ; if ( id != null ) { url += "/" + id ; return requestGetWithStatus ( url , null , type ) ; } else { return requestGetAll ( url , type , null ) ; } } | Executes a http get with to a given id | 68 | 10 |
22,091 | public Serializable requestPut ( final String id , final Serializable object ) throws SDKException { CloseableHttpResponse response = null ; HttpPut httpPut = null ; checkToken ( ) ; try { log . trace ( "Object is: " + object ) ; String fileJSONNode = mapper . toJson ( object ) ; // call the api here log . debug ( "Executing put on: " + this . pathUrl + "/" + id ) ; httpPut = new HttpPut ( this . pathUrl + "/" + id ) ; httpPut . setHeader ( new BasicHeader ( "accept" , "application/json" ) ) ; httpPut . setHeader ( new BasicHeader ( "Content-Type" , "application/json" ) ) ; httpPut . setHeader ( new BasicHeader ( "project-id" , projectId ) ) ; if ( token != null ) { httpPut . setHeader ( new BasicHeader ( "authorization" , bearerToken . replaceAll ( "\"" , "" ) ) ) ; } httpPut . setEntity ( new StringEntity ( fileJSONNode ) ) ; response = httpClient . execute ( httpPut ) ; // check response status RestUtils . checkStatus ( response , HttpURLConnection . HTTP_ACCEPTED ) ; // return the response of the request String result = "" ; if ( response . getEntity ( ) != null ) { result = EntityUtils . toString ( response . getEntity ( ) ) ; } if ( response . getStatusLine ( ) . getStatusCode ( ) != HttpURLConnection . HTTP_NO_CONTENT ) { closeResponseObject ( response ) ; httpPut . releaseConnection ( ) ; JsonParser jsonParser = new JsonParser ( ) ; JsonElement jsonElement = jsonParser . parse ( result ) ; result = mapper . toJson ( jsonElement ) ; log . trace ( "received: " + result ) ; log . trace ( "Casting it into: " + object . getClass ( ) ) ; return mapper . fromJson ( result , object . getClass ( ) ) ; } closeResponseObject ( response ) ; httpPut . releaseConnection ( ) ; return null ; } catch ( IOException e ) { // catch request exceptions here log . error ( e . getMessage ( ) , e ) ; if ( httpPut != null ) { httpPut . releaseConnection ( ) ; } throw new SDKException ( "PUT request failed. Either the request failed or the provided object is incorrect" , e . getStackTrace ( ) , e . getMessage ( ) ) ; } catch ( SDKException e ) { if ( response != null && response . getStatusLine ( ) . getStatusCode ( ) == HttpStatus . SC_UNAUTHORIZED ) { token = null ; if ( httpPut != null ) { httpPut . releaseConnection ( ) ; } return requestPut ( id , object ) ; } else { if ( httpPut != null ) { httpPut . releaseConnection ( ) ; } throw new SDKException ( "PUT request failed" , e . getStackTrace ( ) , e . getMessage ( ) ) ; } } finally { if ( httpPut != null ) { httpPut . releaseConnection ( ) ; } } } | Executes a http put with to a given id while serializing the object content as json and returning the response | 695 | 22 |
22,092 | static BOSHClientConnEvent createConnectionClosedOnErrorEvent ( final BOSHClient source , final List < ComposableBody > outstanding , final Throwable cause ) { return new BOSHClientConnEvent ( source , false , outstanding , cause ) ; } | Creates a connection closed on error event . This represents an unexpected termination of the client session . | 53 | 19 |
22,093 | boolean isAccepted ( final String name ) { for ( String str : charsets ) { if ( str . equalsIgnoreCase ( name ) ) { return true ; } } return false ; } | Determines whether or not the specified charset is supported . | 42 | 13 |
22,094 | private static XmlPullParser getXmlPullParser ( ) { SoftReference < XmlPullParser > ref = XPP_PARSER . get ( ) ; XmlPullParser result = ref . get ( ) ; if ( result == null ) { Exception thrown ; try { XmlPullParserFactory factory = XmlPullParserFactory . newInstance ( ) ; factory . setNamespaceAware ( true ) ; factory . setValidating ( false ) ; result = factory . newPullParser ( ) ; ref = new SoftReference < XmlPullParser > ( result ) ; XPP_PARSER . set ( ref ) ; return result ; } catch ( Exception ex ) { thrown = ex ; } throw ( new IllegalStateException ( "Could not create XmlPull parser" , thrown ) ) ; } else { return result ; } } | Gets a XmlPullParser for use in parsing incoming messages . | 176 | 14 |
22,095 | public static StaticBody fromStream ( final InputStream inStream ) throws BOSHException { ByteArrayOutputStream byteOut = new ByteArrayOutputStream ( ) ; try { byte [ ] buffer = new byte [ BUFFER_SIZE ] ; int read ; do { read = inStream . read ( buffer ) ; if ( read > 0 ) { byteOut . write ( buffer , 0 , read ) ; } } while ( read >= 0 ) ; } catch ( IOException iox ) { throw ( new BOSHException ( "Could not read body data" , iox ) ) ; } return fromString ( byteOut . toString ( ) ) ; } | Creates an instance which is initialized by reading a body message from the provided stream . | 136 | 17 |
22,096 | public static StaticBody fromString ( final String rawXML ) throws BOSHException { BodyParserResults results = PARSER . parse ( rawXML ) ; return new StaticBody ( results . getAttributes ( ) , rawXML ) ; } | Creates an instance which is initialized by reading a body message from the provided raw XML string . | 52 | 19 |
22,097 | @ Help ( help = "Create a VNFPackage by uploading a tar file" ) public VNFPackage create ( String filePath ) throws SDKException { log . debug ( "Start uploading a VNFPackage using the tar at path " + filePath ) ; File f = new File ( filePath ) ; if ( f == null || ! f . exists ( ) ) { log . error ( "No package: " + f . getName ( ) + " found!" ) ; throw new SDKException ( "No package: " + f . getName ( ) + " found!" , new StackTraceElement [ 0 ] , "File " + filePath + " not existing" ) ; } return requestPostPackage ( f ) ; } | Uploads a VNFPackage to the NFVO . | 160 | 13 |
22,098 | @ Help ( help = "Find a User by his name" ) public User findByName ( String name ) throws SDKException { return ( User ) requestGet ( name , User . class ) ; } | Returns a User specified by his username . | 42 | 8 |
22,099 | @ Help ( help = "Change a user's password" ) public void changePassword ( String oldPassword , String newPassword ) throws SDKException { HashMap < String , String > requestBody = new HashMap <> ( ) ; requestBody . put ( "old_pwd" , oldPassword ) ; requestBody . put ( "new_pwd" , newPassword ) ; requestPut ( "changepwd" , requestBody ) ; } | Changes a User s password . | 94 | 6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.